@editframe/api 0.26.2-beta.0 → 0.26.4-beta.0
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/package.json +4 -3
- package/tsdown.config.ts +3 -0
- package/src/resources/caption-file.test.ts +0 -172
- package/src/resources/caption-file.ts +0 -154
- package/src/resources/image-file.test.ts +0 -220
- package/src/resources/image-file.ts +0 -205
- package/src/resources/isobmff-file.test.ts +0 -159
- package/src/resources/isobmff-file.ts +0 -186
- package/src/resources/isobmff-track.test.ts +0 -126
- package/src/resources/isobmff-track.ts +0 -248
- package/src/resources/process-isobmff.test.ts +0 -68
- package/src/resources/process-isobmff.ts +0 -33
- package/src/resources/renders.bundle.ts +0 -53
- package/src/resources/renders.test.ts +0 -202
- package/src/resources/renders.ts +0 -282
- package/src/resources/test-av-file.txt +0 -1
- package/src/resources/transcriptions.test.ts +0 -49
- package/src/resources/transcriptions.ts +0 -67
- package/src/resources/unprocessed-file.test.ts +0 -171
- package/src/resources/unprocessed-file.ts +0 -138
- package/src/resources/url-token.test.ts +0 -46
- package/src/resources/url-token.ts +0 -27
- package/src/utils/assertTypesMatch.ts +0 -10
- package/src/utils/createReadableStreamFromReadable.ts +0 -115
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { HttpResponse, http } from "msw";
|
|
2
|
-
import { setupServer } from "msw/node";
|
|
3
|
-
import { afterAll, afterEach, beforeAll, describe, expect, test } from "vitest";
|
|
4
|
-
|
|
5
|
-
import { Client } from "../client.js";
|
|
6
|
-
import { createURLToken } from "./url-token.js";
|
|
7
|
-
|
|
8
|
-
const server = setupServer();
|
|
9
|
-
const client = new Client("ef_TEST_TOKEN", "http://localhost");
|
|
10
|
-
|
|
11
|
-
describe("URL Token", () => {
|
|
12
|
-
beforeAll(() => server.listen());
|
|
13
|
-
afterEach(() => server.resetHandlers());
|
|
14
|
-
afterAll(() => server.close());
|
|
15
|
-
|
|
16
|
-
describe("createURLToken", () => {
|
|
17
|
-
test("Throws when server returns an error", async () => {
|
|
18
|
-
server.use(
|
|
19
|
-
http.post("http://localhost/api/v1/url-token", () =>
|
|
20
|
-
HttpResponse.text("Internal Server Error", { status: 500 }),
|
|
21
|
-
),
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
await expect(
|
|
25
|
-
createURLToken(client, "http://example.com"),
|
|
26
|
-
).rejects.toThrowError(
|
|
27
|
-
"Failed to create signed url: 500 Internal Server Error Internal Server Error",
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("Returns token from the http response", async () => {
|
|
32
|
-
server.use(
|
|
33
|
-
http.post("http://localhost/api/v1/url-token", () =>
|
|
34
|
-
HttpResponse.json(
|
|
35
|
-
{ token: "test-token" },
|
|
36
|
-
{ status: 200, statusText: "OK" },
|
|
37
|
-
),
|
|
38
|
-
),
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
await expect(createURLToken(client, "http://example.com")).resolves.toBe(
|
|
42
|
-
"test-token",
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import debug from "debug";
|
|
2
|
-
|
|
3
|
-
import type { Client } from "../client.js";
|
|
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
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Type helper that will cause a compilation error
|
|
2
|
-
type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y
|
|
3
|
-
? 1
|
|
4
|
-
: 2
|
|
5
|
-
? true
|
|
6
|
-
: false;
|
|
7
|
-
// Force error with const assertion
|
|
8
|
-
export const assertTypesMatch = <T, U>(
|
|
9
|
-
value: Equals<T, U> extends true ? true : never,
|
|
10
|
-
) => value;
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { type Readable, Stream } from "node:stream";
|
|
2
|
-
|
|
3
|
-
export const createReadableStreamFromReadable = (
|
|
4
|
-
source: Readable & { readableHighWaterMark?: number },
|
|
5
|
-
) => {
|
|
6
|
-
const pump = new StreamPump(source);
|
|
7
|
-
const stream = new ReadableStream(pump, pump);
|
|
8
|
-
return stream;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
class StreamPump {
|
|
12
|
-
public highWaterMark: number;
|
|
13
|
-
public accumalatedSize: number;
|
|
14
|
-
private stream: Stream & {
|
|
15
|
-
readableHighWaterMark?: number;
|
|
16
|
-
readable?: boolean;
|
|
17
|
-
resume?: () => void;
|
|
18
|
-
pause?: () => void;
|
|
19
|
-
destroy?: (error?: Error) => void;
|
|
20
|
-
};
|
|
21
|
-
private controller?: ReadableStreamController<Uint8Array>;
|
|
22
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
stream: Stream & {
|
|
25
|
-
readableHighWaterMark?: number;
|
|
26
|
-
readable?: boolean;
|
|
27
|
-
resume?: () => void;
|
|
28
|
-
pause?: () => void;
|
|
29
|
-
destroy?: (error?: Error) => void;
|
|
30
|
-
},
|
|
31
|
-
) {
|
|
32
|
-
this.highWaterMark =
|
|
33
|
-
stream.readableHighWaterMark ||
|
|
34
|
-
new Stream.Readable().readableHighWaterMark;
|
|
35
|
-
this.accumalatedSize = 0;
|
|
36
|
-
this.stream = stream;
|
|
37
|
-
this.enqueue = this.enqueue.bind(this);
|
|
38
|
-
this.error = this.error.bind(this);
|
|
39
|
-
this.close = this.close.bind(this);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
size(chunk: Uint8Array) {
|
|
43
|
-
return chunk?.byteLength || 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
start(controller: ReadableStreamController<Uint8Array>) {
|
|
47
|
-
this.controller = controller;
|
|
48
|
-
this.stream.on("data", this.enqueue);
|
|
49
|
-
this.stream.once("error", this.error);
|
|
50
|
-
this.stream.once("end", this.close);
|
|
51
|
-
this.stream.once("close", this.close);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
pull() {
|
|
55
|
-
this.resume();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
cancel(reason?: Error) {
|
|
59
|
-
if (this.stream.destroy) {
|
|
60
|
-
this.stream.destroy(reason);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.stream.off("data", this.enqueue);
|
|
64
|
-
this.stream.off("error", this.error);
|
|
65
|
-
this.stream.off("end", this.close);
|
|
66
|
-
this.stream.off("close", this.close);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
enqueue(chunk: Uint8Array | string) {
|
|
70
|
-
if (this.controller) {
|
|
71
|
-
try {
|
|
72
|
-
// const bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
|
|
73
|
-
|
|
74
|
-
const available = (this.controller.desiredSize || 0) - chunk.length;
|
|
75
|
-
this.controller.enqueue(chunk as Uint8Array);
|
|
76
|
-
if (available <= 0) {
|
|
77
|
-
this.pause();
|
|
78
|
-
}
|
|
79
|
-
} catch (_error: any) {
|
|
80
|
-
this.controller.error(
|
|
81
|
-
new Error(
|
|
82
|
-
"Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object",
|
|
83
|
-
),
|
|
84
|
-
);
|
|
85
|
-
this.cancel();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
pause() {
|
|
91
|
-
if (this.stream.pause) {
|
|
92
|
-
this.stream.pause();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
resume() {
|
|
97
|
-
if (this.stream.readable && this.stream.resume) {
|
|
98
|
-
this.stream.resume();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
close() {
|
|
103
|
-
if (this.controller) {
|
|
104
|
-
this.controller.close();
|
|
105
|
-
delete this.controller;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
error(error: Error) {
|
|
110
|
-
if (this.controller) {
|
|
111
|
-
this.controller.error(error);
|
|
112
|
-
delete this.controller;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|