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',
|
||||
message: 'Provided authorization credentials are invalid',
|
||||
}) 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 {
|
||||
InvalidAuthorization,
|
||||
InvalidPayload,
|
||||
QuotaExceeded,
|
||||
ValidationError,
|
||||
} from '../errors.js';
|
||||
import { config } from '../config.js';
|
||||
import { getTakenQuota, save } from '../store.js';
|
||||
import { save } from '../store.js';
|
||||
|
||||
type UploadPayload = {
|
||||
data: string; // base64-encoded
|
||||
|
@ -54,7 +55,10 @@ export default (async function (fastify) {
|
|||
const data = Buffer.from(body.data, 'base64');
|
||||
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 {
|
||||
status: 'ok',
|
||||
|
|
Loading…
Reference in New Issue