@editframe/api 0.7.0-beta.8 → 0.8.0-beta.2
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/client.d.ts +8 -0
- package/dist/client.js +25 -7
- package/dist/index.d.ts +8 -0
- package/dist/index.js +11 -1
- package/dist/resources/caption-file.d.ts +20 -0
- package/dist/resources/image-file.d.ts +29 -0
- package/dist/resources/isobmff-file.d.ts +20 -0
- package/dist/resources/isobmff-track.d.ts +271 -0
- package/dist/resources/renders.d.ts +35 -0
- package/dist/resources/unprocessed-file.d.ts +43 -0
- package/dist/resources/unprocessed-file.js +142 -0
- package/dist/resources/url-token.d.ts +6 -0
- package/dist/resources/url-token.js +20 -0
- package/package.json +9 -10
- package/src/resources/caption-file.ts +1 -1
- package/src/resources/image-file.ts +1 -1
- package/src/resources/isobmff-file.ts +1 -1
- package/src/resources/isobmff-track.ts +1 -1
- package/src/resources/renders.ts +1 -1
- package/src/resources/unprocessed-file.ts +192 -0
- package/src/resources/url-token.ts +27 -0
- package/dist/client.cjs +0 -29
- package/dist/index.cjs +0 -24
- package/dist/resources/caption-file.cjs +0 -56
- package/dist/resources/image-file.cjs +0 -52
- package/dist/resources/isobmff-file.cjs +0 -56
- package/dist/resources/isobmff-track.cjs +0 -71
- package/dist/resources/renders.cjs +0 -56
- package/src/util/nodeStreamToWebStream.ts +0 -20
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
const log = debug("ef:api:url-token");
|
|
3
|
+
const createURLToken = async (client, url) => {
|
|
4
|
+
log("Creating signed url for", url);
|
|
5
|
+
const response = await client.authenticatedFetch("/api/v1/url-token", {
|
|
6
|
+
method: "POST",
|
|
7
|
+
body: JSON.stringify({
|
|
8
|
+
url
|
|
9
|
+
})
|
|
10
|
+
});
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Failed to create signed url: ${response.status} ${response.statusText} ${await response.text()}`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return (await response.json()).token;
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
createURLToken
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editframe/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-beta.2",
|
|
4
4
|
"description": "API functions for EditFrame",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"import": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
},
|
|
11
|
-
"require": {
|
|
12
|
-
"default": "./dist/index.cjs",
|
|
13
|
-
"types": "./dist/index.d.ts"
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
14
10
|
}
|
|
15
11
|
}
|
|
16
12
|
},
|
|
@@ -23,15 +19,18 @@
|
|
|
23
19
|
"author": "",
|
|
24
20
|
"license": "UNLICENSED",
|
|
25
21
|
"devDependencies": {
|
|
26
|
-
"@types/
|
|
27
|
-
"
|
|
22
|
+
"@types/jsonwebtoken": "^9.0.6",
|
|
23
|
+
"@types/node": "^20.14.13",
|
|
24
|
+
"typescript": "^5.5.4",
|
|
28
25
|
"vite": "^5.2.11",
|
|
29
26
|
"vite-plugin-dts": "^3.9.1",
|
|
30
27
|
"vite-tsconfig-paths": "^4.3.2"
|
|
31
28
|
},
|
|
32
29
|
"dependencies": {
|
|
33
|
-
"@editframe/assets": "0.
|
|
30
|
+
"@editframe/assets": "0.8.0-beta.2",
|
|
34
31
|
"debug": "^4.3.5",
|
|
32
|
+
"jsonwebtoken": "^9.0.2",
|
|
33
|
+
"node-fetch": "^3.3.2",
|
|
35
34
|
"zod": "^3.23.8"
|
|
36
35
|
}
|
|
37
36
|
}
|
package/src/resources/renders.ts
CHANGED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { createReadStream } from "node:fs";
|
|
4
|
+
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import debug from "debug";
|
|
7
|
+
|
|
8
|
+
import { md5FilePath, md5Buffer } from "@editframe/assets";
|
|
9
|
+
|
|
10
|
+
import type { Client } from "../client.ts";
|
|
11
|
+
|
|
12
|
+
const log = debug("ef:api:unprocessed-file");
|
|
13
|
+
|
|
14
|
+
const FileProcessors = z
|
|
15
|
+
.array(z.union([z.literal("isobmff"), z.literal("captions")]))
|
|
16
|
+
.refine(
|
|
17
|
+
(value) => {
|
|
18
|
+
return new Set(value).size === value.length;
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
message: "Processors list must not include duplicates",
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const CreateUnprocessedFilePayload = z.object({
|
|
26
|
+
id: z.string(),
|
|
27
|
+
filename: z.string(),
|
|
28
|
+
processes: FileProcessors.optional(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const UpdateUnprocessedFilePayload = z.object({
|
|
32
|
+
processes: FileProcessors.optional(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export interface CreateUnprocessedFileResult {
|
|
36
|
+
byte_size: number;
|
|
37
|
+
last_received_byte: number;
|
|
38
|
+
id: string;
|
|
39
|
+
processes: z.infer<typeof FileProcessors>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface UpdateUnprocessedFileResult {
|
|
43
|
+
byte_size: number;
|
|
44
|
+
last_received_byte: number;
|
|
45
|
+
id: string;
|
|
46
|
+
processes: z.infer<typeof FileProcessors>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const createUnprocessedFile = async (
|
|
50
|
+
client: Client,
|
|
51
|
+
payload: z.infer<typeof CreateUnprocessedFilePayload>,
|
|
52
|
+
) => {
|
|
53
|
+
log("Creating an unprocessed file", payload);
|
|
54
|
+
const response = await client.authenticatedFetch(
|
|
55
|
+
"/api/v1/unprocessed_files",
|
|
56
|
+
{
|
|
57
|
+
method: "POST",
|
|
58
|
+
body: JSON.stringify(payload),
|
|
59
|
+
},
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
log(
|
|
63
|
+
"Unprocessed file created",
|
|
64
|
+
response.status,
|
|
65
|
+
response.statusText,
|
|
66
|
+
response.headers,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
switch (response.status) {
|
|
70
|
+
case 200: {
|
|
71
|
+
return (await response.json()) as CreateUnprocessedFileResult;
|
|
72
|
+
}
|
|
73
|
+
default: {
|
|
74
|
+
console.error(
|
|
75
|
+
`Failed to create file ${response.status} ${response.statusText}`,
|
|
76
|
+
);
|
|
77
|
+
console.error(await response.text());
|
|
78
|
+
throw new Error("Failed to create unprocessed file");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const updateUnprocessedFile = async (
|
|
84
|
+
client: Client,
|
|
85
|
+
fileId: string,
|
|
86
|
+
payload: Partial<z.infer<typeof UpdateUnprocessedFilePayload>>,
|
|
87
|
+
) => {
|
|
88
|
+
log("Updating unprocessed file", fileId, payload);
|
|
89
|
+
const response = await client.authenticatedFetch(
|
|
90
|
+
`/api/v1/unprocessed_files/${fileId}`,
|
|
91
|
+
{
|
|
92
|
+
method: "POST",
|
|
93
|
+
body: JSON.stringify(payload),
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
log("Unprocessed file updated", response);
|
|
98
|
+
|
|
99
|
+
switch (response.status) {
|
|
100
|
+
case 200: {
|
|
101
|
+
return (await response.json()) as UpdateUnprocessedFileResult;
|
|
102
|
+
}
|
|
103
|
+
default: {
|
|
104
|
+
console.error(
|
|
105
|
+
`Failed to update file ${response.status} ${response.statusText}`,
|
|
106
|
+
);
|
|
107
|
+
throw new Error("Failed to update unprocessed file");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const uploadUnprocessedFile = async (
|
|
113
|
+
client: Client,
|
|
114
|
+
fileId: string,
|
|
115
|
+
fileStream: Readable,
|
|
116
|
+
) => {
|
|
117
|
+
log("Uploading unprocessed file", fileId);
|
|
118
|
+
const unprocessedFile = await client.authenticatedFetch(
|
|
119
|
+
`/api/v1/unprocessed_files/${fileId}/upload`,
|
|
120
|
+
{
|
|
121
|
+
method: "POST",
|
|
122
|
+
body: fileStream,
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
log("Unprocessed file track uploaded", unprocessedFile);
|
|
127
|
+
switch (unprocessedFile.status) {
|
|
128
|
+
case 200: {
|
|
129
|
+
return unprocessedFile.json();
|
|
130
|
+
}
|
|
131
|
+
default: {
|
|
132
|
+
console.error("Failed to upload unprocessed file");
|
|
133
|
+
console.error(unprocessedFile.status, unprocessedFile.statusText);
|
|
134
|
+
throw new Error("Failed to upload unprocessed file");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const processAVFileBuffer = async (
|
|
140
|
+
client: Client,
|
|
141
|
+
buffer: Buffer,
|
|
142
|
+
filename = "buffer",
|
|
143
|
+
) => {
|
|
144
|
+
log("Processing AV file buffer");
|
|
145
|
+
const fileId = md5Buffer(buffer);
|
|
146
|
+
|
|
147
|
+
log("File ID", fileId);
|
|
148
|
+
await createUnprocessedFile(client, {
|
|
149
|
+
id: fileId,
|
|
150
|
+
processes: [],
|
|
151
|
+
filename,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const readStream = new Readable({
|
|
155
|
+
read() {
|
|
156
|
+
readStream.push(buffer);
|
|
157
|
+
readStream.push(null);
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
await uploadUnprocessedFile(client, fileId, readStream);
|
|
162
|
+
|
|
163
|
+
const fileInformation = await updateUnprocessedFile(client, fileId, {
|
|
164
|
+
processes: ["isobmff"],
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
log("File processed", fileInformation);
|
|
168
|
+
return fileInformation;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export const processAVFile = async (client: Client, filePath: string) => {
|
|
172
|
+
log("Processing AV file", filePath);
|
|
173
|
+
const fileId = await md5FilePath(filePath);
|
|
174
|
+
|
|
175
|
+
log("File ID", fileId);
|
|
176
|
+
await createUnprocessedFile(client, {
|
|
177
|
+
id: fileId,
|
|
178
|
+
processes: [],
|
|
179
|
+
filename: basename(filePath),
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const readStream = createReadStream(filePath);
|
|
183
|
+
|
|
184
|
+
await uploadUnprocessedFile(client, fileId, readStream);
|
|
185
|
+
|
|
186
|
+
const fileInformation = await updateUnprocessedFile(client, fileId, {
|
|
187
|
+
processes: ["isobmff"],
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
log("File processed", fileInformation);
|
|
191
|
+
return fileInformation;
|
|
192
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
|
|
3
|
+
import type { Client } from "../client.ts";
|
|
4
|
+
|
|
5
|
+
const log = debug("ef:api:url-token");
|
|
6
|
+
|
|
7
|
+
export interface URLTokenResult {
|
|
8
|
+
token: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const createURLToken = async (client: Client, url: string) => {
|
|
12
|
+
log("Creating signed url for", url);
|
|
13
|
+
const response = await client.authenticatedFetch("/api/v1/url-token", {
|
|
14
|
+
method: "POST",
|
|
15
|
+
body: JSON.stringify({
|
|
16
|
+
url,
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Failed to create signed url: ${response.status} ${response.statusText} ${await response.text()}`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return ((await response.json()) as URLTokenResult).token;
|
|
27
|
+
};
|
package/dist/client.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const debug = require("debug");
|
|
4
|
-
const fetch = require("node-fetch");
|
|
5
|
-
const log = debug("ef:api:client");
|
|
6
|
-
class Client {
|
|
7
|
-
constructor(token, efHost) {
|
|
8
|
-
this.token = token;
|
|
9
|
-
this.efHost = efHost;
|
|
10
|
-
this.authenticatedFetch = async (path, init = {}) => {
|
|
11
|
-
init.headers ||= {};
|
|
12
|
-
log(
|
|
13
|
-
"Authenticated fetch",
|
|
14
|
-
{ path, init },
|
|
15
|
-
"(Token will be added as Bearer token)"
|
|
16
|
-
);
|
|
17
|
-
Object.assign(init.headers, {
|
|
18
|
-
Authorization: `Bearer ${this.token}`,
|
|
19
|
-
"Content-Type": "application/json"
|
|
20
|
-
});
|
|
21
|
-
const url = new URL(path, this.efHost);
|
|
22
|
-
const response = await fetch(url, init);
|
|
23
|
-
log("Authenticated fetch response", response.status, response.statusText);
|
|
24
|
-
return response;
|
|
25
|
-
};
|
|
26
|
-
log("Creating client with efHost", efHost, "and !!token", !!token);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.Client = Client;
|
package/dist/index.cjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const captionFile = require("./resources/caption-file.cjs");
|
|
4
|
-
const imageFile = require("./resources/image-file.cjs");
|
|
5
|
-
const isobmffFile = require("./resources/isobmff-file.cjs");
|
|
6
|
-
const isobmffTrack = require("./resources/isobmff-track.cjs");
|
|
7
|
-
const renders = require("./resources/renders.cjs");
|
|
8
|
-
const client = require("./client.cjs");
|
|
9
|
-
exports.CreateCaptionFilePayload = captionFile.CreateCaptionFilePayload;
|
|
10
|
-
exports.createCaptionFile = captionFile.createCaptionFile;
|
|
11
|
-
exports.uploadCaptionFile = captionFile.uploadCaptionFile;
|
|
12
|
-
exports.CreateImageFilePayload = imageFile.CreateImageFilePayload;
|
|
13
|
-
exports.createImageFile = imageFile.createImageFile;
|
|
14
|
-
exports.uploadImageFile = imageFile.uploadImageFile;
|
|
15
|
-
exports.CreateISOBMFFFilePayload = isobmffFile.CreateISOBMFFFilePayload;
|
|
16
|
-
exports.createISOBMFFFile = isobmffFile.createISOBMFFFile;
|
|
17
|
-
exports.uploadFragmentIndex = isobmffFile.uploadFragmentIndex;
|
|
18
|
-
exports.CreateISOBMFFTrackPayload = isobmffTrack.CreateISOBMFFTrackPayload;
|
|
19
|
-
exports.createISOBMFFTrack = isobmffTrack.createISOBMFFTrack;
|
|
20
|
-
exports.uploadISOBMFFTrack = isobmffTrack.uploadISOBMFFTrack;
|
|
21
|
-
exports.CreateRenderPayload = renders.CreateRenderPayload;
|
|
22
|
-
exports.createRender = renders.createRender;
|
|
23
|
-
exports.uploadRender = renders.uploadRender;
|
|
24
|
-
exports.Client = client.Client;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const zod = require("zod");
|
|
4
|
-
const debug = require("debug");
|
|
5
|
-
const log = debug("ef:api:caption-file");
|
|
6
|
-
const CreateCaptionFilePayload = zod.z.object({
|
|
7
|
-
id: zod.z.string(),
|
|
8
|
-
filename: zod.z.string()
|
|
9
|
-
});
|
|
10
|
-
const createCaptionFile = async (client, payload) => {
|
|
11
|
-
log("Creating caption file", payload);
|
|
12
|
-
const fileCreation = await client.authenticatedFetch(
|
|
13
|
-
"/api/video2/caption_files",
|
|
14
|
-
{
|
|
15
|
-
method: "POST",
|
|
16
|
-
body: JSON.stringify(payload)
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
log("Caption file created", fileCreation);
|
|
20
|
-
switch (fileCreation.status) {
|
|
21
|
-
case 200: {
|
|
22
|
-
return await fileCreation.json();
|
|
23
|
-
}
|
|
24
|
-
default: {
|
|
25
|
-
console.error(
|
|
26
|
-
`Failed to create file ${fileCreation.status} ${fileCreation.statusText}`
|
|
27
|
-
);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const uploadCaptionFile = async (client, fileId, fileStream) => {
|
|
33
|
-
log("Uploading caption file", fileId);
|
|
34
|
-
const fileIndex = await client.authenticatedFetch(
|
|
35
|
-
`/api/video2/caption_files/${fileId}/upload`,
|
|
36
|
-
{
|
|
37
|
-
method: "POST",
|
|
38
|
-
body: fileStream
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
log("Caption file uploaded", fileIndex);
|
|
42
|
-
switch (fileIndex.status) {
|
|
43
|
-
case 200: {
|
|
44
|
-
return fileIndex.json();
|
|
45
|
-
}
|
|
46
|
-
default: {
|
|
47
|
-
console.error(
|
|
48
|
-
`Failed to upload caption ${fileIndex.status} ${fileIndex.statusText}`
|
|
49
|
-
);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
exports.CreateCaptionFilePayload = CreateCaptionFilePayload;
|
|
55
|
-
exports.createCaptionFile = createCaptionFile;
|
|
56
|
-
exports.uploadCaptionFile = uploadCaptionFile;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const zod = require("zod");
|
|
4
|
-
const debug = require("debug");
|
|
5
|
-
const log = debug("ef:api:image-file");
|
|
6
|
-
const CreateImageFilePayload = zod.z.object({
|
|
7
|
-
id: zod.z.string(),
|
|
8
|
-
height: zod.z.number().int(),
|
|
9
|
-
width: zod.z.number().int(),
|
|
10
|
-
mime_type: zod.z.enum(["image/jpeg", "image/png", "image/jpg", "image/webp"]),
|
|
11
|
-
filename: zod.z.string()
|
|
12
|
-
});
|
|
13
|
-
const createImageFile = async (client, payload) => {
|
|
14
|
-
log("Creating image file", payload);
|
|
15
|
-
const response = await client.authenticatedFetch("/api/video2/image_files", {
|
|
16
|
-
method: "POST",
|
|
17
|
-
body: JSON.stringify(payload)
|
|
18
|
-
});
|
|
19
|
-
log("Image file created", response);
|
|
20
|
-
switch (response.status) {
|
|
21
|
-
case 200: {
|
|
22
|
-
return await response.json();
|
|
23
|
-
}
|
|
24
|
-
default: {
|
|
25
|
-
console.error(
|
|
26
|
-
`Failed to create file ${response.status} ${response.statusText}`
|
|
27
|
-
);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const uploadImageFile = async (client, fileId, fileStream) => {
|
|
33
|
-
const fileIndex = await client.authenticatedFetch(
|
|
34
|
-
`/api/video2/image_files/${fileId}/upload`,
|
|
35
|
-
{
|
|
36
|
-
method: "POST",
|
|
37
|
-
body: fileStream
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
switch (fileIndex.status) {
|
|
41
|
-
case 200: {
|
|
42
|
-
return fileIndex.json();
|
|
43
|
-
}
|
|
44
|
-
default: {
|
|
45
|
-
console.error("Failed to upload image");
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
exports.CreateImageFilePayload = CreateImageFilePayload;
|
|
51
|
-
exports.createImageFile = createImageFile;
|
|
52
|
-
exports.uploadImageFile = uploadImageFile;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const zod = require("zod");
|
|
4
|
-
const debug = require("debug");
|
|
5
|
-
const log = debug("ef:api:isobmff-file");
|
|
6
|
-
const CreateISOBMFFFilePayload = zod.z.object({
|
|
7
|
-
id: zod.z.string(),
|
|
8
|
-
filename: zod.z.string()
|
|
9
|
-
});
|
|
10
|
-
const createISOBMFFFile = async (client, payload) => {
|
|
11
|
-
log("Creating isobmff file", payload);
|
|
12
|
-
const response = await client.authenticatedFetch(
|
|
13
|
-
"/api/video2/isobmff_files",
|
|
14
|
-
{
|
|
15
|
-
method: "POST",
|
|
16
|
-
body: JSON.stringify(payload)
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
log("ISOBMFF file created", response);
|
|
20
|
-
switch (response.status) {
|
|
21
|
-
case 200: {
|
|
22
|
-
return await response.json();
|
|
23
|
-
}
|
|
24
|
-
default: {
|
|
25
|
-
console.error(
|
|
26
|
-
`Failed to create file ${response.status} ${response.statusText}`
|
|
27
|
-
);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const uploadFragmentIndex = async (client, fileId, fileStream) => {
|
|
33
|
-
log("Uploading fragment index", fileId);
|
|
34
|
-
const fileIndex = await client.authenticatedFetch(
|
|
35
|
-
`/api/video2/isobmff_files/${fileId}/index/upload`,
|
|
36
|
-
{
|
|
37
|
-
method: "POST",
|
|
38
|
-
body: fileStream
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
log("Fragment index uploaded", fileIndex);
|
|
42
|
-
switch (fileIndex.status) {
|
|
43
|
-
case 200: {
|
|
44
|
-
return fileIndex.json();
|
|
45
|
-
}
|
|
46
|
-
default: {
|
|
47
|
-
console.error(
|
|
48
|
-
`Failed to create fragment index ${fileIndex.status} ${fileIndex.statusText}`
|
|
49
|
-
);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
exports.CreateISOBMFFFilePayload = CreateISOBMFFFilePayload;
|
|
55
|
-
exports.createISOBMFFFile = createISOBMFFFile;
|
|
56
|
-
exports.uploadFragmentIndex = uploadFragmentIndex;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const zod = require("zod");
|
|
4
|
-
const debug = require("debug");
|
|
5
|
-
const assets = require("@editframe/assets");
|
|
6
|
-
const log = debug("ef:api:isobmff-track");
|
|
7
|
-
const CreateISOBMFFTrackPayload = zod.z.discriminatedUnion("type", [
|
|
8
|
-
zod.z.object({
|
|
9
|
-
file_id: zod.z.string(),
|
|
10
|
-
track_id: zod.z.number().int(),
|
|
11
|
-
type: zod.z.literal("audio"),
|
|
12
|
-
probe_info: assets.AudioStreamSchema,
|
|
13
|
-
duration_ms: zod.z.number().int(),
|
|
14
|
-
codec_name: zod.z.string(),
|
|
15
|
-
byte_size: zod.z.number().int()
|
|
16
|
-
}),
|
|
17
|
-
zod.z.object({
|
|
18
|
-
file_id: zod.z.string(),
|
|
19
|
-
track_id: zod.z.number().int(),
|
|
20
|
-
type: zod.z.literal("video"),
|
|
21
|
-
probe_info: assets.VideoStreamSchema,
|
|
22
|
-
duration_ms: zod.z.number().int(),
|
|
23
|
-
codec_name: zod.z.string(),
|
|
24
|
-
byte_size: zod.z.number().int()
|
|
25
|
-
})
|
|
26
|
-
]);
|
|
27
|
-
const createISOBMFFTrack = async (client, payload) => {
|
|
28
|
-
log("Creating isobmff track", payload);
|
|
29
|
-
const response = await client.authenticatedFetch(
|
|
30
|
-
"/api/video2/isobmff_tracks",
|
|
31
|
-
{
|
|
32
|
-
method: "POST",
|
|
33
|
-
body: JSON.stringify(payload)
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
log("ISOBMFF track created", response);
|
|
37
|
-
switch (response.status) {
|
|
38
|
-
case 200: {
|
|
39
|
-
return await response.json();
|
|
40
|
-
}
|
|
41
|
-
default: {
|
|
42
|
-
console.error("Failed to create track");
|
|
43
|
-
console.error(await response.json());
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const uploadISOBMFFTrack = async (client, fileId, trackId, fileStream) => {
|
|
49
|
-
log("Uploading isobmff track", fileId, trackId);
|
|
50
|
-
const trackIndex = await client.authenticatedFetch(
|
|
51
|
-
`/api/video2/isobmff_tracks/${fileId}/${trackId}/upload`,
|
|
52
|
-
{
|
|
53
|
-
method: "POST",
|
|
54
|
-
body: fileStream
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
|
-
log("ISOBMFF track uploaded", trackIndex);
|
|
58
|
-
switch (trackIndex.status) {
|
|
59
|
-
case 200: {
|
|
60
|
-
return trackIndex.json();
|
|
61
|
-
}
|
|
62
|
-
default: {
|
|
63
|
-
console.error("Failed to upload track");
|
|
64
|
-
console.error(trackIndex.status, trackIndex.statusText);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
exports.CreateISOBMFFTrackPayload = CreateISOBMFFTrackPayload;
|
|
70
|
-
exports.createISOBMFFTrack = createISOBMFFTrack;
|
|
71
|
-
exports.uploadISOBMFFTrack = uploadISOBMFFTrack;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const zod = require("zod");
|
|
4
|
-
const debug = require("debug");
|
|
5
|
-
const log = debug("ef:api:renders");
|
|
6
|
-
const CreateRenderPayload = zod.z.object({
|
|
7
|
-
id: zod.z.string().uuid(),
|
|
8
|
-
fps: zod.z.number(),
|
|
9
|
-
width: zod.z.number().int(),
|
|
10
|
-
height: zod.z.number().int(),
|
|
11
|
-
work_slice_ms: zod.z.number().int(),
|
|
12
|
-
duration_ms: zod.z.number().int(),
|
|
13
|
-
strategy: zod.z.enum(["v1", "v2"])
|
|
14
|
-
});
|
|
15
|
-
const createRender = async (client, payload) => {
|
|
16
|
-
log("Creating render", payload);
|
|
17
|
-
const response = await client.authenticatedFetch("/api/video2/renders", {
|
|
18
|
-
method: "POST",
|
|
19
|
-
body: JSON.stringify(payload)
|
|
20
|
-
});
|
|
21
|
-
log("Render created", response);
|
|
22
|
-
switch (response.status) {
|
|
23
|
-
case 200: {
|
|
24
|
-
return await response.json();
|
|
25
|
-
}
|
|
26
|
-
default: {
|
|
27
|
-
console.error("Failed to create render");
|
|
28
|
-
console.error(await response.json());
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const uploadRender = async (client, fileId, fileStream) => {
|
|
34
|
-
log("Uploading render", fileId);
|
|
35
|
-
const fileIndex = await client.authenticatedFetch(
|
|
36
|
-
`/api/video2/renders/${fileId}/upload`,
|
|
37
|
-
{
|
|
38
|
-
method: "POST",
|
|
39
|
-
body: fileStream
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
log("Render uploaded", fileIndex);
|
|
43
|
-
switch (fileIndex.status) {
|
|
44
|
-
case 200: {
|
|
45
|
-
return fileIndex.json();
|
|
46
|
-
}
|
|
47
|
-
default: {
|
|
48
|
-
console.error("Failed to upload render");
|
|
49
|
-
console.error(fileIndex.status, fileIndex.statusText);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
exports.CreateRenderPayload = CreateRenderPayload;
|
|
55
|
-
exports.createRender = createRender;
|
|
56
|
-
exports.uploadRender = uploadRender;
|