mirror of
https://github.com/rikkaneko/paste.git
synced 2025-08-08 23:15:34 +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)];
|
return [decoded.slice(0, index), decoded.slice(index + 1)];
|
||||||
} else if (scheme == 'Bearer') {
|
} else if (scheme == 'Bearer') {
|
||||||
return encoded;
|
if (encoded.length > 0) return encoded;
|
||||||
|
else null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -80,7 +80,7 @@ router.post('/info/:uuid', async (req, env, ctx) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Check password and username should be empty
|
// 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.');
|
return PasteAPIRepsonse.build(403, 'Invalid access credentials.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,13 +91,23 @@ router.post('/info/:uuid', async (req, env, ctx) => {
|
||||||
|
|
||||||
// Change paste info logic
|
// Change paste info logic
|
||||||
// Explict assign the fields
|
// Explict assign the fields
|
||||||
const updated_descriptor = {
|
const update: PasteInfoUpdateParams = {
|
||||||
...descriptor,
|
|
||||||
password: params.password ? sha256(params.password).slice(0, 16) : undefined,
|
password: params.password ? sha256(params.password).slice(0, 16) : undefined,
|
||||||
max_access_n: params.max_access_n,
|
max_access_n: params.max_access_n,
|
||||||
title: params.title,
|
title: params.title,
|
||||||
mime_type: params.mime_type,
|
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 }));
|
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.');
|
return PasteAPIRepsonse.build(200, 'This endpoint is not ready.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Fallback route
|
||||||
|
router.all('*', async () => {
|
||||||
|
return PasteAPIRepsonse.build(403, 'Invalid endpoint.');
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue