mirror of
https://github.com/diced/zipline.git
synced 2025-04-11 23:31:17 -05:00
fix: ratelimit positioning
This commit is contained in:
parent
1f00dd51f9
commit
70050afb5f
2 changed files with 41 additions and 40 deletions
|
@ -364,7 +364,8 @@ export default function File({ chunks: chunks_config }) {
|
|||
<Button
|
||||
leftIcon={<IconFileUpload size='1rem' />}
|
||||
onClick={handleUpload}
|
||||
disabled={files.length === 0 ? true : false}
|
||||
loading={loading}
|
||||
disabled={files.length === 0 || loading}
|
||||
>
|
||||
Upload
|
||||
</Button>
|
||||
|
|
|
@ -30,6 +30,45 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
|||
|
||||
if (!user) return res.forbidden('authorization incorrect');
|
||||
|
||||
if (user.ratelimit && !req.headers['content-range']) {
|
||||
const remaining = user.ratelimit.getTime() - Date.now();
|
||||
logger.debug(`${user.id} encountered ratelimit, ${remaining}ms remaining`);
|
||||
if (remaining <= 0) {
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
data: {
|
||||
ratelimit: null,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
return res.ratelimited(remaining);
|
||||
}
|
||||
} else if (!user.ratelimit && !req.headers['content-range']) {
|
||||
if (user.administrator && zconfig.ratelimit.admin > 0) {
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
data: {
|
||||
ratelimit: new Date(Date.now() + zconfig.ratelimit.admin * 1000),
|
||||
},
|
||||
});
|
||||
} else if (!user.administrator && zconfig.ratelimit.user > 0) {
|
||||
if (user.administrator && zconfig.ratelimit.user > 0) {
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
data: {
|
||||
ratelimit: new Date(Date.now() + zconfig.ratelimit.user * 1000),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
uploader.array('file')(req as never, res as never, (result: unknown) => {
|
||||
if (result instanceof Error) reject(result.message);
|
||||
|
@ -197,23 +236,6 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
|||
});
|
||||
}
|
||||
|
||||
if (user.ratelimit) {
|
||||
const remaining = user.ratelimit.getTime() - Date.now();
|
||||
logger.debug(`${user.id} encountered ratelimit, ${remaining}ms remaining`);
|
||||
if (remaining <= 0) {
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
data: {
|
||||
ratelimit: null,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
return res.ratelimited(remaining);
|
||||
}
|
||||
}
|
||||
|
||||
if (!req.files) return res.badRequest('no files');
|
||||
if (req.files && req.files.length === 0) return res.badRequest('no files');
|
||||
|
||||
|
@ -340,28 +362,6 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
|||
}
|
||||
}
|
||||
|
||||
if (user.administrator && zconfig.ratelimit.admin > 0) {
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
data: {
|
||||
ratelimit: new Date(Date.now() + zconfig.ratelimit.admin * 1000),
|
||||
},
|
||||
});
|
||||
} else if (!user.administrator && zconfig.ratelimit.user > 0) {
|
||||
if (user.administrator && zconfig.ratelimit.user > 0) {
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
data: {
|
||||
ratelimit: new Date(Date.now() + zconfig.ratelimit.user * 1000),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (req.headers['no-json']) {
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
return res.end(response.files.join(','));
|
||||
|
|
Loading…
Add table
Reference in a new issue