@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editframe/api",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.4-beta.0",
|
|
4
4
|
"description": "API functions for EditFrame",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"typescript": "^5.5.4"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@editframe/assets": "0.26.
|
|
22
|
+
"@editframe/assets": "0.26.4-beta.0",
|
|
23
23
|
"@vitejs/plugin-react": "^4.3.4",
|
|
24
24
|
"debug": "^4.3.5",
|
|
25
25
|
"eventsource-parser": "^3.0.0",
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
"default": "./dist/resources/renders.bundle.js"
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
|
-
"./package.json": "./package.json"
|
|
56
|
+
"./package.json": "./package.json",
|
|
57
|
+
"./types.json": "./types.json"
|
|
57
58
|
},
|
|
58
59
|
"publishConfig": {
|
|
59
60
|
"exports": {
|
package/tsdown.config.ts
CHANGED
|
@@ -1,172 +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 { webReadableFromBuffers } from "../readableFromBuffers.js";
|
|
7
|
-
import {
|
|
8
|
-
createCaptionFile,
|
|
9
|
-
lookupCaptionFileByMd5,
|
|
10
|
-
uploadCaptionFile,
|
|
11
|
-
} from "./caption-file.js";
|
|
12
|
-
|
|
13
|
-
const server = setupServer();
|
|
14
|
-
const client = new Client("ef_TEST_TOKEN", "http://localhost");
|
|
15
|
-
|
|
16
|
-
describe("CaptionFile", () => {
|
|
17
|
-
beforeAll(() => server.listen());
|
|
18
|
-
afterEach(() => server.resetHandlers());
|
|
19
|
-
afterAll(() => server.close());
|
|
20
|
-
|
|
21
|
-
describe("createCaptionFile", () => {
|
|
22
|
-
test("Throws when file is too large", async () => {
|
|
23
|
-
await expect(
|
|
24
|
-
createCaptionFile(client, {
|
|
25
|
-
md5: "test-md5",
|
|
26
|
-
filename: "test",
|
|
27
|
-
byte_size: 1024 * 1024 * 3,
|
|
28
|
-
}),
|
|
29
|
-
).rejects.toThrowError(
|
|
30
|
-
"File size 3145728 bytes exceeds limit 2097152 bytes",
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("Throws when server returns an error", async () => {
|
|
35
|
-
server.use(
|
|
36
|
-
http.post("http://localhost/api/v1/caption_files", () =>
|
|
37
|
-
HttpResponse.text("Internal Server Error", { status: 500 }),
|
|
38
|
-
),
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
await expect(
|
|
42
|
-
createCaptionFile(client, {
|
|
43
|
-
md5: "test-md5",
|
|
44
|
-
filename: "test",
|
|
45
|
-
byte_size: 4,
|
|
46
|
-
}),
|
|
47
|
-
).rejects.toThrowError(
|
|
48
|
-
"Failed to create caption 500 Internal Server Error",
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("Returns json data from the http response", async () => {
|
|
53
|
-
server.use(
|
|
54
|
-
http.post("http://localhost/api/v1/caption_files", () =>
|
|
55
|
-
HttpResponse.json(
|
|
56
|
-
{ id: "test-id" },
|
|
57
|
-
{ status: 200, statusText: "OK" },
|
|
58
|
-
),
|
|
59
|
-
),
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const response = await createCaptionFile(client, {
|
|
63
|
-
md5: "test-md5",
|
|
64
|
-
filename: "test",
|
|
65
|
-
byte_size: 4,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(response).toEqual({ id: "test-id" });
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("uploadCaptionFile", () => {
|
|
73
|
-
test("Throws when file is too large", async () => {
|
|
74
|
-
await expect(
|
|
75
|
-
uploadCaptionFile(
|
|
76
|
-
client,
|
|
77
|
-
"test-id",
|
|
78
|
-
webReadableFromBuffers(Buffer.from("test")),
|
|
79
|
-
1024 * 1024 * 3,
|
|
80
|
-
),
|
|
81
|
-
).rejects.toThrowError(
|
|
82
|
-
"File size 3145728 bytes exceeds limit 2097152 bytes",
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("Throws when server returns an error", async () => {
|
|
87
|
-
server.use(
|
|
88
|
-
http.post("http://localhost/api/v1/caption_files/test-id/upload", () =>
|
|
89
|
-
HttpResponse.text("Internal Server Error", { status: 500 }),
|
|
90
|
-
),
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
await expect(
|
|
94
|
-
uploadCaptionFile(
|
|
95
|
-
client,
|
|
96
|
-
"test-id",
|
|
97
|
-
webReadableFromBuffers(Buffer.from("nice")),
|
|
98
|
-
4,
|
|
99
|
-
),
|
|
100
|
-
).rejects.toThrowError(
|
|
101
|
-
"Failed to upload caption 500 Internal Server Error",
|
|
102
|
-
);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("Returns json data from the http response", async () => {
|
|
106
|
-
server.use(
|
|
107
|
-
http.post("http://localhost/api/v1/caption_files/test-id/upload", () =>
|
|
108
|
-
HttpResponse.json(
|
|
109
|
-
{ id: "test-id" },
|
|
110
|
-
{ status: 200, statusText: "OK" },
|
|
111
|
-
),
|
|
112
|
-
),
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const response = await uploadCaptionFile(
|
|
116
|
-
client,
|
|
117
|
-
"test-id",
|
|
118
|
-
webReadableFromBuffers(Buffer.from("nice")),
|
|
119
|
-
4,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
expect(response).toEqual({ id: "test-id" });
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
describe("lookupCaptionFileByMd5", () => {
|
|
127
|
-
test("Returns json data from the http response", async () => {
|
|
128
|
-
server.use(
|
|
129
|
-
http.get("http://localhost/api/v1/caption_files/md5/test-md5", () =>
|
|
130
|
-
HttpResponse.json(
|
|
131
|
-
{ id: "test-id", md5: "test-md5", complete: true },
|
|
132
|
-
{ status: 200, statusText: "OK" },
|
|
133
|
-
),
|
|
134
|
-
),
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const response = await lookupCaptionFileByMd5(client, "test-md5");
|
|
138
|
-
|
|
139
|
-
expect(response).toEqual({
|
|
140
|
-
id: "test-id",
|
|
141
|
-
md5: "test-md5",
|
|
142
|
-
complete: true,
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test("Returns null when file is not found", async () => {
|
|
147
|
-
server.use(
|
|
148
|
-
http.get("http://localhost/api/v1/caption_files/md5/test-md5", () =>
|
|
149
|
-
HttpResponse.json({}, { status: 404 }),
|
|
150
|
-
),
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
const response = await lookupCaptionFileByMd5(client, "test-md5");
|
|
154
|
-
|
|
155
|
-
expect(response).toBeNull();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test("Throws when server returns an error", async () => {
|
|
159
|
-
server.use(
|
|
160
|
-
http.get("http://localhost/api/v1/caption_files/md5/test-md5", () =>
|
|
161
|
-
HttpResponse.text("Internal Server Error", { status: 500 }),
|
|
162
|
-
),
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
await expect(
|
|
166
|
-
lookupCaptionFileByMd5(client, "test-md5"),
|
|
167
|
-
).rejects.toThrowError(
|
|
168
|
-
"Failed to lookup caption by md5 test-md5 500 Internal Server Error",
|
|
169
|
-
);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
});
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import debug from "debug";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
import type { Client } from "../client.js";
|
|
5
|
-
|
|
6
|
-
const log = debug("ef:api:caption-file");
|
|
7
|
-
|
|
8
|
-
const MAX_CAPTION_SIZE = 1024 * 1024 * 2; // 2MB
|
|
9
|
-
|
|
10
|
-
export const CreateCaptionFilePayload = z.object({
|
|
11
|
-
/**
|
|
12
|
-
* The md5 hash of the caption file
|
|
13
|
-
*/
|
|
14
|
-
md5: z.string(),
|
|
15
|
-
/**
|
|
16
|
-
* The filename of the caption file
|
|
17
|
-
*/
|
|
18
|
-
filename: z.string(),
|
|
19
|
-
/**
|
|
20
|
-
* The size of the caption file in bytes
|
|
21
|
-
*/
|
|
22
|
-
byte_size: z.number().int().max(MAX_CAPTION_SIZE),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export type CreateCaptionFilePayload = z.infer<typeof CreateCaptionFilePayload>;
|
|
26
|
-
|
|
27
|
-
export interface CreateCaptionFileResult {
|
|
28
|
-
/**
|
|
29
|
-
* Whether the caption file is complete
|
|
30
|
-
*/
|
|
31
|
-
complete: boolean | null;
|
|
32
|
-
/**
|
|
33
|
-
* The id of the caption file
|
|
34
|
-
*/
|
|
35
|
-
id: string;
|
|
36
|
-
/**
|
|
37
|
-
* The md5 hash of the caption file
|
|
38
|
-
*/
|
|
39
|
-
md5: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface LookupCaptionFileByMd5Result {
|
|
43
|
-
/**
|
|
44
|
-
* Whether the caption file is complete
|
|
45
|
-
*/
|
|
46
|
-
complete: boolean | null;
|
|
47
|
-
/**
|
|
48
|
-
* The id of the caption file
|
|
49
|
-
*/
|
|
50
|
-
id: string;
|
|
51
|
-
/**
|
|
52
|
-
* The md5 hash of the caption file
|
|
53
|
-
*/
|
|
54
|
-
md5: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const restrictSize = (size: number) => {
|
|
58
|
-
if (size > MAX_CAPTION_SIZE) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
`File size ${size} bytes exceeds limit ${MAX_CAPTION_SIZE} bytes\n`,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Create a caption file
|
|
67
|
-
* @param client - The authenticated client to use for the request
|
|
68
|
-
* @param payload - The payload to send to the server
|
|
69
|
-
* @returns The result of the request
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* const result = await createCaptionFile(client, {
|
|
73
|
-
* id: "123",
|
|
74
|
-
* filename: "caption.srt",
|
|
75
|
-
* });
|
|
76
|
-
* console.log(result);
|
|
77
|
-
* ```
|
|
78
|
-
* @category CaptionFile
|
|
79
|
-
* @resource
|
|
80
|
-
* @beta
|
|
81
|
-
*/
|
|
82
|
-
export const createCaptionFile = async (
|
|
83
|
-
client: Client,
|
|
84
|
-
payload: CreateCaptionFilePayload,
|
|
85
|
-
) => {
|
|
86
|
-
log("Creating caption file", payload);
|
|
87
|
-
restrictSize(payload.byte_size);
|
|
88
|
-
const response = await client.authenticatedFetch("/api/v1/caption_files", {
|
|
89
|
-
method: "POST",
|
|
90
|
-
body: JSON.stringify(payload),
|
|
91
|
-
});
|
|
92
|
-
log("Caption file created", response);
|
|
93
|
-
|
|
94
|
-
if (response.ok) {
|
|
95
|
-
return (await response.json()) as CreateCaptionFileResult;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
throw new Error(
|
|
99
|
-
`Failed to create caption ${response.status} ${response.statusText}`,
|
|
100
|
-
);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const uploadCaptionFile = async (
|
|
104
|
-
client: Client,
|
|
105
|
-
fileId: string,
|
|
106
|
-
fileStream: ReadableStream,
|
|
107
|
-
fileSize: number,
|
|
108
|
-
) => {
|
|
109
|
-
log("Uploading caption file", fileId);
|
|
110
|
-
restrictSize(fileSize);
|
|
111
|
-
|
|
112
|
-
const response = await client.authenticatedFetch(
|
|
113
|
-
`/api/v1/caption_files/${fileId}/upload`,
|
|
114
|
-
{
|
|
115
|
-
method: "POST",
|
|
116
|
-
body: fileStream,
|
|
117
|
-
duplex: "half",
|
|
118
|
-
},
|
|
119
|
-
);
|
|
120
|
-
log("Caption file uploaded", response);
|
|
121
|
-
|
|
122
|
-
if (response.ok) {
|
|
123
|
-
return response.json();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
throw new Error(
|
|
127
|
-
`Failed to upload caption ${response.status} ${response.statusText}`,
|
|
128
|
-
);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export const lookupCaptionFileByMd5 = async (
|
|
132
|
-
client: Client,
|
|
133
|
-
md5: string,
|
|
134
|
-
): Promise<LookupCaptionFileByMd5Result | null> => {
|
|
135
|
-
const response = await client.authenticatedFetch(
|
|
136
|
-
`/api/v1/caption_files/md5/${md5}`,
|
|
137
|
-
{
|
|
138
|
-
method: "GET",
|
|
139
|
-
},
|
|
140
|
-
);
|
|
141
|
-
log("Caption file lookup", response);
|
|
142
|
-
|
|
143
|
-
if (response.ok) {
|
|
144
|
-
return (await response.json()) as LookupCaptionFileByMd5Result;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (response.status === 404) {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
throw new Error(
|
|
152
|
-
`Failed to lookup caption by md5 ${md5} ${response.status} ${response.statusText}`,
|
|
153
|
-
);
|
|
154
|
-
};
|
|
@@ -1,220 +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 { webReadableFromBuffers } from "../readableFromBuffers.js";
|
|
7
|
-
import {
|
|
8
|
-
CreateImageFilePayload,
|
|
9
|
-
createImageFile,
|
|
10
|
-
lookupImageFileByMd5,
|
|
11
|
-
uploadImageFile,
|
|
12
|
-
} from "./image-file.js";
|
|
13
|
-
|
|
14
|
-
const server = setupServer();
|
|
15
|
-
const client = new Client("ef_TEST_TOKEN", "http://localhost");
|
|
16
|
-
|
|
17
|
-
const UploadMustContinue = (id = "test-file") =>
|
|
18
|
-
http.get(`http://localhost/api/v1/image_files/${id}/upload`, () =>
|
|
19
|
-
HttpResponse.json({}, { status: 202 }),
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
describe("CreateImageFilePayload", () => {
|
|
23
|
-
test("parses mime type from filename", () => {
|
|
24
|
-
const payload = CreateImageFilePayload.parse({
|
|
25
|
-
byte_size: 100,
|
|
26
|
-
filename: "test.jpg",
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
expect(payload.mime_type).toBe("image/jpeg");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("rejects unsupported mime types", () => {
|
|
33
|
-
const payload = CreateImageFilePayload.safeParse({
|
|
34
|
-
byte_size: 100,
|
|
35
|
-
filename: "test.txt",
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
expect(
|
|
39
|
-
payload.error?.issues.some((issue) => issue.path.includes("mime_type")),
|
|
40
|
-
).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe("ImageFile", () => {
|
|
45
|
-
beforeAll(() => server.listen());
|
|
46
|
-
afterEach(() => server.resetHandlers());
|
|
47
|
-
afterAll(() => server.close());
|
|
48
|
-
|
|
49
|
-
describe("createImageFile", () => {
|
|
50
|
-
test("Throws when file is too large", async () => {
|
|
51
|
-
await expect(
|
|
52
|
-
createImageFile(client, {
|
|
53
|
-
md5: "test-md5",
|
|
54
|
-
filename: "test",
|
|
55
|
-
byte_size: 1024 * 1024 * 17,
|
|
56
|
-
height: 100,
|
|
57
|
-
width: 100,
|
|
58
|
-
mime_type: "image/jpeg",
|
|
59
|
-
}),
|
|
60
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
61
|
-
[ZodError: [
|
|
62
|
-
{
|
|
63
|
-
"code": "too_big",
|
|
64
|
-
"maximum": 16777216,
|
|
65
|
-
"type": "number",
|
|
66
|
-
"inclusive": true,
|
|
67
|
-
"exact": false,
|
|
68
|
-
"message": "Number must be less than or equal to 16777216",
|
|
69
|
-
"path": [
|
|
70
|
-
"byte_size"
|
|
71
|
-
]
|
|
72
|
-
}
|
|
73
|
-
]]
|
|
74
|
-
`);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("Throws when server returns an error", async () => {
|
|
78
|
-
server.use(
|
|
79
|
-
http.post("http://localhost/api/v1/image_files", () =>
|
|
80
|
-
HttpResponse.text("Internal Server Error", { status: 500 }),
|
|
81
|
-
),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
await expect(
|
|
85
|
-
createImageFile(client, {
|
|
86
|
-
md5: "test-md5",
|
|
87
|
-
filename: "test",
|
|
88
|
-
byte_size: 4,
|
|
89
|
-
height: 100,
|
|
90
|
-
width: 100,
|
|
91
|
-
mime_type: "image/jpeg",
|
|
92
|
-
}),
|
|
93
|
-
).rejects.toThrowError("Failed to create file 500 Internal Server Error");
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test("Returns json data from the http response", async () => {
|
|
97
|
-
server.use(
|
|
98
|
-
http.post("http://localhost/api/v1/image_files", () =>
|
|
99
|
-
HttpResponse.json(
|
|
100
|
-
{ md5: "test-md5" },
|
|
101
|
-
{ status: 200, statusText: "OK" },
|
|
102
|
-
),
|
|
103
|
-
),
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const response = await createImageFile(client, {
|
|
107
|
-
md5: "test-md5",
|
|
108
|
-
filename: "test",
|
|
109
|
-
byte_size: 4,
|
|
110
|
-
height: 100,
|
|
111
|
-
width: 100,
|
|
112
|
-
mime_type: "image/jpeg",
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(response).toEqual({ md5: "test-md5" });
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe("uploadImageFile", () => {
|
|
120
|
-
test("Throws when file is too large", async () => {
|
|
121
|
-
await expect(
|
|
122
|
-
uploadImageFile(
|
|
123
|
-
client,
|
|
124
|
-
{ id: "test-file-id", byte_size: 1024 * 1024 * 17 },
|
|
125
|
-
webReadableFromBuffers(Buffer.from("test")),
|
|
126
|
-
).whenUploaded(),
|
|
127
|
-
).rejects.toThrowError(
|
|
128
|
-
"File size 17825792 bytes exceeds limit 16777216 bytes",
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test("Throws if upload fails", async () => {
|
|
133
|
-
server.use(
|
|
134
|
-
UploadMustContinue("test-file-id"),
|
|
135
|
-
http.post(
|
|
136
|
-
"http://localhost/api/v1/image_files/test-file-id/upload",
|
|
137
|
-
() => HttpResponse.text("Internal Server Error", { status: 500 }),
|
|
138
|
-
),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
await expect(
|
|
142
|
-
uploadImageFile(
|
|
143
|
-
client,
|
|
144
|
-
{ id: "test-file-id", byte_size: 4 },
|
|
145
|
-
webReadableFromBuffers(Buffer.from("test")),
|
|
146
|
-
).whenUploaded(),
|
|
147
|
-
).rejects.toThrowError(
|
|
148
|
-
"Failed to upload chunk 0 for /api/v1/image_files/test-file-id/upload 500 Internal Server Error",
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test("Uploads file", async () => {
|
|
153
|
-
server.use(
|
|
154
|
-
UploadMustContinue("test-file-id"),
|
|
155
|
-
http.post(
|
|
156
|
-
"http://localhost/api/v1/image_files/test-file-id/upload",
|
|
157
|
-
() => HttpResponse.json(null, { status: 201 }),
|
|
158
|
-
),
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
await expect(
|
|
162
|
-
uploadImageFile(
|
|
163
|
-
client,
|
|
164
|
-
{ id: "test-file-id", byte_size: 4 },
|
|
165
|
-
webReadableFromBuffers(Buffer.from("test")),
|
|
166
|
-
).whenUploaded(),
|
|
167
|
-
).resolves.toEqual([
|
|
168
|
-
{ type: "progress", progress: 0 },
|
|
169
|
-
{ type: "progress", progress: 1 },
|
|
170
|
-
]);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
describe("lookupImageFileByMd5", () => {
|
|
175
|
-
test("Returns json data from the http response", async () => {
|
|
176
|
-
server.use(
|
|
177
|
-
http.get("http://localhost/api/v1/image_files/md5/test-md5", () =>
|
|
178
|
-
HttpResponse.json(
|
|
179
|
-
{ id: "test-id", md5: "test-md5", complete: true },
|
|
180
|
-
{ status: 200, statusText: "OK" },
|
|
181
|
-
),
|
|
182
|
-
),
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
const response = await lookupImageFileByMd5(client, "test-md5");
|
|
186
|
-
|
|
187
|
-
expect(response).toEqual({
|
|
188
|
-
id: "test-id",
|
|
189
|
-
md5: "test-md5",
|
|
190
|
-
complete: true,
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test("Returns null when file is not found", async () => {
|
|
195
|
-
server.use(
|
|
196
|
-
http.get("http://localhost/api/v1/image_files/md5/test-md5", () =>
|
|
197
|
-
HttpResponse.json({}, { status: 404 }),
|
|
198
|
-
),
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
const response = await lookupImageFileByMd5(client, "test-md5");
|
|
202
|
-
|
|
203
|
-
expect(response).toBeNull();
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test("Throws when server returns an error", async () => {
|
|
207
|
-
server.use(
|
|
208
|
-
http.get("http://localhost/api/v1/image_files/md5/test-md5", () =>
|
|
209
|
-
HttpResponse.text("Internal Server Error", { status: 500 }),
|
|
210
|
-
),
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
await expect(
|
|
214
|
-
lookupImageFileByMd5(client, "test-md5"),
|
|
215
|
-
).rejects.toThrowError(
|
|
216
|
-
"Failed to lookup image by md5 test-md5 500 Internal Server Error",
|
|
217
|
-
);
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
});
|