@editframe/api 0.9.0-beta.3 → 0.10.0-beta.3
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/resources/caption-file.d.ts +4 -3
- package/dist/resources/caption-file.js +6 -9
- package/dist/resources/image-file.d.ts +4 -3
- package/dist/resources/image-file.js +3 -3
- package/dist/resources/isobmff-file.d.ts +5 -3
- package/dist/resources/isobmff-file.js +6 -9
- package/dist/resources/isobmff-track.js +5 -8
- package/dist/resources/renders.d.ts +5 -4
- package/dist/resources/renders.js +3 -3
- package/dist/resources/unprocessed-file.d.ts +7 -3
- package/dist/resources/unprocessed-file.js +52 -38
- package/dist/uploadChunks.js +6 -0
- package/package.json +2 -2
- package/src/resources/caption-file.test.ts +12 -15
- package/src/resources/caption-file.ts +7 -9
- package/src/resources/image-file.test.ts +17 -10
- package/src/resources/image-file.ts +4 -3
- package/src/resources/isobmff-file.test.ts +6 -6
- package/src/resources/isobmff-file.ts +8 -9
- package/src/resources/isobmff-track.test.ts +13 -5
- package/src/resources/isobmff-track.ts +5 -8
- package/src/resources/renders.test.ts +5 -5
- package/src/resources/renders.ts +5 -4
- package/src/resources/unprocessed-file.test.ts +119 -15
- package/src/resources/unprocessed-file.ts +69 -47
|
@@ -31,7 +31,7 @@ const FileProcessors = z.array(FileProcessor).refine(
|
|
|
31
31
|
const MAX_FILE_SIZE = 1024 * 1024 * 1024; // 1GiB
|
|
32
32
|
|
|
33
33
|
export const CreateUnprocessedFilePayload = z.object({
|
|
34
|
-
|
|
34
|
+
md5: z.string(),
|
|
35
35
|
filename: z.string(),
|
|
36
36
|
processes: FileProcessors.optional(),
|
|
37
37
|
byte_size: z.number().int().max(MAX_FILE_SIZE),
|
|
@@ -44,7 +44,9 @@ export const UpdateUnprocessedFilePayload = z.object({
|
|
|
44
44
|
export interface CreateUnprocessedFileResult {
|
|
45
45
|
byte_size: number;
|
|
46
46
|
next_byte: number;
|
|
47
|
+
complete: boolean;
|
|
47
48
|
id: string;
|
|
49
|
+
md5: string;
|
|
48
50
|
processes: z.infer<typeof FileProcessors>;
|
|
49
51
|
asset_id: string;
|
|
50
52
|
}
|
|
@@ -52,7 +54,9 @@ export interface CreateUnprocessedFileResult {
|
|
|
52
54
|
export interface UpdateUnprocessedFileResult {
|
|
53
55
|
byte_size?: number;
|
|
54
56
|
next_byte: number;
|
|
57
|
+
complete: boolean;
|
|
55
58
|
id: string;
|
|
59
|
+
md5: string;
|
|
56
60
|
processes: z.infer<typeof FileProcessors>;
|
|
57
61
|
asset_id: string;
|
|
58
62
|
}
|
|
@@ -130,67 +134,85 @@ export const uploadUnprocessedFile = async (
|
|
|
130
134
|
log("Unprocessed file upload complete");
|
|
131
135
|
};
|
|
132
136
|
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
const processResource = async (
|
|
138
|
+
client: Client,
|
|
139
|
+
filename: string,
|
|
140
|
+
md5: string,
|
|
141
|
+
byteSize: number,
|
|
142
|
+
processor: z.infer<typeof FileProcessor>,
|
|
143
|
+
doUpload: (id: string) => Promise<void>,
|
|
144
|
+
) => {
|
|
145
|
+
log("Processing", { filename, md5, byteSize, processor });
|
|
140
146
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
const unprocessedFile = await createUnprocessedFile(client, {
|
|
148
|
+
md5: md5,
|
|
149
|
+
processes: [],
|
|
150
|
+
filename,
|
|
151
|
+
byte_size: byteSize,
|
|
152
|
+
});
|
|
147
153
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
readStream.push(null);
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
+
if (unprocessedFile.complete === false) {
|
|
155
|
+
await doUpload(unprocessedFile.id);
|
|
156
|
+
}
|
|
154
157
|
|
|
155
|
-
|
|
158
|
+
if (unprocessedFile.processes.includes(processor)) {
|
|
159
|
+
log("File already processed", unprocessedFile);
|
|
160
|
+
return unprocessedFile;
|
|
161
|
+
}
|
|
156
162
|
|
|
157
|
-
|
|
163
|
+
const fileInformation = await updateUnprocessedFile(
|
|
164
|
+
client,
|
|
165
|
+
unprocessedFile.id,
|
|
166
|
+
{
|
|
158
167
|
processes: [processor],
|
|
159
|
-
}
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
log("File processed", fileInformation);
|
|
171
|
+
return fileInformation;
|
|
172
|
+
};
|
|
160
173
|
|
|
161
|
-
|
|
162
|
-
|
|
174
|
+
const buildBufferProcessor = (processor: z.infer<typeof FileProcessor>) => {
|
|
175
|
+
return async (client: Client, buffer: Buffer, filename = "buffer") => {
|
|
176
|
+
log(`Processing file buffer: ${processor}`, filename);
|
|
177
|
+
const md5 = md5Buffer(buffer);
|
|
178
|
+
|
|
179
|
+
return await processResource(
|
|
180
|
+
client,
|
|
181
|
+
filename,
|
|
182
|
+
md5,
|
|
183
|
+
buffer.byteLength,
|
|
184
|
+
processor,
|
|
185
|
+
async (id: string) => {
|
|
186
|
+
const readStream = new Readable({
|
|
187
|
+
read() {
|
|
188
|
+
readStream.push(buffer);
|
|
189
|
+
readStream.push(null);
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
await uploadUnprocessedFile(client, id, readStream, buffer.byteLength);
|
|
194
|
+
},
|
|
195
|
+
);
|
|
163
196
|
};
|
|
164
197
|
};
|
|
165
198
|
|
|
166
199
|
const buildFileProcessor = (processor: z.infer<typeof FileProcessor>) => {
|
|
167
200
|
return async (client: Client, filePath: string) => {
|
|
168
201
|
log(`Processing file ${processor}`, filePath);
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
log("File ID", fileId);
|
|
172
|
-
await createUnprocessedFile(client, {
|
|
173
|
-
id: fileId,
|
|
174
|
-
processes: [],
|
|
175
|
-
filename: basename(filePath),
|
|
176
|
-
byte_size: (await stat(filePath)).size,
|
|
177
|
-
});
|
|
202
|
+
const md5 = await md5FilePath(filePath);
|
|
203
|
+
const byteSize = (await stat(filePath)).size;
|
|
178
204
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
await uploadUnprocessedFile(
|
|
205
|
+
return await processResource(
|
|
182
206
|
client,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
207
|
+
basename(filePath),
|
|
208
|
+
md5,
|
|
209
|
+
byteSize,
|
|
210
|
+
processor,
|
|
211
|
+
async (id: string) => {
|
|
212
|
+
const readStream = createReadStream(filePath);
|
|
213
|
+
return await uploadUnprocessedFile(client, id, readStream, byteSize);
|
|
214
|
+
},
|
|
186
215
|
);
|
|
187
|
-
|
|
188
|
-
const fileInformation = await updateUnprocessedFile(client, fileId, {
|
|
189
|
-
processes: [processor],
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
log("File processed", fileInformation);
|
|
193
|
-
return fileInformation;
|
|
194
216
|
};
|
|
195
217
|
};
|
|
196
218
|
|