Skip to content
This repository was archived by the owner on Jun 2, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/components/Card.astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const furl = url ? new URL(url) : "#";
alt={title}
width={512}
height={288}
loading="lazy"
decoding="async"
/>}
</div>
<div class="flex-grow relative flex-grow">
Expand All @@ -36,7 +34,6 @@ const furl = url ? new URL(url) : "#";
width={512}
height={288}
loading="lazy"
decoding="async"
/>}
<div
class="h-full bg-white/90 group-hover:bg-white/80 transition-colors duration-300 py-2 px-6 flex flex-col justify-between"
Expand Down
34 changes: 21 additions & 13 deletions src/components/getThumbnail.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import ky from "ky";
import pseudoThumbnail from "../images/pseudo_thumbnail.jpg";

import pseudoNicovideo from "../images/pseudo_nicovideo_thumbnail.jpg";
import deletedNicovideo from "../images/deleted_nicovideo_thumbnail.jpg";

import pseudoYoutube from "../images/pseudo_youtube_thumbnail.png";

import * as v from "valibot";

export default async function (type: string, url: string | null) {
if (!url) return pseudoThumbnail;
if (!url) return pseudoNicovideo;

switch (type) {
case "nicovideo": {
const sourceId = /(nm|sm)\d+/.exec(url)?.[0];

if (!sourceId) {
return pseudoThumbnail;
return pseudoNicovideo;
}

const res = await ky.get(
Expand All @@ -25,7 +30,7 @@ export default async function (type: string, url: string | null) {
);
if (!res.ok) {
try {
const a = await res.json().then((re) =>
const ls = await res.json().then((re) =>
v.parse(
v.object({
reason: v.union([
Expand All @@ -37,29 +42,32 @@ export default async function (type: string, url: string | null) {
re,
),
);
switch (a.reason) {
switch (ls.reason) {
case "FETCH_FAILED":
return pseudoThumbnail;
console.log(ls.data);
return deletedNicovideo;
case "INVALID_RESPONSE":
console.error(a.data);
return pseudoThumbnail;
console.log(ls.data);
return pseudoNicovideo;
}
} catch (e) {
console.error(e);
return pseudoThumbnail;
console.log(e);
return pseudoNicovideo;
}
}

const a = await res.json();
const b = v.safeParse(v.object({ thumbnailUrl: v.string() }), a);
if (!b.success) {
console.error(b.issues);
return pseudoThumbnail;
console.log(b.issues);
return pseudoNicovideo;
}

return b.output.thumbnailUrl;
}
case "youtube":
return pseudoYoutube;
default:
return pseudoThumbnail;
return pseudoYoutube;
}
}
Binary file added src/images/deleted_nicovideo_thumbnail.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/pseudo_youtube_thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.