mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-27 18:53:43 +03:00
feat: detect if blob too large (#1738)
This commit is contained in:
parent
c1e8818db4
commit
9c6fb82c82
10
packages/env/src/constant.ts
vendored
10
packages/env/src/constant.ts
vendored
@ -17,6 +17,7 @@ export const enum MessageCode {
|
|||||||
leaveWorkspaceFailed,
|
leaveWorkspaceFailed,
|
||||||
downloadWorkspaceFailed,
|
downloadWorkspaceFailed,
|
||||||
refreshTokenError,
|
refreshTokenError,
|
||||||
|
blobTooLarge,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Messages = {
|
export const Messages = {
|
||||||
@ -65,4 +66,11 @@ export const Messages = {
|
|||||||
[MessageCode.refreshTokenError]: {
|
[MessageCode.refreshTokenError]: {
|
||||||
message: 'Refresh token failed',
|
message: 'Refresh token failed',
|
||||||
},
|
},
|
||||||
} as const;
|
[MessageCode.blobTooLarge]: {
|
||||||
|
message: 'Blob too large',
|
||||||
|
},
|
||||||
|
} as const satisfies {
|
||||||
|
[key in MessageCode]: {
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
@ -101,6 +101,21 @@ describe('api', () => {
|
|||||||
document.removeEventListener('affine-error', listener);
|
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 () => {
|
test('refresh token', async () => {
|
||||||
const storage = getLoginStorage();
|
const storage = getLoginStorage();
|
||||||
assertExists(storage);
|
assertExists(storage);
|
||||||
|
@ -302,6 +302,10 @@ export function createWorkspaceApis(prefixUrl = '/') {
|
|||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
const auth = getLoginStorage();
|
const auth = getLoginStorage();
|
||||||
assertExists(auth);
|
assertExists(auth);
|
||||||
|
const mb = arrayBuffer.byteLength / 1048576;
|
||||||
|
if (mb > 10) {
|
||||||
|
throw new RequestError(MessageCode.blobTooLarge);
|
||||||
|
}
|
||||||
return fetch(prefixUrl + 'api/blob', {
|
return fetch(prefixUrl + 'api/blob', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: arrayBuffer,
|
body: arrayBuffer,
|
||||||
|
Loading…
Reference in New Issue
Block a user