@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.
@@ -0,0 +1,8 @@
1
+ import { RequestInit } from 'node-fetch';
2
+ import * as jwt from "jsonwebtoken";
3
+ export declare class Client {
4
+ #private;
5
+ constructor(token: string, efHost?: string);
6
+ authenticatedFetch: (path: string, init?: RequestInit) => Promise<import('node-fetch').Response>;
7
+ sign(payload: Record<string, unknown>, expiresIn?: Parameters<typeof jwt.sign>[2]["expiresIn"]): string;
8
+ }
package/dist/client.js CHANGED
@@ -1,27 +1,45 @@
1
1
  import debug from "debug";
2
+ import * as jwt from "jsonwebtoken";
2
3
  import fetch from "node-fetch";
3
4
  const log = debug("ef:api:client");
4
5
  class Client {
5
- constructor(token, efHost) {
6
- this.token = token;
7
- this.efHost = efHost;
6
+ constructor(token, efHost = "https://editframe.dev") {
8
7
  this.authenticatedFetch = async (path, init = {}) => {
9
8
  init.headers ||= {};
9
+ const url = new URL(path, this.#efHost);
10
10
  log(
11
11
  "Authenticated fetch",
12
- { path, init },
12
+ { url, init },
13
13
  "(Token will be added as Bearer token)"
14
14
  );
15
15
  Object.assign(init.headers, {
16
- Authorization: `Bearer ${this.token}`,
16
+ Authorization: `Bearer ${this.#token}`,
17
17
  "Content-Type": "application/json"
18
18
  });
19
- const url = new URL(path, this.efHost);
20
19
  const response = await fetch(url, init);
21
20
  log("Authenticated fetch response", response.status, response.statusText);
22
21
  return response;
23
22
  };
24
- log("Creating client with efHost", efHost, "and !!token", !!token);
23
+ log("Creating client with efHost", { efHost, tokenIsSet: !!token });
24
+ this.#token = token;
25
+ this.#efHost = efHost;
26
+ const { apiKey, apiSecret } = token.match(/^(?<apiSecret>ef_[^_]+)_(?<apiKey>.+)$/)?.groups ?? {};
27
+ if (!apiKey || !apiSecret) {
28
+ throw new Error("Invalid token format");
29
+ }
30
+ this.#apiKey = apiKey;
31
+ this.#apiSecret = apiSecret;
32
+ }
33
+ #apiKey;
34
+ #apiSecret;
35
+ #token;
36
+ #efHost;
37
+ sign(payload, expiresIn = 60) {
38
+ payload.cid = this.#apiKey;
39
+ return jwt.sign(payload, this.#apiSecret, {
40
+ algorithm: "HS256",
41
+ expiresIn
42
+ });
25
43
  }
26
44
  }
27
45
  export {
@@ -0,0 +1,8 @@
1
+ export { createCaptionFile, CreateCaptionFilePayload, type CreateCaptionFileResult, uploadCaptionFile, } from './resources/caption-file.ts';
2
+ export { createImageFile, CreateImageFilePayload, type CreateImageFileResult, uploadImageFile, } from './resources/image-file.ts';
3
+ export { createISOBMFFFile, CreateISOBMFFFilePayload, type CreateISOBMFFFileResult, uploadFragmentIndex, } from './resources/isobmff-file.ts';
4
+ export { createISOBMFFTrack, CreateISOBMFFTrackPayload, type CreateISOBMFFTrackResult, uploadISOBMFFTrack, } from './resources/isobmff-track.ts';
5
+ export { createRender, CreateRenderPayload, type CreateRenderResult, uploadRender, } from './resources/renders.ts';
6
+ export { createURLToken, type URLTokenResult, } from './resources/url-token.ts';
7
+ export { createUnprocessedFile, CreateUnprocessedFilePayload, type CreateUnprocessedFileResult, updateUnprocessedFile, UpdateUnprocessedFilePayload, type UpdateUnprocessedFileResult, uploadUnprocessedFile, processAVFile, processAVFileBuffer, } from './resources/unprocessed-file.ts';
8
+ export { Client } from './client.ts';
package/dist/index.js CHANGED
@@ -3,6 +3,8 @@ import { CreateImageFilePayload, createImageFile, uploadImageFile } from "./reso
3
3
  import { CreateISOBMFFFilePayload, createISOBMFFFile, uploadFragmentIndex } from "./resources/isobmff-file.js";
4
4
  import { CreateISOBMFFTrackPayload, createISOBMFFTrack, uploadISOBMFFTrack } from "./resources/isobmff-track.js";
5
5
  import { CreateRenderPayload, createRender, uploadRender } from "./resources/renders.js";
6
+ import { createURLToken } from "./resources/url-token.js";
7
+ import { CreateUnprocessedFilePayload, UpdateUnprocessedFilePayload, createUnprocessedFile, processAVFile, processAVFileBuffer, updateUnprocessedFile, uploadUnprocessedFile } from "./resources/unprocessed-file.js";
6
8
  import { Client } from "./client.js";
7
9
  export {
8
10
  Client,
@@ -11,14 +13,22 @@ export {
11
13
  CreateISOBMFFTrackPayload,
12
14
  CreateImageFilePayload,
13
15
  CreateRenderPayload,
16
+ CreateUnprocessedFilePayload,
17
+ UpdateUnprocessedFilePayload,
14
18
  createCaptionFile,
15
19
  createISOBMFFFile,
16
20
  createISOBMFFTrack,
17
21
  createImageFile,
18
22
  createRender,
23
+ createURLToken,
24
+ createUnprocessedFile,
25
+ processAVFile,
26
+ processAVFileBuffer,
27
+ updateUnprocessedFile,
19
28
  uploadCaptionFile,
20
29
  uploadFragmentIndex,
21
30
  uploadISOBMFFTrack,
22
31
  uploadImageFile,
23
- uploadRender
32
+ uploadRender,
33
+ uploadUnprocessedFile
24
34
  };
@@ -0,0 +1,20 @@
1
+ import { Readable } from 'node:stream';
2
+ import { z } from 'zod';
3
+ import { Client } from '../client.ts';
4
+
5
+ export declare const CreateCaptionFilePayload: z.ZodObject<{
6
+ id: z.ZodString;
7
+ filename: z.ZodString;
8
+ }, "strip", z.ZodTypeAny, {
9
+ id: string;
10
+ filename: string;
11
+ }, {
12
+ id: string;
13
+ filename: string;
14
+ }>;
15
+ export interface CreateCaptionFileResult {
16
+ complete: boolean | null;
17
+ id: string;
18
+ }
19
+ export declare const createCaptionFile: (client: Client, payload: z.infer<typeof CreateCaptionFilePayload>) => Promise<CreateCaptionFileResult | undefined>;
20
+ export declare const uploadCaptionFile: (client: Client, fileId: string, fileStream: Readable) => Promise<unknown>;
@@ -0,0 +1,29 @@
1
+ import { Readable } from 'node:stream';
2
+ import { z } from 'zod';
3
+ import { Client } from '../client.ts';
4
+
5
+ export declare const CreateImageFilePayload: z.ZodObject<{
6
+ id: z.ZodString;
7
+ height: z.ZodNumber;
8
+ width: z.ZodNumber;
9
+ mime_type: z.ZodEnum<["image/jpeg", "image/png", "image/jpg", "image/webp"]>;
10
+ filename: z.ZodString;
11
+ }, "strip", z.ZodTypeAny, {
12
+ id: string;
13
+ filename: string;
14
+ height: number;
15
+ width: number;
16
+ mime_type: "image/jpeg" | "image/png" | "image/jpg" | "image/webp";
17
+ }, {
18
+ id: string;
19
+ filename: string;
20
+ height: number;
21
+ width: number;
22
+ mime_type: "image/jpeg" | "image/png" | "image/jpg" | "image/webp";
23
+ }>;
24
+ export interface CreateImageFileResult {
25
+ complete: boolean | null;
26
+ id: string;
27
+ }
28
+ export declare const createImageFile: (client: Client, payload: z.infer<typeof CreateImageFilePayload>) => Promise<CreateImageFileResult | undefined>;
29
+ export declare const uploadImageFile: (client: Client, fileId: string, fileStream: Readable) => Promise<unknown>;
@@ -0,0 +1,20 @@
1
+ import { Readable } from 'node:stream';
2
+ import { z } from 'zod';
3
+ import { Client } from '../client.ts';
4
+
5
+ export declare const CreateISOBMFFFilePayload: z.ZodObject<{
6
+ id: z.ZodString;
7
+ filename: z.ZodString;
8
+ }, "strip", z.ZodTypeAny, {
9
+ id: string;
10
+ filename: string;
11
+ }, {
12
+ id: string;
13
+ filename: string;
14
+ }>;
15
+ export interface CreateISOBMFFFileResult {
16
+ fragment_index_complete: boolean;
17
+ id: string;
18
+ }
19
+ export declare const createISOBMFFFile: (client: Client, payload: z.infer<typeof CreateISOBMFFFilePayload>) => Promise<CreateISOBMFFFileResult | undefined>;
20
+ export declare const uploadFragmentIndex: (client: Client, fileId: string, fileStream: Readable) => Promise<unknown>;
@@ -0,0 +1,271 @@
1
+ import { Readable } from 'node:stream';
2
+ import { z } from 'zod';
3
+ import { Client } from '../client.ts';
4
+
5
+ export declare const CreateISOBMFFTrackPayload: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
6
+ file_id: z.ZodString;
7
+ track_id: z.ZodNumber;
8
+ type: z.ZodLiteral<"audio">;
9
+ probe_info: z.ZodObject<{
10
+ index: z.ZodNumber;
11
+ codec_name: z.ZodString;
12
+ codec_long_name: z.ZodString;
13
+ codec_type: z.ZodLiteral<"audio">;
14
+ codec_tag_string: z.ZodString;
15
+ codec_tag: z.ZodString;
16
+ sample_fmt: z.ZodString;
17
+ sample_rate: z.ZodString;
18
+ channels: z.ZodNumber;
19
+ channel_layout: z.ZodString;
20
+ bits_per_sample: z.ZodNumber;
21
+ initial_padding: z.ZodOptional<z.ZodNumber>;
22
+ r_frame_rate: z.ZodString;
23
+ avg_frame_rate: z.ZodString;
24
+ time_base: z.ZodString;
25
+ start_pts: z.ZodNumber;
26
+ start_time: z.ZodNumber;
27
+ duration_ts: z.ZodNumber;
28
+ duration: z.ZodNumber;
29
+ bit_rate: z.ZodString;
30
+ disposition: z.ZodRecord<z.ZodString, z.ZodUnknown>;
31
+ }, "strip", z.ZodTypeAny, {
32
+ duration: number;
33
+ index: number;
34
+ codec_name: string;
35
+ codec_long_name: string;
36
+ codec_type: "audio";
37
+ codec_tag_string: string;
38
+ codec_tag: string;
39
+ sample_fmt: string;
40
+ sample_rate: string;
41
+ channels: number;
42
+ channel_layout: string;
43
+ bits_per_sample: number;
44
+ r_frame_rate: string;
45
+ avg_frame_rate: string;
46
+ time_base: string;
47
+ start_pts: number;
48
+ start_time: number;
49
+ duration_ts: number;
50
+ bit_rate: string;
51
+ disposition: Record<string, unknown>;
52
+ initial_padding?: number | undefined;
53
+ }, {
54
+ duration: number;
55
+ index: number;
56
+ codec_name: string;
57
+ codec_long_name: string;
58
+ codec_type: "audio";
59
+ codec_tag_string: string;
60
+ codec_tag: string;
61
+ sample_fmt: string;
62
+ sample_rate: string;
63
+ channels: number;
64
+ channel_layout: string;
65
+ bits_per_sample: number;
66
+ r_frame_rate: string;
67
+ avg_frame_rate: string;
68
+ time_base: string;
69
+ start_pts: number;
70
+ start_time: number;
71
+ duration_ts: number;
72
+ bit_rate: string;
73
+ disposition: Record<string, unknown>;
74
+ initial_padding?: number | undefined;
75
+ }>;
76
+ duration_ms: z.ZodNumber;
77
+ codec_name: z.ZodString;
78
+ byte_size: z.ZodNumber;
79
+ }, "strip", z.ZodTypeAny, {
80
+ type: "audio";
81
+ file_id: string;
82
+ track_id: number;
83
+ probe_info: {
84
+ duration: number;
85
+ index: number;
86
+ codec_name: string;
87
+ codec_long_name: string;
88
+ codec_type: "audio";
89
+ codec_tag_string: string;
90
+ codec_tag: string;
91
+ sample_fmt: string;
92
+ sample_rate: string;
93
+ channels: number;
94
+ channel_layout: string;
95
+ bits_per_sample: number;
96
+ r_frame_rate: string;
97
+ avg_frame_rate: string;
98
+ time_base: string;
99
+ start_pts: number;
100
+ start_time: number;
101
+ duration_ts: number;
102
+ bit_rate: string;
103
+ disposition: Record<string, unknown>;
104
+ initial_padding?: number | undefined;
105
+ };
106
+ duration_ms: number;
107
+ codec_name: string;
108
+ byte_size: number;
109
+ }, {
110
+ type: "audio";
111
+ file_id: string;
112
+ track_id: number;
113
+ probe_info: {
114
+ duration: number;
115
+ index: number;
116
+ codec_name: string;
117
+ codec_long_name: string;
118
+ codec_type: "audio";
119
+ codec_tag_string: string;
120
+ codec_tag: string;
121
+ sample_fmt: string;
122
+ sample_rate: string;
123
+ channels: number;
124
+ channel_layout: string;
125
+ bits_per_sample: number;
126
+ r_frame_rate: string;
127
+ avg_frame_rate: string;
128
+ time_base: string;
129
+ start_pts: number;
130
+ start_time: number;
131
+ duration_ts: number;
132
+ bit_rate: string;
133
+ disposition: Record<string, unknown>;
134
+ initial_padding?: number | undefined;
135
+ };
136
+ duration_ms: number;
137
+ codec_name: string;
138
+ byte_size: number;
139
+ }>, z.ZodObject<{
140
+ file_id: z.ZodString;
141
+ track_id: z.ZodNumber;
142
+ type: z.ZodLiteral<"video">;
143
+ probe_info: z.ZodObject<{
144
+ index: z.ZodNumber;
145
+ codec_name: z.ZodString;
146
+ codec_long_name: z.ZodString;
147
+ codec_type: z.ZodLiteral<"video">;
148
+ codec_tag_string: z.ZodString;
149
+ codec_tag: z.ZodString;
150
+ width: z.ZodNumber;
151
+ height: z.ZodNumber;
152
+ coded_width: z.ZodNumber;
153
+ coded_height: z.ZodNumber;
154
+ r_frame_rate: z.ZodString;
155
+ avg_frame_rate: z.ZodString;
156
+ time_base: z.ZodString;
157
+ start_pts: z.ZodOptional<z.ZodNumber>;
158
+ start_time: z.ZodOptional<z.ZodNumber>;
159
+ duration_ts: z.ZodOptional<z.ZodNumber>;
160
+ duration: z.ZodOptional<z.ZodNumber>;
161
+ bit_rate: z.ZodOptional<z.ZodString>;
162
+ disposition: z.ZodRecord<z.ZodString, z.ZodUnknown>;
163
+ }, "strip", z.ZodTypeAny, {
164
+ index: number;
165
+ codec_name: string;
166
+ codec_long_name: string;
167
+ codec_type: "video";
168
+ codec_tag_string: string;
169
+ codec_tag: string;
170
+ r_frame_rate: string;
171
+ avg_frame_rate: string;
172
+ time_base: string;
173
+ disposition: Record<string, unknown>;
174
+ width: number;
175
+ height: number;
176
+ coded_width: number;
177
+ coded_height: number;
178
+ duration?: number | undefined;
179
+ start_pts?: number | undefined;
180
+ start_time?: number | undefined;
181
+ duration_ts?: number | undefined;
182
+ bit_rate?: string | undefined;
183
+ }, {
184
+ index: number;
185
+ codec_name: string;
186
+ codec_long_name: string;
187
+ codec_type: "video";
188
+ codec_tag_string: string;
189
+ codec_tag: string;
190
+ r_frame_rate: string;
191
+ avg_frame_rate: string;
192
+ time_base: string;
193
+ disposition: Record<string, unknown>;
194
+ width: number;
195
+ height: number;
196
+ coded_width: number;
197
+ coded_height: number;
198
+ duration?: number | undefined;
199
+ start_pts?: number | undefined;
200
+ start_time?: number | undefined;
201
+ duration_ts?: number | undefined;
202
+ bit_rate?: string | undefined;
203
+ }>;
204
+ duration_ms: z.ZodNumber;
205
+ codec_name: z.ZodString;
206
+ byte_size: z.ZodNumber;
207
+ }, "strip", z.ZodTypeAny, {
208
+ type: "video";
209
+ file_id: string;
210
+ track_id: number;
211
+ probe_info: {
212
+ index: number;
213
+ codec_name: string;
214
+ codec_long_name: string;
215
+ codec_type: "video";
216
+ codec_tag_string: string;
217
+ codec_tag: string;
218
+ r_frame_rate: string;
219
+ avg_frame_rate: string;
220
+ time_base: string;
221
+ disposition: Record<string, unknown>;
222
+ width: number;
223
+ height: number;
224
+ coded_width: number;
225
+ coded_height: number;
226
+ duration?: number | undefined;
227
+ start_pts?: number | undefined;
228
+ start_time?: number | undefined;
229
+ duration_ts?: number | undefined;
230
+ bit_rate?: string | undefined;
231
+ };
232
+ duration_ms: number;
233
+ codec_name: string;
234
+ byte_size: number;
235
+ }, {
236
+ type: "video";
237
+ file_id: string;
238
+ track_id: number;
239
+ probe_info: {
240
+ index: number;
241
+ codec_name: string;
242
+ codec_long_name: string;
243
+ codec_type: "video";
244
+ codec_tag_string: string;
245
+ codec_tag: string;
246
+ r_frame_rate: string;
247
+ avg_frame_rate: string;
248
+ time_base: string;
249
+ disposition: Record<string, unknown>;
250
+ width: number;
251
+ height: number;
252
+ coded_width: number;
253
+ coded_height: number;
254
+ duration?: number | undefined;
255
+ start_pts?: number | undefined;
256
+ start_time?: number | undefined;
257
+ duration_ts?: number | undefined;
258
+ bit_rate?: string | undefined;
259
+ };
260
+ duration_ms: number;
261
+ codec_name: string;
262
+ byte_size: number;
263
+ }>]>;
264
+ export interface CreateISOBMFFTrackResult {
265
+ last_received_byte: number;
266
+ byte_size: number;
267
+ track_id: number;
268
+ file_id: string;
269
+ }
270
+ export declare const createISOBMFFTrack: (client: Client, payload: z.infer<typeof CreateISOBMFFTrackPayload>) => Promise<CreateISOBMFFTrackResult | undefined>;
271
+ export declare const uploadISOBMFFTrack: (client: Client, fileId: string, trackId: number, fileStream: Readable) => Promise<unknown>;
@@ -0,0 +1,35 @@
1
+ import { Readable } from 'node:stream';
2
+ import { z } from 'zod';
3
+ import { Client } from '../client.ts';
4
+
5
+ export declare const CreateRenderPayload: z.ZodObject<{
6
+ id: z.ZodString;
7
+ fps: z.ZodNumber;
8
+ width: z.ZodNumber;
9
+ height: z.ZodNumber;
10
+ work_slice_ms: z.ZodNumber;
11
+ duration_ms: z.ZodNumber;
12
+ strategy: z.ZodEnum<["v1", "v2"]>;
13
+ }, "strip", z.ZodTypeAny, {
14
+ id: string;
15
+ height: number;
16
+ width: number;
17
+ duration_ms: number;
18
+ fps: number;
19
+ work_slice_ms: number;
20
+ strategy: "v1" | "v2";
21
+ }, {
22
+ id: string;
23
+ height: number;
24
+ width: number;
25
+ duration_ms: number;
26
+ fps: number;
27
+ work_slice_ms: number;
28
+ strategy: "v1" | "v2";
29
+ }>;
30
+ export interface CreateRenderResult {
31
+ status: "complete" | "created" | "failed" | "pending" | "rendering";
32
+ id: string;
33
+ }
34
+ export declare const createRender: (client: Client, payload: z.infer<typeof CreateRenderPayload>) => Promise<CreateRenderResult | undefined>;
35
+ export declare const uploadRender: (client: Client, fileId: string, fileStream: Readable) => Promise<unknown>;
@@ -0,0 +1,43 @@
1
+ import { Readable } from 'node:stream';
2
+ import { z } from 'zod';
3
+ import { Client } from '../client.ts';
4
+
5
+ declare const FileProcessors: z.ZodEffects<z.ZodArray<z.ZodUnion<[z.ZodLiteral<"isobmff">, z.ZodLiteral<"captions">]>, "many">, ("isobmff" | "captions")[], ("isobmff" | "captions")[]>;
6
+ export declare const CreateUnprocessedFilePayload: z.ZodObject<{
7
+ id: z.ZodString;
8
+ filename: z.ZodString;
9
+ processes: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodUnion<[z.ZodLiteral<"isobmff">, z.ZodLiteral<"captions">]>, "many">, ("isobmff" | "captions")[], ("isobmff" | "captions")[]>>;
10
+ }, "strip", z.ZodTypeAny, {
11
+ id: string;
12
+ filename: string;
13
+ processes?: ("isobmff" | "captions")[] | undefined;
14
+ }, {
15
+ id: string;
16
+ filename: string;
17
+ processes?: ("isobmff" | "captions")[] | undefined;
18
+ }>;
19
+ export declare const UpdateUnprocessedFilePayload: z.ZodObject<{
20
+ processes: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodUnion<[z.ZodLiteral<"isobmff">, z.ZodLiteral<"captions">]>, "many">, ("isobmff" | "captions")[], ("isobmff" | "captions")[]>>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ processes?: ("isobmff" | "captions")[] | undefined;
23
+ }, {
24
+ processes?: ("isobmff" | "captions")[] | undefined;
25
+ }>;
26
+ export interface CreateUnprocessedFileResult {
27
+ byte_size: number;
28
+ last_received_byte: number;
29
+ id: string;
30
+ processes: z.infer<typeof FileProcessors>;
31
+ }
32
+ export interface UpdateUnprocessedFileResult {
33
+ byte_size: number;
34
+ last_received_byte: number;
35
+ id: string;
36
+ processes: z.infer<typeof FileProcessors>;
37
+ }
38
+ export declare const createUnprocessedFile: (client: Client, payload: z.infer<typeof CreateUnprocessedFilePayload>) => Promise<CreateUnprocessedFileResult>;
39
+ export declare const updateUnprocessedFile: (client: Client, fileId: string, payload: Partial<z.infer<typeof UpdateUnprocessedFilePayload>>) => Promise<UpdateUnprocessedFileResult>;
40
+ export declare const uploadUnprocessedFile: (client: Client, fileId: string, fileStream: Readable) => Promise<unknown>;
41
+ export declare const processAVFileBuffer: (client: Client, buffer: Buffer, filename?: string) => Promise<UpdateUnprocessedFileResult>;
42
+ export declare const processAVFile: (client: Client, filePath: string) => Promise<UpdateUnprocessedFileResult>;
43
+ export {};
@@ -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
+ };
@@ -0,0 +1,6 @@
1
+ import { Client } from '../client.ts';
2
+
3
+ export interface URLTokenResult {
4
+ token: string;
5
+ }
6
+ export declare const createURLToken: (client: Client, url: string) => Promise<string>;