feat: add download micro-app for cli

This commit is contained in:
2025-03-11 11:04:10 +08:00
parent 7b25dbdf08
commit 1c820c3083
8 changed files with 186 additions and 155 deletions

View File

@@ -5,13 +5,22 @@ export const error = (msg: string, code = 500) => {
return JSON.stringify({ code, message: msg });
};
export const checkAuth = async (req: http.IncomingMessage, res: http.ServerResponse) => {
let token = '';
const authroization = req.headers?.['authorization'] as string;
if (!authroization) {
const url = new URL(req.url || '', 'http://localhost');
const resNoPermission = () => {
res.statusCode = 401;
res.end(error('Invalid authorization'));
return { tokenUser: null, token: null };
};
if (authroization) {
// return resNoPermission();
token = authroization.split(' ')[1];
} else if (url.searchParams.get('token')) {
token = url.searchParams.get('token') || '';
} else {
return resNoPermission();
}
const token = authroization.split(' ')[1];
let tokenUser;
try {
tokenUser = await User.verifyToken(token);