cursedbelt-server 4.56.0 → 4.58.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.
- package/dist/server/engagement/actions.d.ts +85 -3
- package/dist/server/engagement/actions.js +93 -11
- package/dist/server/engagement/api.d.ts +2 -1
- package/dist/server/engagement/api.js +9 -10
- package/dist/server/engagement/d1.d.ts +3 -0
- package/dist/server/engagement/d1.js +36 -10
- package/dist/server/engagement/store.d.ts +7 -3
- package/dist/server/engagement/store.js +22 -7
- package/dist/server/engagement/visits.d.ts +37 -0
- package/dist/server/engagement/visits.js +28 -0
- package/dist/server/youtube/ytdlp.d.ts +9 -0
- package/dist/server/youtube/ytdlp.js +16 -5
- package/docs/engagement.md +14 -0
- package/package.json +2 -2
- package/src/server/engagement/actions.ts +109 -12
- package/src/server/engagement/api.ts +8 -9
- package/src/server/engagement/d1.spec.ts +60 -1
- package/src/server/engagement/d1.ts +34 -9
- package/src/server/engagement/engagement.spec.ts +41 -0
- package/src/server/engagement/store.ts +20 -7
- package/src/server/engagement/visits.ts +53 -0
- package/src/server/youtube/ytdlp.spec.ts +13 -0
- package/src/server/youtube/ytdlp.ts +23 -6
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
* age check) is handed the owner's own cookie jar per call; reading that jar is the app's business.
|
|
20
20
|
*
|
|
21
21
|
* ── The file stays on disk ──────────────────────────────────────────────────────────────
|
|
22
|
-
* A download resolves to a PATH inside a fresh temporary directory
|
|
22
|
+
* A download resolves to a PATH inside a fresh temporary directory — or inside the caller's own
|
|
23
|
+
* `workDir`, which makes it resumable across failures (forge task 4010) — and the caller disposes of
|
|
23
24
|
* it. A 1080p video is gigabytes, and reading it into memory to hand it over would make the
|
|
24
25
|
* agent's footprint the size of the largest video in a playlist. Music, whose files are a few
|
|
25
26
|
* MB, reads the bytes and disposes at once.
|
|
@@ -123,6 +124,14 @@ export interface YtDownload {
|
|
|
123
124
|
interface YtDlpCallOptions {
|
|
124
125
|
/** A Netscape-format cookie jar yt-dlp reads (`--cookies`). The caller owns and removes it. */
|
|
125
126
|
cookiesFile?: string;
|
|
127
|
+
/**
|
|
128
|
+
* A RESUMABLE download: yt-dlp writes into this directory, which the CALLER owns — made if it is
|
|
129
|
+
* missing, kept with its `.part` files when the download fails, so the next call with the same
|
|
130
|
+
* directory continues where the bytes stopped instead of starting a 25 GB film again. The owner,
|
|
131
|
+
* 2026-10-29: *"if my internet was to go out … my downloads in process could be picked back up
|
|
132
|
+
* where they left off"* (forge task 4010). `dispose` still removes it once the file is had.
|
|
133
|
+
*/
|
|
134
|
+
workDir?: string;
|
|
126
135
|
}
|
|
127
136
|
|
|
128
137
|
/**
|
|
@@ -270,7 +279,7 @@ export function ytDlpArgs(
|
|
|
270
279
|
target: string,
|
|
271
280
|
outDir: string,
|
|
272
281
|
profile: Pick<YtDlpProfile, "format" | "extraArgs" | "maxFilesize">,
|
|
273
|
-
options: { cacheDir?: string; jsRuntime?: string; cookiesFile?: string } = {},
|
|
282
|
+
options: { cacheDir?: string; jsRuntime?: string; cookiesFile?: string; resumable?: boolean } = {},
|
|
274
283
|
): string[] {
|
|
275
284
|
return [
|
|
276
285
|
...(options.jsRuntime ? ["--js-runtimes", `bun:${options.jsRuntime}`] : []),
|
|
@@ -282,7 +291,9 @@ export function ytDlpArgs(
|
|
|
282
291
|
...(profile.extraArgs ?? []),
|
|
283
292
|
"--max-filesize",
|
|
284
293
|
profile.maxFilesize,
|
|
285
|
-
|
|
294
|
+
// Resumable: keep the `.part` and continue it. Otherwise no `.part` at all — a fresh directory
|
|
295
|
+
// per run has nothing to continue, and a half file there is only litter.
|
|
296
|
+
...(options.resumable ? ["--continue"] : ["--no-part"]),
|
|
286
297
|
"--no-mtime",
|
|
287
298
|
"--no-colors",
|
|
288
299
|
"--newline",
|
|
@@ -293,7 +304,9 @@ export function ytDlpArgs(
|
|
|
293
304
|
"--print",
|
|
294
305
|
`after_move:${INFO_MARK}%()j`,
|
|
295
306
|
"-o",
|
|
296
|
-
|
|
307
|
+
// Resumable runs name the file for the directory, not the site's id: a signed URL resolved
|
|
308
|
+
// afresh on the next try can carry a different id, and a different name is a fresh download.
|
|
309
|
+
join(outDir, options.resumable ? "download.%(ext)s" : "%(id)s.%(ext)s"),
|
|
297
310
|
"--",
|
|
298
311
|
isPageUrl(target) ? target : `https://www.youtube.com/watch?v=${target}`,
|
|
299
312
|
];
|
|
@@ -429,7 +442,9 @@ export function createYtDlp(options: YtDlpOptions): YtDlpFetch {
|
|
|
429
442
|
|
|
430
443
|
/** One yt-dlp run into a fresh directory. Throws a classified error on failure. */
|
|
431
444
|
const attempt = async (target: string, onProgress?: (fraction: number) => void, call: YtDlpCallOptions = {}): Promise<YtDownload> => {
|
|
432
|
-
const
|
|
445
|
+
const resumable = call.workDir !== undefined;
|
|
446
|
+
const dir = call.workDir ?? (await mkdtemp(join(options.tmpRoot ?? tmpdir(), "ytdlp-")));
|
|
447
|
+
if (resumable) await mkdir(dir, { recursive: true });
|
|
433
448
|
const dispose = () => rm(dir, { recursive: true, force: true });
|
|
434
449
|
try {
|
|
435
450
|
let info: YtInfo | null = null;
|
|
@@ -439,6 +454,7 @@ export function createYtDlp(options: YtDlpOptions): YtDlpFetch {
|
|
|
439
454
|
...(options.cacheDir ? { cacheDir: options.cacheDir } : {}),
|
|
440
455
|
...(jsRuntime ? { jsRuntime } : {}),
|
|
441
456
|
...(call.cookiesFile ? { cookiesFile: call.cookiesFile } : {}),
|
|
457
|
+
...(resumable ? { resumable } : {}),
|
|
442
458
|
}),
|
|
443
459
|
(line) => {
|
|
444
460
|
const fraction = parseYtProgress(line);
|
|
@@ -455,7 +471,8 @@ export function createYtDlp(options: YtDlpOptions): YtDlpFetch {
|
|
|
455
471
|
const extension = (found.ext || found.filepath.split(".").at(-1) || "bin").toLowerCase();
|
|
456
472
|
return { path: found.filepath, extension, info: found, dir, dispose };
|
|
457
473
|
} catch (error) {
|
|
458
|
-
|
|
474
|
+
// 🔴 A resumable directory is the caller's, and its `.part` is the whole point: keep it.
|
|
475
|
+
if (!resumable) await dispose();
|
|
459
476
|
throw error;
|
|
460
477
|
}
|
|
461
478
|
};
|