feat(wip): 支持 JWT

This commit is contained in:
xream
2024-10-30 22:27:39 +08:00
parent 07e50175f9
commit 542957d34a
4 changed files with 7433 additions and 7392 deletions

View File

@@ -20,6 +20,26 @@ export default function register($app) {
$app.get('/api/utils/env', getEnv); // get runtime environment
$app.get('/api/utils/backup', gistBackup); // gist backup actions
$app.get('/api/utils/refresh', refresh);
$app.post('/api/jwt', (req, res) => {
if (!ENV().isNode) {
return failed(
res,
new RequestInvalidError(
'INVALID_ENV',
`This endpoint is only available in Node.js environment`,
),
);
}
const { payload, options } = req.body;
const jwt = eval(`require("jsonwebtoken")`);
res.set('Content-Type', 'application/json;charset=utf-8').send({
token: jwt.sign(
payload,
eval('process.env.SUB_STORE_FRONTEND_BACKEND_PATH'),
options,
),
});
});
// Storage management
$app.route('/api/storage')