feat: detect if blob too large (#1738)

This commit is contained in:
Himself65
2023-03-29 02:39:23 -05:00
committed by GitHub
parent c1e8818db4
commit 9c6fb82c82
3 changed files with 28 additions and 1 deletions

View File

@@ -101,6 +101,21 @@ describe('api', () => {
document.removeEventListener('affine-error', listener);
});
test('blob too large', async () => {
let called = false;
try {
await workspaceApis.uploadBlob(
'test',
new ArrayBuffer(1024 * 1024 * 1024 + 1),
'image/png'
);
} catch (e) {
called = true;
expect(e).toBeInstanceOf(RequestError);
}
expect(called, 'throw error').toBe(true);
});
test('refresh token', async () => {
const storage = getLoginStorage();
assertExists(storage);

View File

@@ -302,6 +302,10 @@ export function createWorkspaceApis(prefixUrl = '/') {
): Promise<string> => {
const auth = getLoginStorage();
assertExists(auth);
const mb = arrayBuffer.byteLength / 1048576;
if (mb > 10) {
throw new RequestError(MessageCode.blobTooLarge);
}
return fetch(prefixUrl + 'api/blob', {
method: 'PUT',
body: arrayBuffer,