mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 03:26:47 +08:00
feat: add user level blob quota (#4114)
This commit is contained in:
@@ -339,7 +339,6 @@ async function collectBlobSizes(
|
||||
const res = await request(app.getHttpServer())
|
||||
.post(gql)
|
||||
.auth(token, { type: 'bearer' })
|
||||
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
|
||||
.send({
|
||||
query: `
|
||||
query {
|
||||
@@ -353,6 +352,26 @@ async function collectBlobSizes(
|
||||
return res.body.data.collectBlobSizes.size;
|
||||
}
|
||||
|
||||
async function collectAllBlobSizes(
|
||||
app: INestApplication,
|
||||
token: string
|
||||
): Promise<number> {
|
||||
const res = await request(app.getHttpServer())
|
||||
.post(gql)
|
||||
.auth(token, { type: 'bearer' })
|
||||
.send({
|
||||
query: `
|
||||
query {
|
||||
collectAllBlobSizes {
|
||||
size
|
||||
}
|
||||
}
|
||||
`,
|
||||
})
|
||||
.expect(200);
|
||||
return res.body.data.collectAllBlobSizes.size;
|
||||
}
|
||||
|
||||
async function setBlob(
|
||||
app: INestApplication,
|
||||
token: string,
|
||||
@@ -447,6 +466,7 @@ async function getInviteInfo(
|
||||
export {
|
||||
acceptInvite,
|
||||
acceptInviteById,
|
||||
collectAllBlobSizes,
|
||||
collectBlobSizes,
|
||||
createTestApp,
|
||||
createWorkspace,
|
||||
|
||||
@@ -10,6 +10,7 @@ import request from 'supertest';
|
||||
|
||||
import { AppModule } from '../app';
|
||||
import {
|
||||
collectAllBlobSizes,
|
||||
collectBlobSizes,
|
||||
createWorkspace,
|
||||
listBlobs,
|
||||
@@ -108,4 +109,25 @@ describe('Workspace Module - Blobs', () => {
|
||||
const size = await collectBlobSizes(app, u1.token.token, workspace.id);
|
||||
ok(size === 4, 'failed to collect blob sizes');
|
||||
});
|
||||
|
||||
it('should calc all blobs size', async () => {
|
||||
const u1 = await signUp(app, 'u1', 'u1@affine.pro', '1');
|
||||
|
||||
const workspace1 = await createWorkspace(app, u1.token.token);
|
||||
|
||||
const buffer1 = Buffer.from([0, 0]);
|
||||
await setBlob(app, u1.token.token, workspace1.id, buffer1);
|
||||
const buffer2 = Buffer.from([0, 1]);
|
||||
await setBlob(app, u1.token.token, workspace1.id, buffer2);
|
||||
|
||||
const workspace2 = await createWorkspace(app, u1.token.token);
|
||||
|
||||
const buffer3 = Buffer.from([0, 0]);
|
||||
await setBlob(app, u1.token.token, workspace2.id, buffer3);
|
||||
const buffer4 = Buffer.from([0, 1]);
|
||||
await setBlob(app, u1.token.token, workspace2.id, buffer4);
|
||||
|
||||
const size = await collectAllBlobSizes(app, u1.token.token);
|
||||
ok(size === 8, 'failed to collect all blob sizes');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user