feat: throw QuotaExceeded error on upload when applicable
This commit is contained in:
parent
89a6efb4a3
commit
8c8ac3523b
|
@ -26,3 +26,10 @@ export const InvalidAuthorization = () =>
|
||||||
name: 'InvalidAuthorization',
|
name: 'InvalidAuthorization',
|
||||||
message: 'Provided authorization credentials are invalid',
|
message: 'Provided authorization credentials are invalid',
|
||||||
}) as FastifyError;
|
}) as FastifyError;
|
||||||
|
|
||||||
|
export const QuotaExceeded = () => ({
|
||||||
|
code: '422',
|
||||||
|
statusCode: 422,
|
||||||
|
name: 'QuotaExceeded',
|
||||||
|
message: 'Your quota has exceeded. Please delete some files to proceed.',
|
||||||
|
});
|
||||||
|
|
|
@ -5,10 +5,11 @@ import crypto from 'node:crypto';
|
||||||
import {
|
import {
|
||||||
InvalidAuthorization,
|
InvalidAuthorization,
|
||||||
InvalidPayload,
|
InvalidPayload,
|
||||||
|
QuotaExceeded,
|
||||||
ValidationError,
|
ValidationError,
|
||||||
} from '../errors.js';
|
} from '../errors.js';
|
||||||
import { config } from '../config.js';
|
import { config } from '../config.js';
|
||||||
import { getTakenQuota, save } from '../store.js';
|
import { save } from '../store.js';
|
||||||
|
|
||||||
type UploadPayload = {
|
type UploadPayload = {
|
||||||
data: string; // base64-encoded
|
data: string; // base64-encoded
|
||||||
|
@ -54,7 +55,10 @@ export default (async function (fastify) {
|
||||||
const data = Buffer.from(body.data, 'base64');
|
const data = Buffer.from(body.data, 'base64');
|
||||||
const name = body.name;
|
const name = body.name;
|
||||||
|
|
||||||
await save(data, name, client.name);
|
const status = await save(data, name, client.name);
|
||||||
|
if (status === 'Quota exceeded') {
|
||||||
|
throw QuotaExceeded();
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
|
|
Loading…
Reference in New Issue