1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-09-17 18:06:10 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee
Files
react-native-update-cli/src/user.ts
sunnylqm b24b27d100 ts
2025-01-11 20:23:25 +08:00

34 lines
930 B
TypeScript

import { question } from './utils';
import { post, get, replaceSession, saveSession, closeSession } from './api';
import crypto from 'node:crypto';
function md5(str: string) {
return crypto.createHash('md5').update(str).digest('hex');
}
export const commands = {
login: async ({ args }: { args: string[] }) => {
const email = args[0] || (await question('email:'));
const pwd = args[1] || (await question('password:', true));
const { token, info } = await post('/user/login', {
email,
pwd: md5(pwd),
});
replaceSession({ token });
await saveSession();
console.log(`欢迎使用 pushy 热更新服务, ${info.name}.`);
},
logout: async () => {
await closeSession();
console.log('已退出登录');
},
me: async () => {
const me = await get('/user/me');
for (const k in me) {
if (k !== 'ok') {
console.log(`${k}: ${me[k]}`);
}
}
},
};