@editframe/api 0.7.0-beta.6 → 0.8.0-beta.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/client.d.ts +8 -0
- package/dist/client.js +26 -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/caption-file.js +1 -2
- package/dist/resources/image-file.d.ts +29 -0
- package/dist/resources/image-file.js +1 -2
- package/dist/resources/isobmff-file.d.ts +20 -0
- package/dist/resources/isobmff-file.js +1 -2
- package/dist/resources/isobmff-track.d.ts +271 -0
- package/dist/resources/isobmff-track.js +1 -2
- package/dist/resources/renders.d.ts +35 -0
- package/dist/resources/renders.js +1 -2
- package/dist/resources/signed-url.d.ts +6 -0
- package/dist/resources/signed-url.js +20 -0
- package/dist/resources/unprocessed-file.d.ts +43 -0
- package/dist/resources/unprocessed-file.js +142 -0
- package/package.json +9 -10
- package/src/resources/caption-file.ts +2 -3
- package/src/resources/image-file.ts +2 -3
- package/src/resources/isobmff-file.ts +2 -3
- package/src/resources/isobmff-track.ts +2 -3
- package/src/resources/renders.ts +2 -3
- package/src/resources/signed-url.ts +27 -0
- package/src/resources/unprocessed-file.ts +192 -0
- package/dist/client.cjs +0 -28
- package/dist/index.cjs +0 -24
- package/dist/resources/caption-file.cjs +0 -57
- package/dist/resources/image-file.cjs +0 -53
- package/dist/resources/isobmff-file.cjs +0 -57
- package/dist/resources/isobmff-track.cjs +0 -72
- package/dist/resources/renders.cjs +0 -57
- package/dist/util/nodeStreamToWebStream.cjs +0 -21
- package/dist/util/nodeStreamToWebStream.js +0 -21
- package/src/util/nodeStreamToWebStream.ts +0 -20
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { createReadStream } from "node:fs";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import debug from "debug";
|
|
6
|
+
import { md5Buffer, md5FilePath } from "@editframe/assets";
|
|
7
|
+
const log = debug("ef:api:unprocessed-file");
|
|
8
|
+
const FileProcessors = z.array(z.union([z.literal("isobmff"), z.literal("captions")])).refine(
|
|
9
|
+
(value) => {
|
|
10
|
+
return new Set(value).size === value.length;
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
message: "Processors list must not include duplicates"
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
const CreateUnprocessedFilePayload = z.object({
|
|
17
|
+
id: z.string(),
|
|
18
|
+
filename: z.string(),
|
|
19
|
+
processes: FileProcessors.optional()
|
|
20
|
+
});
|
|
21
|
+
const UpdateUnprocessedFilePayload = z.object({
|
|
22
|
+
processes: FileProcessors.optional()
|
|
23
|
+
});
|
|
24
|
+
const createUnprocessedFile = async (client, payload) => {
|
|
25
|
+
log("Creating an unprocessed file", payload);
|
|
26
|
+
const response = await client.authenticatedFetch(
|
|
27
|
+
"/api/v1/unprocessed_files",
|
|
28
|
+
{
|
|
29
|
+
method: "POST",
|
|
30
|
+
body: JSON.stringify(payload)
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
log(
|
|
34
|
+
"Unprocessed file created",
|
|
35
|
+
response.status,
|
|
36
|
+
response.statusText,
|
|
37
|
+
response.headers
|
|
38
|
+
);
|
|
39
|
+
switch (response.status) {
|
|
40
|
+
case 200: {
|
|
41
|
+
return await response.json();
|
|
42
|
+
}
|
|
43
|
+
default: {
|
|
44
|
+
console.error(
|
|
45
|
+
`Failed to create file ${response.status} ${response.statusText}`
|
|
46
|
+
);
|
|
47
|
+
console.error(await response.text());
|
|
48
|
+
throw new Error("Failed to create unprocessed file");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const updateUnprocessedFile = async (client, fileId, payload) => {
|
|
53
|
+
log("Updating unprocessed file", fileId, payload);
|
|
54
|
+
const response = await client.authenticatedFetch(
|
|
55
|
+
`/api/v1/unprocessed_files/${fileId}`,
|
|
56
|
+
{
|
|
57
|
+
method: "POST",
|
|
58
|
+
body: JSON.stringify(payload)
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
log("Unprocessed file updated", response);
|
|
62
|
+
switch (response.status) {
|
|
63
|
+
case 200: {
|
|
64
|
+
return await response.json();
|
|
65
|
+
}
|
|
66
|
+
default: {
|
|
67
|
+
console.error(
|
|
68
|
+
`Failed to update file ${response.status} ${response.statusText}`
|
|
69
|
+
);
|
|
70
|
+
throw new Error("Failed to update unprocessed file");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const uploadUnprocessedFile = async (client, fileId, fileStream) => {
|
|
75
|
+
log("Uploading unprocessed file", fileId);
|
|
76
|
+
const unprocessedFile = await client.authenticatedFetch(
|
|
77
|
+
`/api/v1/unprocessed_files/${fileId}/upload`,
|
|
78
|
+
{
|
|
79
|
+
method: "POST",
|
|
80
|
+
body: fileStream
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
log("Unprocessed file track uploaded", unprocessedFile);
|
|
84
|
+
switch (unprocessedFile.status) {
|
|
85
|
+
case 200: {
|
|
86
|
+
return unprocessedFile.json();
|
|
87
|
+
}
|
|
88
|
+
default: {
|
|
89
|
+
console.error("Failed to upload unprocessed file");
|
|
90
|
+
console.error(unprocessedFile.status, unprocessedFile.statusText);
|
|
91
|
+
throw new Error("Failed to upload unprocessed file");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const processAVFileBuffer = async (client, buffer, filename = "buffer") => {
|
|
96
|
+
log("Processing AV file buffer");
|
|
97
|
+
const fileId = md5Buffer(buffer);
|
|
98
|
+
log("File ID", fileId);
|
|
99
|
+
await createUnprocessedFile(client, {
|
|
100
|
+
id: fileId,
|
|
101
|
+
processes: [],
|
|
102
|
+
filename
|
|
103
|
+
});
|
|
104
|
+
const readStream = new Readable({
|
|
105
|
+
read() {
|
|
106
|
+
readStream.push(buffer);
|
|
107
|
+
readStream.push(null);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
await uploadUnprocessedFile(client, fileId, readStream);
|
|
111
|
+
const fileInformation = await updateUnprocessedFile(client, fileId, {
|
|
112
|
+
processes: ["isobmff"]
|
|
113
|
+
});
|
|
114
|
+
log("File processed", fileInformation);
|
|
115
|
+
return fileInformation;
|
|
116
|
+
};
|
|
117
|
+
const processAVFile = async (client, filePath) => {
|
|
118
|
+
log("Processing AV file", filePath);
|
|
119
|
+
const fileId = await md5FilePath(filePath);
|
|
120
|
+
log("File ID", fileId);
|
|
121
|
+
await createUnprocessedFile(client, {
|
|
122
|
+
id: fileId,
|
|
123
|
+
processes: [],
|
|
124
|
+
filename: basename(filePath)
|
|
125
|
+
});
|
|
126
|
+
const readStream = createReadStream(filePath);
|
|
127
|
+
await uploadUnprocessedFile(client, fileId, readStream);
|
|
128
|
+
const fileInformation = await updateUnprocessedFile(client, fileId, {
|
|
129
|
+
processes: ["isobmff"]
|
|
130
|
+
});
|
|
131
|
+
log("File processed", fileInformation);
|
|
132
|
+
return fileInformation;
|
|
133
|
+
};
|
|
134
|
+
export {
|
|
135
|
+
CreateUnprocessedFilePayload,
|
|
136
|
+
UpdateUnprocessedFilePayload,
|
|
137
|
+
createUnprocessedFile,
|
|
138
|
+
processAVFile,
|
|
139
|
+
processAVFileBuffer,
|
|
140
|
+
updateUnprocessedFile,
|
|
141
|
+
uploadUnprocessedFile
|
|
142
|
+
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editframe/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-beta.1",
|
|
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.1",
|
|
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
|
}
|
|
@@ -3,8 +3,7 @@ import type { Readable } from "node:stream";
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import debug from "debug";
|
|
5
5
|
|
|
6
|
-
import type { Client } from "../client";
|
|
7
|
-
import { nodeStreamToWebStream } from "../util/nodeStreamToWebStream";
|
|
6
|
+
import type { Client } from "../client.ts";
|
|
8
7
|
|
|
9
8
|
const log = debug("ef:api:caption-file");
|
|
10
9
|
|
|
@@ -55,7 +54,7 @@ export const uploadCaptionFile = async (
|
|
|
55
54
|
`/api/video2/caption_files/${fileId}/upload`,
|
|
56
55
|
{
|
|
57
56
|
method: "POST",
|
|
58
|
-
body:
|
|
57
|
+
body: fileStream,
|
|
59
58
|
},
|
|
60
59
|
);
|
|
61
60
|
log("Caption file uploaded", fileIndex);
|
|
@@ -3,8 +3,7 @@ import type { Readable } from "node:stream";
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import debug from "debug";
|
|
5
5
|
|
|
6
|
-
import type { Client } from "../client";
|
|
7
|
-
import { nodeStreamToWebStream } from "../util/nodeStreamToWebStream";
|
|
6
|
+
import type { Client } from "../client.ts";
|
|
8
7
|
|
|
9
8
|
const log = debug("ef:api:image-file");
|
|
10
9
|
|
|
@@ -54,7 +53,7 @@ export const uploadImageFile = async (
|
|
|
54
53
|
`/api/video2/image_files/${fileId}/upload`,
|
|
55
54
|
{
|
|
56
55
|
method: "POST",
|
|
57
|
-
body:
|
|
56
|
+
body: fileStream,
|
|
58
57
|
},
|
|
59
58
|
);
|
|
60
59
|
switch (fileIndex.status) {
|
|
@@ -3,8 +3,7 @@ import type { Readable } from "node:stream";
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import debug from "debug";
|
|
5
5
|
|
|
6
|
-
import type { Client } from "../client";
|
|
7
|
-
import { nodeStreamToWebStream } from "../util/nodeStreamToWebStream";
|
|
6
|
+
import type { Client } from "../client.ts";
|
|
8
7
|
|
|
9
8
|
const log = debug("ef:api:isobmff-file");
|
|
10
9
|
|
|
@@ -56,7 +55,7 @@ export const uploadFragmentIndex = async (
|
|
|
56
55
|
`/api/video2/isobmff_files/${fileId}/index/upload`,
|
|
57
56
|
{
|
|
58
57
|
method: "POST",
|
|
59
|
-
body:
|
|
58
|
+
body: fileStream,
|
|
60
59
|
},
|
|
61
60
|
);
|
|
62
61
|
|
|
@@ -5,8 +5,7 @@ import debug from "debug";
|
|
|
5
5
|
|
|
6
6
|
import { AudioStreamSchema, VideoStreamSchema } from "@editframe/assets";
|
|
7
7
|
|
|
8
|
-
import type { Client } from "../client";
|
|
9
|
-
import { nodeStreamToWebStream } from "../util/nodeStreamToWebStream";
|
|
8
|
+
import type { Client } from "../client.ts";
|
|
10
9
|
|
|
11
10
|
const log = debug("ef:api:isobmff-track");
|
|
12
11
|
|
|
@@ -75,7 +74,7 @@ export const uploadISOBMFFTrack = async (
|
|
|
75
74
|
`/api/video2/isobmff_tracks/${fileId}/${trackId}/upload`,
|
|
76
75
|
{
|
|
77
76
|
method: "POST",
|
|
78
|
-
body:
|
|
77
|
+
body: fileStream,
|
|
79
78
|
},
|
|
80
79
|
);
|
|
81
80
|
|
package/src/resources/renders.ts
CHANGED
|
@@ -3,8 +3,7 @@ import type { Readable } from "node:stream";
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import debug from "debug";
|
|
5
5
|
|
|
6
|
-
import type { Client } from "../client";
|
|
7
|
-
import { nodeStreamToWebStream } from "../util/nodeStreamToWebStream";
|
|
6
|
+
import type { Client } from "../client.ts";
|
|
8
7
|
|
|
9
8
|
const log = debug("ef:api:renders");
|
|
10
9
|
|
|
@@ -56,7 +55,7 @@ export const uploadRender = async (
|
|
|
56
55
|
`/api/video2/renders/${fileId}/upload`,
|
|
57
56
|
{
|
|
58
57
|
method: "POST",
|
|
59
|
-
body:
|
|
58
|
+
body: fileStream,
|
|
60
59
|
},
|
|
61
60
|
);
|
|
62
61
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
|
|
3
|
+
import type { Client } from "../client.ts";
|
|
4
|
+
|
|
5
|
+
const log = debug("ef:api:signed-url");
|
|
6
|
+
|
|
7
|
+
export interface SignedURLResult {
|
|
8
|
+
url: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const createSignedURL = async (client: Client, url: string) => {
|
|
12
|
+
log("Creating signed url for", url);
|
|
13
|
+
const response = await client.authenticatedFetch("/api/v1/signed-url", {
|
|
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 SignedURLResult).url;
|
|
27
|
+
};
|
|
@@ -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
|
+
};
|
package/dist/client.cjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const debug = require("debug");
|
|
4
|
-
const log = debug("ef:api:client");
|
|
5
|
-
class Client {
|
|
6
|
-
constructor(token, efHost) {
|
|
7
|
-
this.token = token;
|
|
8
|
-
this.efHost = efHost;
|
|
9
|
-
this.authenticatedFetch = async (path, init = {}) => {
|
|
10
|
-
init.headers ||= {};
|
|
11
|
-
log(
|
|
12
|
-
"Authenticated fetch",
|
|
13
|
-
{ path, init },
|
|
14
|
-
"(Token will be added as Bearer token)"
|
|
15
|
-
);
|
|
16
|
-
Object.assign(init.headers, {
|
|
17
|
-
Authorization: `Bearer ${this.token}`,
|
|
18
|
-
"Content-Type": "application/json"
|
|
19
|
-
});
|
|
20
|
-
const url = new URL(path, this.efHost);
|
|
21
|
-
const response = await fetch(url, init);
|
|
22
|
-
log("Authenticated fetch response", response.status, response.statusText);
|
|
23
|
-
return response;
|
|
24
|
-
};
|
|
25
|
-
log("Creating client with efHost", efHost, "and !!token", !!token);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
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,57 +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 nodeStreamToWebStream = require("../util/nodeStreamToWebStream.cjs");
|
|
6
|
-
const log = debug("ef:api:caption-file");
|
|
7
|
-
const CreateCaptionFilePayload = zod.z.object({
|
|
8
|
-
id: zod.z.string(),
|
|
9
|
-
filename: zod.z.string()
|
|
10
|
-
});
|
|
11
|
-
const createCaptionFile = async (client, payload) => {
|
|
12
|
-
log("Creating caption file", payload);
|
|
13
|
-
const fileCreation = await client.authenticatedFetch(
|
|
14
|
-
"/api/video2/caption_files",
|
|
15
|
-
{
|
|
16
|
-
method: "POST",
|
|
17
|
-
body: JSON.stringify(payload)
|
|
18
|
-
}
|
|
19
|
-
);
|
|
20
|
-
log("Caption file created", fileCreation);
|
|
21
|
-
switch (fileCreation.status) {
|
|
22
|
-
case 200: {
|
|
23
|
-
return await fileCreation.json();
|
|
24
|
-
}
|
|
25
|
-
default: {
|
|
26
|
-
console.error(
|
|
27
|
-
`Failed to create file ${fileCreation.status} ${fileCreation.statusText}`
|
|
28
|
-
);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const uploadCaptionFile = async (client, fileId, fileStream) => {
|
|
34
|
-
log("Uploading caption file", fileId);
|
|
35
|
-
const fileIndex = await client.authenticatedFetch(
|
|
36
|
-
`/api/video2/caption_files/${fileId}/upload`,
|
|
37
|
-
{
|
|
38
|
-
method: "POST",
|
|
39
|
-
body: nodeStreamToWebStream.nodeStreamToWebStream(fileStream)
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
log("Caption file uploaded", fileIndex);
|
|
43
|
-
switch (fileIndex.status) {
|
|
44
|
-
case 200: {
|
|
45
|
-
return fileIndex.json();
|
|
46
|
-
}
|
|
47
|
-
default: {
|
|
48
|
-
console.error(
|
|
49
|
-
`Failed to upload caption ${fileIndex.status} ${fileIndex.statusText}`
|
|
50
|
-
);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
exports.CreateCaptionFilePayload = CreateCaptionFilePayload;
|
|
56
|
-
exports.createCaptionFile = createCaptionFile;
|
|
57
|
-
exports.uploadCaptionFile = uploadCaptionFile;
|
|
@@ -1,53 +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 nodeStreamToWebStream = require("../util/nodeStreamToWebStream.cjs");
|
|
6
|
-
const log = debug("ef:api:image-file");
|
|
7
|
-
const CreateImageFilePayload = zod.z.object({
|
|
8
|
-
id: zod.z.string(),
|
|
9
|
-
height: zod.z.number().int(),
|
|
10
|
-
width: zod.z.number().int(),
|
|
11
|
-
mime_type: zod.z.enum(["image/jpeg", "image/png", "image/jpg", "image/webp"]),
|
|
12
|
-
filename: zod.z.string()
|
|
13
|
-
});
|
|
14
|
-
const createImageFile = async (client, payload) => {
|
|
15
|
-
log("Creating image file", payload);
|
|
16
|
-
const response = await client.authenticatedFetch("/api/video2/image_files", {
|
|
17
|
-
method: "POST",
|
|
18
|
-
body: JSON.stringify(payload)
|
|
19
|
-
});
|
|
20
|
-
log("Image file created", response);
|
|
21
|
-
switch (response.status) {
|
|
22
|
-
case 200: {
|
|
23
|
-
return await response.json();
|
|
24
|
-
}
|
|
25
|
-
default: {
|
|
26
|
-
console.error(
|
|
27
|
-
`Failed to create file ${response.status} ${response.statusText}`
|
|
28
|
-
);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const uploadImageFile = async (client, fileId, fileStream) => {
|
|
34
|
-
const fileIndex = await client.authenticatedFetch(
|
|
35
|
-
`/api/video2/image_files/${fileId}/upload`,
|
|
36
|
-
{
|
|
37
|
-
method: "POST",
|
|
38
|
-
body: nodeStreamToWebStream.nodeStreamToWebStream(fileStream)
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
switch (fileIndex.status) {
|
|
42
|
-
case 200: {
|
|
43
|
-
return fileIndex.json();
|
|
44
|
-
}
|
|
45
|
-
default: {
|
|
46
|
-
console.error("Failed to upload image");
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
exports.CreateImageFilePayload = CreateImageFilePayload;
|
|
52
|
-
exports.createImageFile = createImageFile;
|
|
53
|
-
exports.uploadImageFile = uploadImageFile;
|