chore: add 10MB of grace bytes for storage quota (#1904)

This commit is contained in:
Huang Xin
2025-08-26 13:28:15 +08:00
committed by GitHub
parent 76feefff00
commit 66fceb2313
2 changed files with 8 additions and 2 deletions
@@ -1,7 +1,11 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { createSupabaseClient } from '@/utils/supabase';
import { corsAllMethods, runMiddleware } from '@/utils/cors';
import { getStoragePlanData, validateUserAndToken } from '@/utils/access';
import {
getStoragePlanData,
validateUserAndToken,
STORAGE_QUOTA_GRACE_BYTES,
} from '@/utils/access';
import { getUploadSignedUrl } from '@/utils/object';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
@@ -23,7 +27,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
const { usage, quota } = getStoragePlanData(token);
if (usage + fileSize > quota) {
if (usage + fileSize > quota + STORAGE_QUOTA_GRACE_BYTES) {
return res.status(403).json({ error: 'Insufficient storage quota', usage });
}
+2
View File
@@ -16,6 +16,8 @@ export const getUserPlan = (token: string): UserPlan => {
return data['plan'] || 'free';
};
export const STORAGE_QUOTA_GRACE_BYTES = 10 * 1024 * 1024; // 10 MB grace
export const getStoragePlanData = (token: string) => {
const data = jwtDecode<Token>(token) || {};
const plan = data['plan'] || 'free';