@editframe/api 0.37.3-beta → 0.38.1
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/CHUNK_SIZE_BYTES.cjs +13 -0
- package/dist/CHUNK_SIZE_BYTES.cjs.map +1 -0
- package/dist/ProgressIterator.cjs +109 -0
- package/dist/ProgressIterator.cjs.map +1 -0
- package/dist/ProgressIterator.d.cts +30 -0
- package/dist/StreamEventSource.cjs +127 -0
- package/dist/StreamEventSource.cjs.map +1 -0
- package/dist/StreamEventSource.d.cts +65 -0
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/client.cjs +54 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +14 -0
- package/dist/index.cjs +70 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/dist/node.cjs +175 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +27 -0
- package/dist/node.d.ts +8 -3
- package/dist/node.js +64 -5
- package/dist/node.js.map +1 -1
- package/dist/resources/caption-file.cjs +74 -0
- package/dist/resources/caption-file.cjs.map +1 -0
- package/dist/resources/caption-file.d.cts +83 -0
- package/dist/resources/caption-file.d.ts +5 -0
- package/dist/resources/caption-file.js +3 -0
- package/dist/resources/caption-file.js.map +1 -1
- package/dist/resources/file.cjs +145 -0
- package/dist/resources/file.cjs.map +1 -0
- package/dist/resources/file.d.cts +91 -0
- package/dist/resources/file.d.ts +91 -0
- package/dist/resources/file.js +129 -0
- package/dist/resources/file.js.map +1 -0
- package/dist/resources/image-file.cjs +87 -0
- package/dist/resources/image-file.cjs.map +1 -0
- package/dist/resources/image-file.d.cts +123 -0
- package/dist/resources/image-file.d.ts +7 -0
- package/dist/resources/image-file.js +4 -0
- package/dist/resources/image-file.js.map +1 -1
- package/dist/resources/isobmff-file.cjs +72 -0
- package/dist/resources/isobmff-file.cjs.map +1 -0
- package/dist/resources/isobmff-file.d.cts +81 -0
- package/dist/resources/isobmff-file.d.ts +8 -0
- package/dist/resources/isobmff-file.js +5 -0
- package/dist/resources/isobmff-file.js.map +1 -1
- package/dist/resources/isobmff-track.cjs +109 -0
- package/dist/resources/isobmff-track.cjs.map +1 -0
- package/dist/resources/isobmff-track.d.cts +769 -0
- package/dist/resources/isobmff-track.d.ts +2 -0
- package/dist/resources/isobmff-track.js +2 -0
- package/dist/resources/isobmff-track.js.map +1 -1
- package/dist/resources/process-isobmff.cjs +16 -0
- package/dist/resources/process-isobmff.cjs.map +1 -0
- package/dist/resources/process-isobmff.d.cts +17 -0
- package/dist/resources/renders.bundle.cjs +50 -0
- package/dist/resources/renders.bundle.cjs.map +1 -0
- package/dist/resources/renders.bundle.d.cts +9 -0
- package/dist/resources/renders.bundle.d.ts +1 -1
- package/dist/resources/renders.cjs +152 -0
- package/dist/resources/renders.cjs.map +1 -0
- package/dist/resources/renders.d.cts +284 -0
- package/dist/resources/renders.d.ts +19 -19
- package/dist/resources/renders.js +1 -1
- package/dist/resources/transcriptions.cjs +38 -0
- package/dist/resources/transcriptions.cjs.map +1 -0
- package/dist/resources/transcriptions.d.cts +30 -0
- package/dist/resources/unprocessed-file.cjs +61 -0
- package/dist/resources/unprocessed-file.cjs.map +1 -0
- package/dist/resources/unprocessed-file.d.cts +51 -0
- package/dist/resources/unprocessed-file.d.ts +9 -0
- package/dist/resources/unprocessed-file.js +4 -0
- package/dist/resources/unprocessed-file.js.map +1 -1
- package/dist/resources/url-token.cjs +19 -0
- package/dist/resources/url-token.cjs.map +1 -0
- package/dist/resources/url-token.d.cts +10 -0
- package/dist/streamChunker.cjs +29 -0
- package/dist/streamChunker.cjs.map +1 -0
- package/dist/uploadChunks.cjs +87 -0
- package/dist/uploadChunks.cjs.map +1 -0
- package/dist/uploadChunks.d.cts +14 -0
- package/dist/utils/assertTypesMatch.cjs +7 -0
- package/dist/utils/assertTypesMatch.cjs.map +1 -0
- package/dist/utils/createReadableStreamFromReadable.cjs +71 -0
- package/dist/utils/createReadableStreamFromReadable.cjs.map +1 -0
- package/dist/utils/createReadableStreamFromReadable.d.cts +9 -0
- package/dist/utils/createReadableStreamFromReadable.d.ts +1 -1
- package/package.json +37 -9
- package/tsdown.config.ts +1 -0
|
@@ -20,20 +20,20 @@ declare const RenderOutputConfiguration: z.ZodDiscriminatedUnion<"container", [z
|
|
|
20
20
|
codec: "aac";
|
|
21
21
|
}>;
|
|
22
22
|
}, "strip", z.ZodTypeAny, {
|
|
23
|
-
audio: {
|
|
24
|
-
codec: "aac";
|
|
25
|
-
};
|
|
26
23
|
video: {
|
|
27
24
|
codec: "h264";
|
|
28
25
|
};
|
|
29
|
-
container: "mp4";
|
|
30
|
-
}, {
|
|
31
26
|
audio: {
|
|
32
27
|
codec: "aac";
|
|
33
28
|
};
|
|
29
|
+
container: "mp4";
|
|
30
|
+
}, {
|
|
34
31
|
video: {
|
|
35
32
|
codec: "h264";
|
|
36
33
|
};
|
|
34
|
+
audio: {
|
|
35
|
+
codec: "aac";
|
|
36
|
+
};
|
|
37
37
|
container: "mp4";
|
|
38
38
|
}>, z.ZodObject<{
|
|
39
39
|
container: z.ZodLiteral<"jpeg">;
|
|
@@ -100,20 +100,20 @@ declare const CreateRenderPayload: z.ZodObject<{
|
|
|
100
100
|
codec: "aac";
|
|
101
101
|
}>;
|
|
102
102
|
}, "strip", z.ZodTypeAny, {
|
|
103
|
-
audio: {
|
|
104
|
-
codec: "aac";
|
|
105
|
-
};
|
|
106
103
|
video: {
|
|
107
104
|
codec: "h264";
|
|
108
105
|
};
|
|
109
|
-
container: "mp4";
|
|
110
|
-
}, {
|
|
111
106
|
audio: {
|
|
112
107
|
codec: "aac";
|
|
113
108
|
};
|
|
109
|
+
container: "mp4";
|
|
110
|
+
}, {
|
|
114
111
|
video: {
|
|
115
112
|
codec: "h264";
|
|
116
113
|
};
|
|
114
|
+
audio: {
|
|
115
|
+
codec: "aac";
|
|
116
|
+
};
|
|
117
117
|
container: "mp4";
|
|
118
118
|
}>, z.ZodObject<{
|
|
119
119
|
container: z.ZodLiteral<"jpeg">;
|
|
@@ -163,12 +163,12 @@ declare const CreateRenderPayload: z.ZodObject<{
|
|
|
163
163
|
metadata?: Record<string, string> | undefined;
|
|
164
164
|
strategy?: "v1" | undefined;
|
|
165
165
|
output?: {
|
|
166
|
-
audio: {
|
|
167
|
-
codec: "aac";
|
|
168
|
-
};
|
|
169
166
|
video: {
|
|
170
167
|
codec: "h264";
|
|
171
168
|
};
|
|
169
|
+
audio: {
|
|
170
|
+
codec: "aac";
|
|
171
|
+
};
|
|
172
172
|
container: "mp4";
|
|
173
173
|
} | {
|
|
174
174
|
container: "jpeg";
|
|
@@ -194,12 +194,12 @@ declare const CreateRenderPayload: z.ZodObject<{
|
|
|
194
194
|
metadata?: Record<string, string> | undefined;
|
|
195
195
|
strategy?: "v1" | undefined;
|
|
196
196
|
output?: {
|
|
197
|
-
audio: {
|
|
198
|
-
codec: "aac";
|
|
199
|
-
};
|
|
200
197
|
video: {
|
|
201
198
|
codec: "h264";
|
|
202
199
|
};
|
|
200
|
+
audio: {
|
|
201
|
+
codec: "aac";
|
|
202
|
+
};
|
|
203
203
|
container: "mp4";
|
|
204
204
|
} | {
|
|
205
205
|
container: "jpeg";
|
|
@@ -240,12 +240,12 @@ declare class OutputConfiguration {
|
|
|
240
240
|
transparency?: boolean | undefined;
|
|
241
241
|
} | null;
|
|
242
242
|
get mp4Config(): {
|
|
243
|
-
audio: {
|
|
244
|
-
codec: "aac";
|
|
245
|
-
};
|
|
246
243
|
video: {
|
|
247
244
|
codec: "h264";
|
|
248
245
|
};
|
|
246
|
+
audio: {
|
|
247
|
+
codec: "aac";
|
|
248
|
+
};
|
|
249
249
|
container: "mp4";
|
|
250
250
|
} | null;
|
|
251
251
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_ProgressIterator = require('../ProgressIterator.cjs');
|
|
3
|
+
let debug = require("debug");
|
|
4
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
5
|
+
let zod = require("zod");
|
|
6
|
+
zod = require_rolldown_runtime.__toESM(zod);
|
|
7
|
+
|
|
8
|
+
//#region src/resources/transcriptions.ts
|
|
9
|
+
const log = (0, debug.default)("ef:api:transcriptions");
|
|
10
|
+
const CreateTranscriptionPayload = zod.z.object({
|
|
11
|
+
file_id: zod.z.string(),
|
|
12
|
+
track_id: zod.z.number().int()
|
|
13
|
+
});
|
|
14
|
+
const createTranscription = async (client, payload) => {
|
|
15
|
+
log("Creating transcription", payload);
|
|
16
|
+
const response = await client.authenticatedFetch("/api/v1/transcriptions", {
|
|
17
|
+
method: "POST",
|
|
18
|
+
body: JSON.stringify(payload)
|
|
19
|
+
});
|
|
20
|
+
log("Transcription created", response);
|
|
21
|
+
if (response.ok) return await response.json();
|
|
22
|
+
throw new Error(`Failed to create transcription ${response.status} ${response.statusText}`);
|
|
23
|
+
};
|
|
24
|
+
const getTranscriptionProgress = async (client, id) => {
|
|
25
|
+
return new require_ProgressIterator.CompletionIterator(await client.authenticatedEventSource(`/api/v1/transcriptions/${id}/progress`));
|
|
26
|
+
};
|
|
27
|
+
const getTranscriptionInfo = async (client, id) => {
|
|
28
|
+
const response = await client.authenticatedFetch(`/api/v1/transcriptions/${id}`);
|
|
29
|
+
if (response.ok) return await response.json();
|
|
30
|
+
throw new Error(`Failed to get transcription info ${response.status} ${response.statusText}`);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.CreateTranscriptionPayload = CreateTranscriptionPayload;
|
|
35
|
+
exports.createTranscription = createTranscription;
|
|
36
|
+
exports.getTranscriptionInfo = getTranscriptionInfo;
|
|
37
|
+
exports.getTranscriptionProgress = getTranscriptionProgress;
|
|
38
|
+
//# sourceMappingURL=transcriptions.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcriptions.cjs","names":["z","CompletionIterator"],"sources":["../../src/resources/transcriptions.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { CompletionIterator } from \"../ProgressIterator.js\";\n\nconst log = debug(\"ef:api:transcriptions\");\n\nexport const CreateTranscriptionPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n});\n\nexport type CreateTranscriptionPayload = z.infer<\n typeof CreateTranscriptionPayload\n>;\n\nexport interface CreateTranscriptionResult {\n id: string;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"transcribing\";\n}\n\nexport interface TranscriptionInfoResult {\n id: string;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"transcribing\";\n}\n\nexport const createTranscription = async (\n client: Client,\n payload: CreateTranscriptionPayload,\n) => {\n log(\"Creating transcription\", payload);\n const response = await client.authenticatedFetch(\"/api/v1/transcriptions\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Transcription created\", response);\n if (response.ok) {\n return (await response.json()) as CreateTranscriptionResult;\n }\n\n throw new Error(\n `Failed to create transcription ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getTranscriptionProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/transcriptions/${id}/progress`,\n );\n\n return new CompletionIterator(eventSource);\n};\n\nexport const getTranscriptionInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(\n `/api/v1/transcriptions/${id}`,\n );\n\n if (response.ok) {\n return (await response.json()) as TranscriptionInfoResult;\n }\n\n throw new Error(\n `Failed to get transcription info ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;;;;;AAKA,MAAM,yBAAY,wBAAwB;AAE1C,MAAa,6BAA6BA,MAAE,OAAO;CACjD,SAASA,MAAE,QAAQ;CACnB,UAAUA,MAAE,QAAQ,CAAC,KAAK;CAC3B,CAAC;AAgBF,MAAa,sBAAsB,OACjC,QACA,YACG;AACH,KAAI,0BAA0B,QAAQ;CACtC,MAAM,WAAW,MAAM,OAAO,mBAAmB,0BAA0B;EACzE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AAEF,KAAI,yBAAyB,SAAS;AACtC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MACR,kCAAkC,SAAS,OAAO,GAAG,SAAS,aAC/D;;AAGH,MAAa,2BAA2B,OAAO,QAAgB,OAAe;AAK5E,QAAO,IAAIC,4CAJS,MAAM,OAAO,yBAC/B,0BAA0B,GAAG,WAC9B,CAEyC;;AAG5C,MAAa,uBAAuB,OAAO,QAAgB,OAAe;CACxE,MAAM,WAAW,MAAM,OAAO,mBAC5B,0BAA0B,KAC3B;AAED,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MACR,oCAAoC,SAAS,OAAO,GAAG,SAAS,aACjE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Client } from "../client.cjs";
|
|
2
|
+
import { CompletionIterator } from "../ProgressIterator.cjs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/resources/transcriptions.d.ts
|
|
6
|
+
declare const CreateTranscriptionPayload: z.ZodObject<{
|
|
7
|
+
file_id: z.ZodString;
|
|
8
|
+
track_id: z.ZodNumber;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
file_id: string;
|
|
11
|
+
track_id: number;
|
|
12
|
+
}, {
|
|
13
|
+
file_id: string;
|
|
14
|
+
track_id: number;
|
|
15
|
+
}>;
|
|
16
|
+
type CreateTranscriptionPayload = z.infer<typeof CreateTranscriptionPayload>;
|
|
17
|
+
interface CreateTranscriptionResult {
|
|
18
|
+
id: string;
|
|
19
|
+
status: "complete" | "created" | "failed" | "pending" | "transcribing";
|
|
20
|
+
}
|
|
21
|
+
interface TranscriptionInfoResult {
|
|
22
|
+
id: string;
|
|
23
|
+
status: "complete" | "created" | "failed" | "pending" | "transcribing";
|
|
24
|
+
}
|
|
25
|
+
declare const createTranscription: (client: Client, payload: CreateTranscriptionPayload) => Promise<CreateTranscriptionResult>;
|
|
26
|
+
declare const getTranscriptionProgress: (client: Client, id: string) => Promise<CompletionIterator>;
|
|
27
|
+
declare const getTranscriptionInfo: (client: Client, id: string) => Promise<TranscriptionInfoResult>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { CreateTranscriptionPayload, CreateTranscriptionResult, TranscriptionInfoResult, createTranscription, getTranscriptionInfo, getTranscriptionProgress };
|
|
30
|
+
//# sourceMappingURL=transcriptions.d.cts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_uploadChunks = require('../uploadChunks.cjs');
|
|
3
|
+
const require_assertTypesMatch = require('../utils/assertTypesMatch.cjs');
|
|
4
|
+
let debug = require("debug");
|
|
5
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
6
|
+
let zod = require("zod");
|
|
7
|
+
zod = require_rolldown_runtime.__toESM(zod);
|
|
8
|
+
|
|
9
|
+
//#region src/resources/unprocessed-file.ts
|
|
10
|
+
const log = (0, debug.default)("ef:api:unprocessed-file");
|
|
11
|
+
const MAX_FILE_SIZE = 1024 * 1024 * 1024;
|
|
12
|
+
const CreateUnprocessedFilePayload = zod.z.object({
|
|
13
|
+
md5: zod.z.string(),
|
|
14
|
+
filename: zod.z.string(),
|
|
15
|
+
byte_size: zod.z.number().int().max(MAX_FILE_SIZE)
|
|
16
|
+
});
|
|
17
|
+
const UpdateUnprocessedFilePayload = zod.z.object({});
|
|
18
|
+
require_assertTypesMatch.assertTypesMatch(true);
|
|
19
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
20
|
+
const createUnprocessedFile = async (client, payload) => {
|
|
21
|
+
log("Creating an unprocessed file", payload);
|
|
22
|
+
CreateUnprocessedFilePayload.parse(payload);
|
|
23
|
+
const response = await client.authenticatedFetch("/api/v1/unprocessed_files", {
|
|
24
|
+
method: "POST",
|
|
25
|
+
body: JSON.stringify(payload)
|
|
26
|
+
});
|
|
27
|
+
log("Unprocessed file created", response.status, response.statusText, response.headers);
|
|
28
|
+
if (response.ok) return await response.json();
|
|
29
|
+
throw new Error(`Failed to create unprocessed file ${response.status} ${response.statusText}`);
|
|
30
|
+
};
|
|
31
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
32
|
+
const uploadUnprocessedReadableStream = (client, uploadDetails, fileStream) => {
|
|
33
|
+
log("Uploading unprocessed file", uploadDetails.id);
|
|
34
|
+
return require_uploadChunks.uploadChunks(client, {
|
|
35
|
+
url: `/api/v1/unprocessed_files/${uploadDetails.id}/upload`,
|
|
36
|
+
fileSize: uploadDetails.byte_size,
|
|
37
|
+
fileStream,
|
|
38
|
+
maxSize: MAX_FILE_SIZE
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
42
|
+
const lookupUnprocessedFileByMd5 = async (client, md5) => {
|
|
43
|
+
const response = await client.authenticatedFetch(`/api/v1/unprocessed_files/md5/${md5}`, { method: "GET" });
|
|
44
|
+
if (response.ok) return await response.json();
|
|
45
|
+
if (response.status === 404) return null;
|
|
46
|
+
throw new Error(`Failed to lookup unprocessed file by md5 ${md5} ${response.status} ${response.statusText}`);
|
|
47
|
+
};
|
|
48
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
49
|
+
const processIsobmffFile = async (client, id) => {
|
|
50
|
+
const response = await client.authenticatedFetch(`/api/v1/unprocessed_files/${id}/isobmff`, { method: "POST" });
|
|
51
|
+
if (response.ok) return await response.json();
|
|
52
|
+
throw new Error(`Failed to process isobmff file ${id} ${response.status} ${response.statusText}`);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.CreateUnprocessedFilePayload = CreateUnprocessedFilePayload;
|
|
57
|
+
exports.createUnprocessedFile = createUnprocessedFile;
|
|
58
|
+
exports.lookupUnprocessedFileByMd5 = lookupUnprocessedFileByMd5;
|
|
59
|
+
exports.processIsobmffFile = processIsobmffFile;
|
|
60
|
+
exports.uploadUnprocessedReadableStream = uploadUnprocessedReadableStream;
|
|
61
|
+
//# sourceMappingURL=unprocessed-file.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unprocessed-file.cjs","names":["z","assertTypesMatch","uploadChunks"],"sources":["../../src/resources/unprocessed-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:unprocessed-file\");\n\nconst MAX_FILE_SIZE = 1024 * 1024 * 1024; // 1GiB\n\nexport const CreateUnprocessedFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n byte_size: z.number().int().max(MAX_FILE_SIZE),\n});\n\nexport const UpdateUnprocessedFilePayload = z.object({});\n\nexport type CreateUnprocessedFilePayload = z.infer<\n typeof CreateUnprocessedFilePayload\n>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UnprocessedFile {\n byte_size: number;\n next_byte: number;\n complete: boolean;\n id: string;\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UnprocessedFileUploadDetails {\n id: string;\n byte_size: number;\n}\n\n// Ensure that the UnprocessedFileUploadDetails type matches the shape of the\n// UnprocessedFile type, but without the optional fields.\nassertTypesMatch<\n Pick<UnprocessedFile, \"id\" | \"byte_size\">,\n UnprocessedFileUploadDetails\n>(true);\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateUnprocessedFileResult extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface LookupUnprocessedFileByMd5Result extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UpdateUnprocessedFileResult extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface ProcessIsobmffFileResult {\n id: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createUnprocessedFile = async (\n client: Client,\n payload: CreateUnprocessedFilePayload,\n) => {\n log(\"Creating an unprocessed file\", payload);\n CreateUnprocessedFilePayload.parse(payload);\n const response = await client.authenticatedFetch(\n \"/api/v1/unprocessed_files\",\n {\n method: \"POST\",\n body: JSON.stringify(payload),\n },\n );\n\n log(\n \"Unprocessed file created\",\n response.status,\n response.statusText,\n response.headers,\n );\n\n if (response.ok) {\n return (await response.json()) as CreateUnprocessedFileResult;\n }\n\n throw new Error(\n `Failed to create unprocessed file ${response.status} ${response.statusText}`,\n );\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadUnprocessedReadableStream = (\n client: Client,\n uploadDetails: UnprocessedFileUploadDetails,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading unprocessed file\", uploadDetails.id);\n\n return uploadChunks(client, {\n url: `/api/v1/unprocessed_files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize: MAX_FILE_SIZE,\n });\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const lookupUnprocessedFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupUnprocessedFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(\n `/api/v1/unprocessed_files/md5/${md5}`,\n {\n method: \"GET\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as LookupUnprocessedFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup unprocessed file by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const processIsobmffFile = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(\n `/api/v1/unprocessed_files/${id}/isobmff`,\n {\n method: \"POST\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as ProcessIsobmffFileResult;\n }\n\n throw new Error(\n `Failed to process isobmff file ${id} ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;;;;;;AAOA,MAAM,yBAAY,0BAA0B;AAE5C,MAAM,gBAAgB,OAAO,OAAO;AAEpC,MAAa,+BAA+BA,MAAE,OAAO;CACnD,KAAKA,MAAE,QAAQ;CACf,UAAUA,MAAE,QAAQ;CACpB,WAAWA,MAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,cAAc;CAC/C,CAAC;AAEF,MAAa,+BAA+BA,MAAE,OAAO,EAAE,CAAC;AAuBxDC,0CAGE,KAAK;;AAiBP,MAAa,wBAAwB,OACnC,QACA,YACG;AACH,KAAI,gCAAgC,QAAQ;AAC5C,8BAA6B,MAAM,QAAQ;CAC3C,MAAM,WAAW,MAAM,OAAO,mBAC5B,6BACA;EACE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CACF;AAED,KACE,4BACA,SAAS,QACT,SAAS,YACT,SAAS,QACV;AAED,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MACR,qCAAqC,SAAS,OAAO,GAAG,SAAS,aAClE;;;AAIH,MAAa,mCACX,QACA,eACA,eACG;AACH,KAAI,8BAA8B,cAAc,GAAG;AAEnD,QAAOC,kCAAa,QAAQ;EAC1B,KAAK,6BAA6B,cAAc,GAAG;EACnD,UAAU,cAAc;EACxB;EACA,SAAS;EACV,CAAC;;;AAIJ,MAAa,6BAA6B,OACxC,QACA,QACqD;CACrD,MAAM,WAAW,MAAM,OAAO,mBAC5B,iCAAiC,OACjC,EACE,QAAQ,OACT,CACF;AAED,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MACR,4CAA4C,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aAChF;;;AAIH,MAAa,qBAAqB,OAAO,QAAgB,OAAe;CACtE,MAAM,WAAW,MAAM,OAAO,mBAC5B,6BAA6B,GAAG,WAChC,EACE,QAAQ,QACT,CACF;AAED,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MACR,kCAAkC,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aACrE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Client } from "../client.cjs";
|
|
2
|
+
import { IteratorWithPromise, UploadChunkEvent } from "../uploadChunks.cjs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/resources/unprocessed-file.d.ts
|
|
6
|
+
declare const CreateUnprocessedFilePayload: z.ZodObject<{
|
|
7
|
+
md5: z.ZodString;
|
|
8
|
+
filename: z.ZodString;
|
|
9
|
+
byte_size: z.ZodNumber;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
md5: string;
|
|
12
|
+
filename: string;
|
|
13
|
+
byte_size: number;
|
|
14
|
+
}, {
|
|
15
|
+
md5: string;
|
|
16
|
+
filename: string;
|
|
17
|
+
byte_size: number;
|
|
18
|
+
}>;
|
|
19
|
+
type CreateUnprocessedFilePayload = z.infer<typeof CreateUnprocessedFilePayload>;
|
|
20
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
21
|
+
interface UnprocessedFile {
|
|
22
|
+
byte_size: number;
|
|
23
|
+
next_byte: number;
|
|
24
|
+
complete: boolean;
|
|
25
|
+
id: string;
|
|
26
|
+
md5: string;
|
|
27
|
+
}
|
|
28
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
29
|
+
interface UnprocessedFileUploadDetails {
|
|
30
|
+
id: string;
|
|
31
|
+
byte_size: number;
|
|
32
|
+
}
|
|
33
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
34
|
+
interface CreateUnprocessedFileResult extends UnprocessedFile {}
|
|
35
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
36
|
+
interface LookupUnprocessedFileByMd5Result extends UnprocessedFile {}
|
|
37
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
38
|
+
interface ProcessIsobmffFileResult {
|
|
39
|
+
id: string;
|
|
40
|
+
}
|
|
41
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
42
|
+
declare const createUnprocessedFile: (client: Client, payload: CreateUnprocessedFilePayload) => Promise<CreateUnprocessedFileResult>;
|
|
43
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
44
|
+
declare const uploadUnprocessedReadableStream: (client: Client, uploadDetails: UnprocessedFileUploadDetails, fileStream: ReadableStream) => IteratorWithPromise<UploadChunkEvent>;
|
|
45
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
46
|
+
declare const lookupUnprocessedFileByMd5: (client: Client, md5: string) => Promise<LookupUnprocessedFileByMd5Result | null>;
|
|
47
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
48
|
+
declare const processIsobmffFile: (client: Client, id: string) => Promise<ProcessIsobmffFileResult>;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { CreateUnprocessedFilePayload, CreateUnprocessedFileResult, LookupUnprocessedFileByMd5Result, ProcessIsobmffFileResult, UnprocessedFile, UnprocessedFileUploadDetails, createUnprocessedFile, lookupUnprocessedFileByMd5, processIsobmffFile, uploadUnprocessedReadableStream };
|
|
51
|
+
//# sourceMappingURL=unprocessed-file.d.cts.map
|
|
@@ -17,6 +17,7 @@ declare const CreateUnprocessedFilePayload: z.ZodObject<{
|
|
|
17
17
|
byte_size: number;
|
|
18
18
|
}>;
|
|
19
19
|
type CreateUnprocessedFilePayload = z.infer<typeof CreateUnprocessedFilePayload>;
|
|
20
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
20
21
|
interface UnprocessedFile {
|
|
21
22
|
byte_size: number;
|
|
22
23
|
next_byte: number;
|
|
@@ -24,18 +25,26 @@ interface UnprocessedFile {
|
|
|
24
25
|
id: string;
|
|
25
26
|
md5: string;
|
|
26
27
|
}
|
|
28
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
27
29
|
interface UnprocessedFileUploadDetails {
|
|
28
30
|
id: string;
|
|
29
31
|
byte_size: number;
|
|
30
32
|
}
|
|
33
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
31
34
|
interface CreateUnprocessedFileResult extends UnprocessedFile {}
|
|
35
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
32
36
|
interface LookupUnprocessedFileByMd5Result extends UnprocessedFile {}
|
|
37
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
33
38
|
interface ProcessIsobmffFileResult {
|
|
34
39
|
id: string;
|
|
35
40
|
}
|
|
41
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
36
42
|
declare const createUnprocessedFile: (client: Client, payload: CreateUnprocessedFilePayload) => Promise<CreateUnprocessedFileResult>;
|
|
43
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
37
44
|
declare const uploadUnprocessedReadableStream: (client: Client, uploadDetails: UnprocessedFileUploadDetails, fileStream: ReadableStream) => IteratorWithPromise<UploadChunkEvent>;
|
|
45
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
38
46
|
declare const lookupUnprocessedFileByMd5: (client: Client, md5: string) => Promise<LookupUnprocessedFileByMd5Result | null>;
|
|
47
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
39
48
|
declare const processIsobmffFile: (client: Client, id: string) => Promise<ProcessIsobmffFileResult>;
|
|
40
49
|
//#endregion
|
|
41
50
|
export { CreateUnprocessedFilePayload, CreateUnprocessedFileResult, LookupUnprocessedFileByMd5Result, ProcessIsobmffFileResult, UnprocessedFile, UnprocessedFileUploadDetails, createUnprocessedFile, lookupUnprocessedFileByMd5, processIsobmffFile, uploadUnprocessedReadableStream };
|
|
@@ -13,6 +13,7 @@ const CreateUnprocessedFilePayload = z.object({
|
|
|
13
13
|
});
|
|
14
14
|
const UpdateUnprocessedFilePayload = z.object({});
|
|
15
15
|
assertTypesMatch(true);
|
|
16
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
16
17
|
const createUnprocessedFile = async (client, payload) => {
|
|
17
18
|
log("Creating an unprocessed file", payload);
|
|
18
19
|
CreateUnprocessedFilePayload.parse(payload);
|
|
@@ -24,6 +25,7 @@ const createUnprocessedFile = async (client, payload) => {
|
|
|
24
25
|
if (response.ok) return await response.json();
|
|
25
26
|
throw new Error(`Failed to create unprocessed file ${response.status} ${response.statusText}`);
|
|
26
27
|
};
|
|
28
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
27
29
|
const uploadUnprocessedReadableStream = (client, uploadDetails, fileStream) => {
|
|
28
30
|
log("Uploading unprocessed file", uploadDetails.id);
|
|
29
31
|
return uploadChunks(client, {
|
|
@@ -33,12 +35,14 @@ const uploadUnprocessedReadableStream = (client, uploadDetails, fileStream) => {
|
|
|
33
35
|
maxSize: MAX_FILE_SIZE
|
|
34
36
|
});
|
|
35
37
|
};
|
|
38
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
36
39
|
const lookupUnprocessedFileByMd5 = async (client, md5) => {
|
|
37
40
|
const response = await client.authenticatedFetch(`/api/v1/unprocessed_files/md5/${md5}`, { method: "GET" });
|
|
38
41
|
if (response.ok) return await response.json();
|
|
39
42
|
if (response.status === 404) return null;
|
|
40
43
|
throw new Error(`Failed to lookup unprocessed file by md5 ${md5} ${response.status} ${response.statusText}`);
|
|
41
44
|
};
|
|
45
|
+
/** @deprecated Use the unified file API from ./file.js instead */
|
|
42
46
|
const processIsobmffFile = async (client, id) => {
|
|
43
47
|
const response = await client.authenticatedFetch(`/api/v1/unprocessed_files/${id}/isobmff`, { method: "POST" });
|
|
44
48
|
if (response.ok) return await response.json();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unprocessed-file.js","names":[],"sources":["../../src/resources/unprocessed-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:unprocessed-file\");\n\nconst MAX_FILE_SIZE = 1024 * 1024 * 1024; // 1GiB\n\nexport const CreateUnprocessedFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n byte_size: z.number().int().max(MAX_FILE_SIZE),\n});\n\nexport const UpdateUnprocessedFilePayload = z.object({});\n\nexport type CreateUnprocessedFilePayload = z.infer<\n typeof CreateUnprocessedFilePayload\n>;\n\nexport interface UnprocessedFile {\n byte_size: number;\n next_byte: number;\n complete: boolean;\n id: string;\n md5: string;\n}\n\nexport interface UnprocessedFileUploadDetails {\n id: string;\n byte_size: number;\n}\n\n// Ensure that the UnprocessedFileUploadDetails type matches the shape of the\n// UnprocessedFile type, but without the optional fields.\nassertTypesMatch<\n Pick<UnprocessedFile, \"id\" | \"byte_size\">,\n UnprocessedFileUploadDetails\n>(true);\n\nexport interface CreateUnprocessedFileResult extends UnprocessedFile {}\n\nexport interface LookupUnprocessedFileByMd5Result extends UnprocessedFile {}\n\nexport interface UpdateUnprocessedFileResult extends UnprocessedFile {}\n\nexport interface ProcessIsobmffFileResult {\n id: string;\n}\n\nexport const createUnprocessedFile = async (\n client: Client,\n payload: CreateUnprocessedFilePayload,\n) => {\n log(\"Creating an unprocessed file\", payload);\n CreateUnprocessedFilePayload.parse(payload);\n const response = await client.authenticatedFetch(\n \"/api/v1/unprocessed_files\",\n {\n method: \"POST\",\n body: JSON.stringify(payload),\n },\n );\n\n log(\n \"Unprocessed file created\",\n response.status,\n response.statusText,\n response.headers,\n );\n\n if (response.ok) {\n return (await response.json()) as CreateUnprocessedFileResult;\n }\n\n throw new Error(\n `Failed to create unprocessed file ${response.status} ${response.statusText}`,\n );\n};\n\nexport const uploadUnprocessedReadableStream = (\n client: Client,\n uploadDetails: UnprocessedFileUploadDetails,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading unprocessed file\", uploadDetails.id);\n\n return uploadChunks(client, {\n url: `/api/v1/unprocessed_files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize: MAX_FILE_SIZE,\n });\n};\n\nexport const lookupUnprocessedFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupUnprocessedFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(\n `/api/v1/unprocessed_files/md5/${md5}`,\n {\n method: \"GET\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as LookupUnprocessedFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup unprocessed file by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const processIsobmffFile = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(\n `/api/v1/unprocessed_files/${id}/isobmff`,\n {\n method: \"POST\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as ProcessIsobmffFileResult;\n }\n\n throw new Error(\n `Failed to process isobmff file ${id} ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;;;AAOA,MAAM,MAAM,MAAM,0BAA0B;AAE5C,MAAM,gBAAgB,OAAO,OAAO;AAEpC,MAAa,+BAA+B,EAAE,OAAO;CACnD,KAAK,EAAE,QAAQ;CACf,UAAU,EAAE,QAAQ;CACpB,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,cAAc;CAC/C,CAAC;AAEF,MAAa,+BAA+B,EAAE,OAAO,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"unprocessed-file.js","names":[],"sources":["../../src/resources/unprocessed-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:unprocessed-file\");\n\nconst MAX_FILE_SIZE = 1024 * 1024 * 1024; // 1GiB\n\nexport const CreateUnprocessedFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n byte_size: z.number().int().max(MAX_FILE_SIZE),\n});\n\nexport const UpdateUnprocessedFilePayload = z.object({});\n\nexport type CreateUnprocessedFilePayload = z.infer<\n typeof CreateUnprocessedFilePayload\n>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UnprocessedFile {\n byte_size: number;\n next_byte: number;\n complete: boolean;\n id: string;\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UnprocessedFileUploadDetails {\n id: string;\n byte_size: number;\n}\n\n// Ensure that the UnprocessedFileUploadDetails type matches the shape of the\n// UnprocessedFile type, but without the optional fields.\nassertTypesMatch<\n Pick<UnprocessedFile, \"id\" | \"byte_size\">,\n UnprocessedFileUploadDetails\n>(true);\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateUnprocessedFileResult extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface LookupUnprocessedFileByMd5Result extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UpdateUnprocessedFileResult extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface ProcessIsobmffFileResult {\n id: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createUnprocessedFile = async (\n client: Client,\n payload: CreateUnprocessedFilePayload,\n) => {\n log(\"Creating an unprocessed file\", payload);\n CreateUnprocessedFilePayload.parse(payload);\n const response = await client.authenticatedFetch(\n \"/api/v1/unprocessed_files\",\n {\n method: \"POST\",\n body: JSON.stringify(payload),\n },\n );\n\n log(\n \"Unprocessed file created\",\n response.status,\n response.statusText,\n response.headers,\n );\n\n if (response.ok) {\n return (await response.json()) as CreateUnprocessedFileResult;\n }\n\n throw new Error(\n `Failed to create unprocessed file ${response.status} ${response.statusText}`,\n );\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadUnprocessedReadableStream = (\n client: Client,\n uploadDetails: UnprocessedFileUploadDetails,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading unprocessed file\", uploadDetails.id);\n\n return uploadChunks(client, {\n url: `/api/v1/unprocessed_files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize: MAX_FILE_SIZE,\n });\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const lookupUnprocessedFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupUnprocessedFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(\n `/api/v1/unprocessed_files/md5/${md5}`,\n {\n method: \"GET\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as LookupUnprocessedFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup unprocessed file by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const processIsobmffFile = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(\n `/api/v1/unprocessed_files/${id}/isobmff`,\n {\n method: \"POST\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as ProcessIsobmffFileResult;\n }\n\n throw new Error(\n `Failed to process isobmff file ${id} ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;;;AAOA,MAAM,MAAM,MAAM,0BAA0B;AAE5C,MAAM,gBAAgB,OAAO,OAAO;AAEpC,MAAa,+BAA+B,EAAE,OAAO;CACnD,KAAK,EAAE,QAAQ;CACf,UAAU,EAAE,QAAQ;CACpB,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,cAAc;CAC/C,CAAC;AAEF,MAAa,+BAA+B,EAAE,OAAO,EAAE,CAAC;AAuBxD,iBAGE,KAAK;;AAiBP,MAAa,wBAAwB,OACnC,QACA,YACG;AACH,KAAI,gCAAgC,QAAQ;AAC5C,8BAA6B,MAAM,QAAQ;CAC3C,MAAM,WAAW,MAAM,OAAO,mBAC5B,6BACA;EACE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CACF;AAED,KACE,4BACA,SAAS,QACT,SAAS,YACT,SAAS,QACV;AAED,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MACR,qCAAqC,SAAS,OAAO,GAAG,SAAS,aAClE;;;AAIH,MAAa,mCACX,QACA,eACA,eACG;AACH,KAAI,8BAA8B,cAAc,GAAG;AAEnD,QAAO,aAAa,QAAQ;EAC1B,KAAK,6BAA6B,cAAc,GAAG;EACnD,UAAU,cAAc;EACxB;EACA,SAAS;EACV,CAAC;;;AAIJ,MAAa,6BAA6B,OACxC,QACA,QACqD;CACrD,MAAM,WAAW,MAAM,OAAO,mBAC5B,iCAAiC,OACjC,EACE,QAAQ,OACT,CACF;AAED,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MACR,4CAA4C,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aAChF;;;AAIH,MAAa,qBAAqB,OAAO,QAAgB,OAAe;CACtE,MAAM,WAAW,MAAM,OAAO,mBAC5B,6BAA6B,GAAG,WAChC,EACE,QAAQ,QACT,CACF;AAED,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MACR,kCAAkC,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aACrE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let debug = require("debug");
|
|
3
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
4
|
+
|
|
5
|
+
//#region src/resources/url-token.ts
|
|
6
|
+
const log = (0, debug.default)("ef:api:url-token");
|
|
7
|
+
const createURLToken = async (client, url) => {
|
|
8
|
+
log("Creating signed url for", url);
|
|
9
|
+
const response = await client.authenticatedFetch("/api/v1/url-token", {
|
|
10
|
+
method: "POST",
|
|
11
|
+
body: JSON.stringify({ url })
|
|
12
|
+
});
|
|
13
|
+
if (!response.ok) throw new Error(`Failed to create signed url: ${response.status} ${response.statusText} ${await response.text()}`);
|
|
14
|
+
return (await response.json()).token;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.createURLToken = createURLToken;
|
|
19
|
+
//# sourceMappingURL=url-token.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-token.cjs","names":[],"sources":["../../src/resources/url-token.ts"],"sourcesContent":["import debug from \"debug\";\n\nimport type { Client } from \"../client.js\";\n\nconst log = debug(\"ef:api:url-token\");\n\nexport interface URLTokenResult {\n token: string;\n}\n\nexport const createURLToken = async (client: Client, url: string) => {\n log(\"Creating signed url for\", url);\n const response = await client.authenticatedFetch(\"/api/v1/url-token\", {\n method: \"POST\",\n body: JSON.stringify({\n url,\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to create signed url: ${response.status} ${response.statusText} ${await response.text()}`,\n );\n }\n\n return ((await response.json()) as URLTokenResult).token;\n};\n"],"mappings":";;;;;AAIA,MAAM,yBAAY,mBAAmB;AAMrC,MAAa,iBAAiB,OAAO,QAAgB,QAAgB;AACnE,KAAI,2BAA2B,IAAI;CACnC,MAAM,WAAW,MAAM,OAAO,mBAAmB,qBAAqB;EACpE,QAAQ;EACR,MAAM,KAAK,UAAU,EACnB,KACD,CAAC;EACH,CAAC;AAEF,KAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MACR,gCAAgC,SAAS,OAAO,GAAG,SAAS,WAAW,GAAG,MAAM,SAAS,MAAM,GAChG;AAGH,SAAS,MAAM,SAAS,MAAM,EAAqB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Client } from "../client.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/resources/url-token.d.ts
|
|
4
|
+
interface URLTokenResult {
|
|
5
|
+
token: string;
|
|
6
|
+
}
|
|
7
|
+
declare const createURLToken: (client: Client, url: string) => Promise<string>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { URLTokenResult, createURLToken };
|
|
10
|
+
//# sourceMappingURL=url-token.d.cts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_CHUNK_SIZE_BYTES = require('./CHUNK_SIZE_BYTES.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/streamChunker.ts
|
|
4
|
+
async function* streamChunker(readableStream, chunkSize = require_CHUNK_SIZE_BYTES.CHUNK_SIZE_BYTES) {
|
|
5
|
+
const reader = readableStream.getReader();
|
|
6
|
+
let buffer = new Uint8Array(0);
|
|
7
|
+
try {
|
|
8
|
+
while (true) {
|
|
9
|
+
const { done, value } = await reader.read();
|
|
10
|
+
if (done) break;
|
|
11
|
+
const chunk = value;
|
|
12
|
+
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
13
|
+
newBuffer.set(buffer);
|
|
14
|
+
newBuffer.set(chunk, buffer.length);
|
|
15
|
+
buffer = newBuffer;
|
|
16
|
+
while (buffer.length >= chunkSize) {
|
|
17
|
+
yield buffer.slice(0, chunkSize);
|
|
18
|
+
buffer = buffer.slice(chunkSize);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (buffer.length > 0) yield buffer;
|
|
22
|
+
} finally {
|
|
23
|
+
reader.releaseLock();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.streamChunker = streamChunker;
|
|
29
|
+
//# sourceMappingURL=streamChunker.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamChunker.cjs","names":["CHUNK_SIZE_BYTES"],"sources":["../src/streamChunker.ts"],"sourcesContent":["import { CHUNK_SIZE_BYTES } from \"./CHUNK_SIZE_BYTES.js\";\n\nexport async function* streamChunker(\n readableStream: ReadableStream,\n chunkSize = CHUNK_SIZE_BYTES,\n) {\n const reader = readableStream.getReader();\n let buffer = new Uint8Array(0);\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const chunk = value;\n const newBuffer = new Uint8Array(buffer.length + chunk.length);\n newBuffer.set(buffer);\n newBuffer.set(chunk, buffer.length);\n buffer = newBuffer;\n\n while (buffer.length >= chunkSize) {\n yield buffer.slice(0, chunkSize);\n buffer = buffer.slice(chunkSize);\n }\n }\n\n if (buffer.length > 0) {\n yield buffer;\n }\n } finally {\n reader.releaseLock();\n }\n}\n"],"mappings":";;;AAEA,gBAAuB,cACrB,gBACA,YAAYA,2CACZ;CACA,MAAM,SAAS,eAAe,WAAW;CACzC,IAAI,SAAS,IAAI,WAAW,EAAE;AAE9B,KAAI;AACF,SAAO,MAAM;GACX,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,MAAM;AAC3C,OAAI,KAAM;GAEV,MAAM,QAAQ;GACd,MAAM,YAAY,IAAI,WAAW,OAAO,SAAS,MAAM,OAAO;AAC9D,aAAU,IAAI,OAAO;AACrB,aAAU,IAAI,OAAO,OAAO,OAAO;AACnC,YAAS;AAET,UAAO,OAAO,UAAU,WAAW;AACjC,UAAM,OAAO,MAAM,GAAG,UAAU;AAChC,aAAS,OAAO,MAAM,UAAU;;;AAIpC,MAAI,OAAO,SAAS,EAClB,OAAM;WAEA;AACR,SAAO,aAAa"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_CHUNK_SIZE_BYTES = require('./CHUNK_SIZE_BYTES.cjs');
|
|
3
|
+
const require_streamChunker = require('./streamChunker.cjs');
|
|
4
|
+
let debug = require("debug");
|
|
5
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
6
|
+
|
|
7
|
+
//#region src/uploadChunks.ts
|
|
8
|
+
const log = (0, debug.default)("ef:api:uploadChunk");
|
|
9
|
+
const uploadChunk = async (client, { url, chunkBuffer, chunkNumber, fileSize, chunkSizeBytes = require_CHUNK_SIZE_BYTES.CHUNK_SIZE_BYTES }) => {
|
|
10
|
+
const startByte = chunkNumber * chunkSizeBytes;
|
|
11
|
+
const endByte = startByte + chunkBuffer.length - 1;
|
|
12
|
+
log(`Uploading chunk ${chunkNumber} for ${url}`);
|
|
13
|
+
const response = await client.authenticatedFetch(url, {
|
|
14
|
+
method: "POST",
|
|
15
|
+
headers: {
|
|
16
|
+
"Content-Range": `bytes=${startByte}-${endByte}/${fileSize}`,
|
|
17
|
+
"Content-Type": "application/octet-stream"
|
|
18
|
+
},
|
|
19
|
+
body: chunkBuffer
|
|
20
|
+
});
|
|
21
|
+
if (response.ok) {
|
|
22
|
+
if (response.status === 201) {
|
|
23
|
+
log(`File ${url} fully uploaded`);
|
|
24
|
+
return {
|
|
25
|
+
complete: true,
|
|
26
|
+
body: await response.json()
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (response.status === 202) {
|
|
30
|
+
log(`File ${url} chunk ${chunkNumber} uploaded`);
|
|
31
|
+
return {
|
|
32
|
+
complete: false,
|
|
33
|
+
body: await response.json()
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Failed to upload chunk ${chunkNumber} for ${url} ${response.status} ${response.statusText}`);
|
|
38
|
+
};
|
|
39
|
+
function uploadChunks(client, { url, fileSize, fileStream, maxSize, chunkSizeBytes = require_CHUNK_SIZE_BYTES.CHUNK_SIZE_BYTES }) {
|
|
40
|
+
const makeGenerator = async function* () {
|
|
41
|
+
if (fileSize > maxSize) throw new Error(`File size ${fileSize} bytes exceeds limit ${maxSize} bytes`);
|
|
42
|
+
log("Checking upload status", url);
|
|
43
|
+
const uploadStatus = await client.authenticatedFetch(url);
|
|
44
|
+
yield {
|
|
45
|
+
type: "progress",
|
|
46
|
+
progress: 0
|
|
47
|
+
};
|
|
48
|
+
if (uploadStatus.status === 200) {
|
|
49
|
+
log("Chunk already uploaded");
|
|
50
|
+
yield {
|
|
51
|
+
type: "progress",
|
|
52
|
+
progress: 1
|
|
53
|
+
};
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let chunkNumber = 0;
|
|
57
|
+
let complete = false;
|
|
58
|
+
for await (const chunkBuffer of require_streamChunker.streamChunker(fileStream, chunkSizeBytes)) {
|
|
59
|
+
log(`Uploading chunk ${chunkNumber}`);
|
|
60
|
+
({complete} = await uploadChunk(client, {
|
|
61
|
+
url,
|
|
62
|
+
chunkBuffer,
|
|
63
|
+
chunkNumber,
|
|
64
|
+
fileSize,
|
|
65
|
+
chunkSizeBytes
|
|
66
|
+
}));
|
|
67
|
+
chunkNumber++;
|
|
68
|
+
yield {
|
|
69
|
+
type: "progress",
|
|
70
|
+
progress: Math.min(1, chunkNumber / (fileSize / chunkSizeBytes))
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (!complete) throw new Error("Did not complete upload");
|
|
74
|
+
};
|
|
75
|
+
const generator = makeGenerator();
|
|
76
|
+
generator.whenUploaded = async () => {
|
|
77
|
+
if (fileSize > maxSize) throw new Error(`File size ${fileSize} bytes exceeds limit ${maxSize} bytes`);
|
|
78
|
+
const events = [];
|
|
79
|
+
for await (const event of generator) events.push(event);
|
|
80
|
+
return events;
|
|
81
|
+
};
|
|
82
|
+
return generator;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
exports.uploadChunks = uploadChunks;
|
|
87
|
+
//# sourceMappingURL=uploadChunks.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadChunks.cjs","names":["CHUNK_SIZE_BYTES","streamChunker","events: UploadChunkEvent[]"],"sources":["../src/uploadChunks.ts"],"sourcesContent":["import debug from \"debug\";\n\nimport { CHUNK_SIZE_BYTES } from \"./CHUNK_SIZE_BYTES.js\";\nimport type { Client } from \"./client.js\";\nimport { streamChunker } from \"./streamChunker.js\";\n\nconst log = debug(\"ef:api:uploadChunk\");\n\ninterface UploadChunkOptions {\n url: string;\n chunkBuffer: Uint8Array;\n chunkNumber: number;\n fileSize: number;\n chunkSizeBytes?: number;\n}\n\n/**\n * @internal\n */\nexport interface IteratorWithPromise<T> extends AsyncGenerator<\n T,\n void,\n unknown\n> {\n whenUploaded: () => Promise<T[]>;\n}\n\nexport const fakeCompleteUpload = (): IteratorWithPromise<UploadChunkEvent> => {\n const makeGenerator = async function* (): AsyncGenerator<\n UploadChunkEvent,\n void,\n unknown\n > {\n yield { type: \"progress\", progress: 1 };\n };\n\n const generator = makeGenerator() as IteratorWithPromise<UploadChunkEvent>;\n generator.whenUploaded = async () => {\n return [{ type: \"progress\", progress: 1 }];\n };\n return generator;\n};\n\nconst uploadChunk = async (\n client: Client,\n {\n url,\n chunkBuffer,\n chunkNumber,\n fileSize,\n chunkSizeBytes = CHUNK_SIZE_BYTES,\n }: UploadChunkOptions,\n) => {\n const startByte = chunkNumber * chunkSizeBytes;\n const endByte = startByte + chunkBuffer.length - 1;\n\n log(`Uploading chunk ${chunkNumber} for ${url}`);\n const response = await client.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Range\": `bytes=${startByte}-${endByte}/${fileSize}`,\n \"Content-Type\": \"application/octet-stream\",\n },\n body: chunkBuffer as BodyInit,\n });\n\n if (response.ok) {\n if (response.status === 201) {\n log(`File ${url} fully uploaded`);\n return { complete: true, body: await response.json() };\n }\n if (response.status === 202) {\n log(`File ${url} chunk ${chunkNumber} uploaded`);\n return { complete: false, body: await response.json() };\n }\n }\n\n throw new Error(\n `Failed to upload chunk ${chunkNumber} for ${url} ${response.status} ${response.statusText}`,\n );\n};\n\ninterface UploadChunksOptions {\n url: string;\n fileStream: ReadableStream;\n fileSize: number;\n maxSize: number;\n chunkSizeBytes?: number;\n}\n\nexport interface UploadChunkEvent {\n type: \"progress\";\n progress: number;\n}\n\nexport function uploadChunks(\n client: Client,\n {\n url,\n fileSize,\n fileStream,\n maxSize,\n chunkSizeBytes = CHUNK_SIZE_BYTES,\n }: UploadChunksOptions,\n): IteratorWithPromise<UploadChunkEvent> {\n const makeGenerator = async function* (): AsyncGenerator<\n UploadChunkEvent,\n void,\n unknown\n > {\n if (fileSize > maxSize) {\n throw new Error(\n `File size ${fileSize} bytes exceeds limit ${maxSize} bytes`,\n );\n }\n\n log(\"Checking upload status\", url);\n const uploadStatus = await client.authenticatedFetch(url);\n\n yield { type: \"progress\", progress: 0 };\n\n if (uploadStatus.status === 200) {\n log(\"Chunk already uploaded\");\n yield { type: \"progress\", progress: 1 };\n return;\n }\n\n let chunkNumber = 0;\n let complete = false;\n for await (const chunkBuffer of streamChunker(fileStream, chunkSizeBytes)) {\n log(`Uploading chunk ${chunkNumber}`);\n ({ complete } = await uploadChunk(client, {\n url: url,\n chunkBuffer,\n chunkNumber,\n fileSize,\n chunkSizeBytes,\n }));\n chunkNumber++;\n yield {\n type: \"progress\",\n progress: Math.min(1, chunkNumber / (fileSize / chunkSizeBytes)),\n };\n }\n if (!complete) {\n throw new Error(\"Did not complete upload\");\n }\n };\n\n const generator = makeGenerator() as IteratorWithPromise<UploadChunkEvent>;\n generator.whenUploaded = async () => {\n if (fileSize > maxSize) {\n throw new Error(\n `File size ${fileSize} bytes exceeds limit ${maxSize} bytes`,\n );\n }\n const events: UploadChunkEvent[] = [];\n for await (const event of generator) {\n events.push(event);\n }\n return events;\n };\n return generator;\n}\n"],"mappings":";;;;;;;AAMA,MAAM,yBAAY,qBAAqB;AAqCvC,MAAM,cAAc,OAClB,QACA,EACE,KACA,aACA,aACA,UACA,iBAAiBA,gDAEhB;CACH,MAAM,YAAY,cAAc;CAChC,MAAM,UAAU,YAAY,YAAY,SAAS;AAEjD,KAAI,mBAAmB,YAAY,OAAO,MAAM;CAChD,MAAM,WAAW,MAAM,OAAO,mBAAmB,KAAK;EACpD,QAAQ;EACR,SAAS;GACP,iBAAiB,SAAS,UAAU,GAAG,QAAQ,GAAG;GAClD,gBAAgB;GACjB;EACD,MAAM;EACP,CAAC;AAEF,KAAI,SAAS,IAAI;AACf,MAAI,SAAS,WAAW,KAAK;AAC3B,OAAI,QAAQ,IAAI,iBAAiB;AACjC,UAAO;IAAE,UAAU;IAAM,MAAM,MAAM,SAAS,MAAM;IAAE;;AAExD,MAAI,SAAS,WAAW,KAAK;AAC3B,OAAI,QAAQ,IAAI,SAAS,YAAY,WAAW;AAChD,UAAO;IAAE,UAAU;IAAO,MAAM,MAAM,SAAS,MAAM;IAAE;;;AAI3D,OAAM,IAAI,MACR,0BAA0B,YAAY,OAAO,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aACjF;;AAgBH,SAAgB,aACd,QACA,EACE,KACA,UACA,YACA,SACA,iBAAiBA,6CAEoB;CACvC,MAAM,gBAAgB,mBAIpB;AACA,MAAI,WAAW,QACb,OAAM,IAAI,MACR,aAAa,SAAS,uBAAuB,QAAQ,QACtD;AAGH,MAAI,0BAA0B,IAAI;EAClC,MAAM,eAAe,MAAM,OAAO,mBAAmB,IAAI;AAEzD,QAAM;GAAE,MAAM;GAAY,UAAU;GAAG;AAEvC,MAAI,aAAa,WAAW,KAAK;AAC/B,OAAI,yBAAyB;AAC7B,SAAM;IAAE,MAAM;IAAY,UAAU;IAAG;AACvC;;EAGF,IAAI,cAAc;EAClB,IAAI,WAAW;AACf,aAAW,MAAM,eAAeC,oCAAc,YAAY,eAAe,EAAE;AACzE,OAAI,mBAAmB,cAAc;AACrC,IAAC,CAAE,YAAa,MAAM,YAAY,QAAQ;IACnC;IACL;IACA;IACA;IACA;IACD,CAAC;AACF;AACA,SAAM;IACJ,MAAM;IACN,UAAU,KAAK,IAAI,GAAG,eAAe,WAAW,gBAAgB;IACjE;;AAEH,MAAI,CAAC,SACH,OAAM,IAAI,MAAM,0BAA0B;;CAI9C,MAAM,YAAY,eAAe;AACjC,WAAU,eAAe,YAAY;AACnC,MAAI,WAAW,QACb,OAAM,IAAI,MACR,aAAa,SAAS,uBAAuB,QAAQ,QACtD;EAEH,MAAMC,SAA6B,EAAE;AACrC,aAAW,MAAM,SAAS,UACxB,QAAO,KAAK,MAAM;AAEpB,SAAO;;AAET,QAAO"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/uploadChunks.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
interface IteratorWithPromise<T> extends AsyncGenerator<T, void, unknown> {
|
|
6
|
+
whenUploaded: () => Promise<T[]>;
|
|
7
|
+
}
|
|
8
|
+
interface UploadChunkEvent {
|
|
9
|
+
type: "progress";
|
|
10
|
+
progress: number;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { IteratorWithPromise, UploadChunkEvent };
|
|
14
|
+
//# sourceMappingURL=uploadChunks.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertTypesMatch.cjs","names":[],"sources":["../../src/utils/assertTypesMatch.ts"],"sourcesContent":["// Type helper that will cause a compilation error\ntype Equals<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2\n ? true\n : false;\n// Force error with const assertion\nexport const assertTypesMatch = <T, U>(\n value: Equals<T, U> extends true ? true : never,\n) => value;\n"],"mappings":";;AAMA,MAAa,oBACX,UACG"}
|