cursedbelt-server 4.70.0 → 4.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,6 +30,11 @@ export interface TubeApiVideo {
30
30
  channelTitle: string;
31
31
  thumbnail: string;
32
32
  url: string;
33
+ /**
34
+ * When the VIDEO went up (`contentDetails.videoPublishedAt`), epoch ms — not `snippet.publishedAt`,
35
+ * which is when it was added to the playlist. `null` when the reply carries none (a private video).
36
+ */
37
+ publishedAt: number | null;
33
38
  }
34
39
  export interface TubeApiPlaylist {
35
40
  id: string;
@@ -3,6 +3,13 @@ const API_BASE = "https://www.googleapis.com/youtube/v3";
3
3
  export const youtubeThumbnailUrl = (videoId) => videoId ? `https://i.ytimg.com/vi/${videoId}/mqdefault.jpg` : "";
4
4
  /** Read-only, and nothing else. See the header. */
5
5
  export const YOUTUBE_READONLY_SCOPE = "https://www.googleapis.com/auth/youtube.readonly";
6
+ /** An RFC 3339 stamp as epoch ms, or `null` for anything absent or unparseable. */
7
+ const epochMs = (stamp) => {
8
+ if (typeof stamp !== "string" || !stamp)
9
+ return null;
10
+ const ms = Date.parse(stamp);
11
+ return Number.isFinite(ms) ? ms : null;
12
+ };
6
13
  /**
7
14
  * `medium` first, deliberately. `default` is 120×90 and looks like a thumbnail from 2009 on
8
15
  * a retina phone; `maxres` does not exist for most videos, so preferring it would leave
@@ -135,6 +142,7 @@ export function createYouTubeApi(fetchImpl = fetch) {
135
142
  channelTitle: String(snippet.videoOwnerChannelTitle ?? ""),
136
143
  thumbnail: pickThumb(snippet.thumbnails) || youtubeThumbnailUrl(videoId),
137
144
  url: watchUrl(videoId),
145
+ publishedAt: epochMs(details.videoPublishedAt),
138
146
  };
139
147
  })
140
148
  .filter((v) => v.videoId && !UNPLAYABLE_TITLES.has(v.title)),
@@ -188,6 +196,8 @@ export function createYouTubeApi(fetchImpl = fetch) {
188
196
  channelTitle: String(snippet.channelTitle ?? ""),
189
197
  thumbnail: pickThumb(snippet.thumbnails) || youtubeThumbnailUrl(videoId),
190
198
  url: watchUrl(videoId),
199
+ // On a `videos` row the snippet IS the video's, so its publishedAt is the upload.
200
+ publishedAt: epochMs(snippet.publishedAt),
191
201
  };
192
202
  })
193
203
  .filter((v) => v.videoId),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursedbelt-server",
3
- "version": "4.70.0",
3
+ "version": "4.71.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "description": "The app-facing Bun/Hono server tier of the cursedbelt split — storage, sharing, activity, guard, sync. React-free; cursedbelt-core below it.",
@@ -441,7 +441,7 @@
441
441
  "@node-rs/argon2": "^2.0.2",
442
442
  "@types/bun": "^1.3.14",
443
443
  "@types/node": "^24",
444
- "cursedbelt": "^5.141.0",
444
+ "cursedbelt": "^6.1.0",
445
445
  "hono": "4.12.28",
446
446
  "kysely": "^0.28.17",
447
447
  "kysely-bun-sqlite": "^0.4.0",
@@ -21,9 +21,9 @@ const fakeGoogle = (handler: Handler) => {
21
21
  return { seen, api: createYouTubeApi(fetchImpl) };
22
22
  };
23
23
 
24
- const item = (videoId: string, title = `Video ${videoId}`) => ({
25
- snippet: { title, videoOwnerChannelTitle: "Chan", thumbnails: {} },
26
- contentDetails: { videoId },
24
+ const item = (videoId: string, title = `Video ${videoId}`, videoPublishedAt?: string) => ({
25
+ snippet: { title, videoOwnerChannelTitle: "Chan", thumbnails: {}, publishedAt: "2030-01-01T00:00:00Z" },
26
+ contentDetails: { videoId, ...(videoPublishedAt ? { videoPublishedAt } : {}) },
27
27
  });
28
28
 
29
29
  describe("createYouTubeApi", () => {
@@ -43,6 +43,7 @@ describe("createYouTubeApi", () => {
43
43
  channelTitle: "Chan",
44
44
  thumbnail: youtubeThumbnailUrl("a1"),
45
45
  url: "https://www.youtube.com/watch?v=a1",
46
+ publishedAt: null,
46
47
  },
47
48
  ],
48
49
  },
@@ -51,6 +52,29 @@ describe("createYouTubeApi", () => {
51
52
  expect(seen[0]?.searchParams.get("playlistId")).toBe("PL1");
52
53
  });
53
54
 
55
+ test("a video's date is when IT went up (contentDetails), never when it joined the playlist (snippet)", async () => {
56
+ const { api } = fakeGoogle(() => ({
57
+ body: { items: [item("d1", "Dated", "2019-06-01T12:00:00Z"), item("d2", "Undated"), item("d3", "Garbled", "soon")] },
58
+ }));
59
+ const page = await api.playlistItems("tok", "PL1");
60
+ expect(page.status === "ok" ? page.value.items.map((v) => v.publishedAt) : []).toEqual([
61
+ Date.UTC(2019, 5, 1, 12),
62
+ null,
63
+ null,
64
+ ]);
65
+ });
66
+
67
+ test("a liked video's date is its own snippet's — on a videos row the snippet is the video", async () => {
68
+ const { api, seen } = fakeGoogle(() => ({
69
+ body: { items: [{ id: "L1", snippet: { title: "Liked", channelTitle: "C", publishedAt: "2021-02-03T00:00:00Z" } }] },
70
+ }));
71
+ const page = await api.liked("tok");
72
+ expect(page.status === "ok" ? page.value.items.map((v) => [v.videoId, v.publishedAt]) : []).toEqual([
73
+ ["L1", Date.UTC(2021, 1, 3)],
74
+ ]);
75
+ expect(seen[0]?.searchParams.get("myRating")).toBe("like");
76
+ });
77
+
54
78
  test("🔴 every page is walked, and a list stopped at the cap SAYS so", async () => {
55
79
  const { api } = fakeGoogle((url) => {
56
80
  const at = Number(url.searchParams.get("pageToken") ?? "0");
@@ -36,8 +36,20 @@ export interface TubeApiVideo {
36
36
  channelTitle: string;
37
37
  thumbnail: string;
38
38
  url: string;
39
+ /**
40
+ * When the VIDEO went up (`contentDetails.videoPublishedAt`), epoch ms — not `snippet.publishedAt`,
41
+ * which is when it was added to the playlist. `null` when the reply carries none (a private video).
42
+ */
43
+ publishedAt: number | null;
39
44
  }
40
45
 
46
+ /** An RFC 3339 stamp as epoch ms, or `null` for anything absent or unparseable. */
47
+ const epochMs = (stamp: unknown): number | null => {
48
+ if (typeof stamp !== "string" || !stamp) return null;
49
+ const ms = Date.parse(stamp);
50
+ return Number.isFinite(ms) ? ms : null;
51
+ };
52
+
41
53
  export interface TubeApiPlaylist {
42
54
  id: string;
43
55
  title: string;
@@ -224,6 +236,7 @@ export function createYouTubeApi(fetchImpl: FetchLike = fetch) {
224
236
  channelTitle: String(snippet.videoOwnerChannelTitle ?? ""),
225
237
  thumbnail: pickThumb(snippet.thumbnails as Thumbs) || youtubeThumbnailUrl(videoId),
226
238
  url: watchUrl(videoId),
239
+ publishedAt: epochMs(details.videoPublishedAt),
227
240
  };
228
241
  })
229
242
  .filter((v) => v.videoId && !UNPLAYABLE_TITLES.has(v.title)),
@@ -289,6 +302,8 @@ export function createYouTubeApi(fetchImpl: FetchLike = fetch) {
289
302
  channelTitle: String(snippet.channelTitle ?? ""),
290
303
  thumbnail: pickThumb(snippet.thumbnails as Thumbs) || youtubeThumbnailUrl(videoId),
291
304
  url: watchUrl(videoId),
305
+ // On a `videos` row the snippet IS the video's, so its publishedAt is the upload.
306
+ publishedAt: epochMs(snippet.publishedAt),
292
307
  };
293
308
  })
294
309
  .filter((v) => v.videoId),