Skip to content

Commit

Permalink
ensure
Browse files Browse the repository at this point in the history
  • Loading branch information
SnO2WMaN committed Nov 27, 2023
1 parent 34849ed commit 9713253
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Common/Nicovideo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from "zod";

export const mkNicovideoService = ({ logger }: { logger: Logger }) => {
return {
async getInfo(sourceId: string) {
async getFreshInfo(sourceId: string) {
const url = new URL(`/api/watch/v3_guest/${sourceId}`, "https://www.nicovideo.jp");
url.searchParams.set("_frontendId", "6");
url.searchParams.set("_frontendVersion", "0");
Expand Down
5 changes: 1 addition & 4 deletions src/FetchExternal/NicovideoOriginalSource.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ type NicovideoOriginalSource {
"ニコニコ動画の埋め込み用URL"
embedUrl: String!

"""
削除されている場合は`null`を返却
"""
info: NicovideoOriginalSourceFreshInfo
info: NicovideoOriginalSourceFreshInfo!
}

"ニコニコ動画のフレッシュな動画情報"
Expand Down
12 changes: 9 additions & 3 deletions src/FetchExternal/NicovideoOriginalSource.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { GraphQLError } from "graphql";

import { MkResolver } from "../utils/MkResolver.js";
import { NicovideoOriginalSourceTagDTO } from "./NicovideoOriginalSourceTag.dto.js";
export const mkNicovideoOriginalSourceResolver: MkResolver<"NicovideoOriginalSource", "NicovideoService"> = ({
Expand All @@ -8,9 +10,13 @@ export const mkNicovideoOriginalSourceResolver: MkResolver<"NicovideoOriginalSou
url: ({ sourceId }) => `https://www.nicovideo.jp/watch/${sourceId}`,
embedUrl: ({ sourceId }) => `https://embed.nicovideo.jp/watch/${sourceId}`,
async info({ sourceId }) {
return NicovideoService.getInfo(sourceId).then((info) =>
info ? { ...info, tags: info.tags.map((tag) => new NicovideoOriginalSourceTagDTO({ name: tag })) } : null,
);
const info = await NicovideoService.getFreshInfo(sourceId);
if (!info) throw new GraphQLError("Failed to get fresh info");

return {
...info,
tags: info.tags.map((tag) => new NicovideoOriginalSourceTagDTO({ name: tag })),
};
},
};
};

0 comments on commit 9713253

Please sign in to comment.