mirror of
https://github.com/rikkaneko/paste.git
synced 2025-08-08 06:55:32 +01:00
Fix edit-meta API logic
Signed-off-by: Joe Ma <rikkaneko23@gmail.com>
This commit is contained in:
parent
a2347f9f94
commit
bc0704f49d
2 changed files with 21 additions and 5 deletions
|
@ -171,7 +171,8 @@ export function get_auth(headers: Headers, required_scheme: string): string | [s
|
|||
|
||||
return [decoded.slice(0, index), decoded.slice(index + 1)];
|
||||
} else if (scheme == 'Bearer') {
|
||||
return encoded;
|
||||
if (encoded.length > 0) return encoded;
|
||||
else null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -80,7 +80,7 @@ router.post('/info/:uuid', async (req, env, ctx) => {
|
|||
);
|
||||
}
|
||||
// Check password and username should be empty
|
||||
if (cert.length != 0 || descriptor.password !== sha256(cert).slice(0, 16)) {
|
||||
if (descriptor.password !== sha256(cert as string).slice(0, 16)) {
|
||||
return PasteAPIRepsonse.build(403, 'Invalid access credentials.');
|
||||
}
|
||||
}
|
||||
|
@ -91,13 +91,23 @@ router.post('/info/:uuid', async (req, env, ctx) => {
|
|||
|
||||
// Change paste info logic
|
||||
// Explict assign the fields
|
||||
const updated_descriptor = {
|
||||
...descriptor,
|
||||
const update: PasteInfoUpdateParams = {
|
||||
password: params.password ? sha256(params.password).slice(0, 16) : undefined,
|
||||
max_access_n: params.max_access_n,
|
||||
title: params.title,
|
||||
mime_type: params.mime_type,
|
||||
expired_at: params.expired_at ? params.expired_at : descriptor.expired_at,
|
||||
expired_at: params.expired_at,
|
||||
};
|
||||
|
||||
// Remove redundant fields
|
||||
Object.keys(update).forEach(
|
||||
(key) =>
|
||||
update[key as keyof PasteInfoUpdateParams] === undefined && delete update[key as keyof PasteInfoUpdateParams]
|
||||
);
|
||||
|
||||
const updated_descriptor: PasteIndexEntry = {
|
||||
...descriptor,
|
||||
...update,
|
||||
};
|
||||
|
||||
ctx.waitUntil(env.PASTE_INDEX.put(uuid, JSON.stringify(updated_descriptor), { expirationTtl: 2419200 }));
|
||||
|
@ -291,4 +301,9 @@ router.post('/upload', async (req, env, ctx) => {
|
|||
return PasteAPIRepsonse.build(200, 'This endpoint is not ready.');
|
||||
});
|
||||
|
||||
// Fallback route
|
||||
router.all('*', async () => {
|
||||
return PasteAPIRepsonse.build(403, 'Invalid endpoint.');
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue