feat: 修改为bun,优化代码
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
import { CreateDemoUser } from '@/models/user.ts';
|
||||
|
||||
await CreateDemoUser();
|
||||
50
src/scripts/change-user-pwd.ts
Normal file
50
src/scripts/change-user-pwd.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { program, Command } from '../program.ts';
|
||||
import { initUser, logger, close } from './common.ts';
|
||||
const usrCommand = new Command('user').description('用户相关操作');
|
||||
program.addCommand(usrCommand);
|
||||
|
||||
const changePwd = new Command('pwd')
|
||||
.description('修改用户密码')
|
||||
.option('-u, --username <username>', '用户名')
|
||||
.option('-p, --password <password>', '新密码')
|
||||
.action(async (opts) => {
|
||||
const username = opts.username;
|
||||
const password = opts.password;
|
||||
if (!username) {
|
||||
logger.error('用户名不能为空');
|
||||
close();
|
||||
return;
|
||||
}
|
||||
const { User } = await initUser();
|
||||
const newPassword = password || 'kevisual';
|
||||
|
||||
logger.info(`用户名: ${username}`);
|
||||
logger.info(`新密码: ${newPassword}`);
|
||||
const user = await User.findOne({ where: { username: username }, logging: false });
|
||||
if (!user) {
|
||||
logger.error('用户不存在');
|
||||
return;
|
||||
}
|
||||
const newP = await user.createPassword(newPassword);
|
||||
logger.info('新密码加密成功', '新密码: ', newPassword);
|
||||
close();
|
||||
});
|
||||
usrCommand.addCommand(changePwd);
|
||||
|
||||
const list = new Command('list').description('列出所有用户').action(async () => {
|
||||
console.log('列出所有用户 start');
|
||||
const { User } = await initUser();
|
||||
console.log('列出所有用户');
|
||||
const users = await User.findAll({ limit: 10, order: [['createdAt', 'DESC']] });
|
||||
if (users.length === 0) {
|
||||
logger.info('没有用户');
|
||||
return;
|
||||
}
|
||||
users.forEach((user) => {
|
||||
console.log(`用户名: ${user.username}`);
|
||||
});
|
||||
console.log(`用户数量: ${users.length}`);
|
||||
await close();
|
||||
});
|
||||
|
||||
usrCommand.addCommand(list);
|
||||
29
src/scripts/common.ts
Normal file
29
src/scripts/common.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { config } from '../modules/config.ts';
|
||||
import { sequelize } from '../modules/sequelize.ts';
|
||||
export { program, Command } from '../program.ts';
|
||||
import { User, UserInit, OrgInit, Org } from '@kevisual/code-center-module/models';
|
||||
import { Logger } from '@kevisual/logger';
|
||||
export const close = async () => {
|
||||
process.exit(0);
|
||||
};
|
||||
export { sequelize };
|
||||
export const logger = new Logger({
|
||||
level: (config?.LOG_LEVEL || 'info') as any,
|
||||
showTime: true,
|
||||
});
|
||||
|
||||
export const initUser = async () => {
|
||||
console.log('init user');
|
||||
await UserInit(sequelize, undefined, {
|
||||
alter: true,
|
||||
logging: false,
|
||||
});
|
||||
await OrgInit(sequelize, undefined, {
|
||||
alter: true,
|
||||
logging: false,
|
||||
});
|
||||
return {
|
||||
User: User,
|
||||
Org: Org,
|
||||
};
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
import { ContainerModel } from '../routes/container/models/index.ts';
|
||||
|
||||
const main = async () => {
|
||||
// await ContainerModel.update(
|
||||
// {
|
||||
// type: 'render-js',
|
||||
// },
|
||||
// {
|
||||
// where: {
|
||||
// type: '',
|
||||
// },
|
||||
// },
|
||||
// );
|
||||
const containers = await ContainerModel.findAll();
|
||||
for (const container of containers) {
|
||||
console.log(container.id, container.type);
|
||||
}
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
main();
|
||||
@@ -1,40 +0,0 @@
|
||||
import { bucketName, minioClient } from '@/modules/minio.ts';
|
||||
import { S3Error } from 'minio';
|
||||
const main = async () => {
|
||||
const res = await new Promise((resolve, reject) => {
|
||||
let res: any[] = [];
|
||||
let hasError = false;
|
||||
minioClient
|
||||
.listObjectsV2(bucketName, 'root/codeflow/0.0.1/')
|
||||
.on('data', (data) => {
|
||||
res.push(data);
|
||||
})
|
||||
.on('error', (err) => {
|
||||
console.error('error', err);
|
||||
hasError = true;
|
||||
})
|
||||
.on('end', () => {
|
||||
if (hasError) {
|
||||
reject();
|
||||
return;
|
||||
} else {
|
||||
resolve(res);
|
||||
}
|
||||
});
|
||||
});
|
||||
console.log(res);
|
||||
};
|
||||
// main();
|
||||
|
||||
const main2 = async () => {
|
||||
try {
|
||||
const obj = await minioClient.statObject(bucketName, 'root/codeflow/0.0.1/README.md');
|
||||
|
||||
console.log(obj);
|
||||
} catch (e) {
|
||||
console.log('', e.message, '\n\r', e.code);
|
||||
// console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
main2();
|
||||
12
src/scripts/list-app.ts
Normal file
12
src/scripts/list-app.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { AppListModel, AppModel } from '../routes/app-manager/module/index.ts';
|
||||
|
||||
import { program, Command, close } from './common.ts';
|
||||
|
||||
const app = program.command('app');
|
||||
|
||||
const appList = new Command('list').action(async () => {
|
||||
const list = await AppListModel.findAll();
|
||||
console.log(list.map((item) => item.toJSON()));
|
||||
close();
|
||||
});
|
||||
app.addCommand(appList);
|
||||
@@ -1,15 +0,0 @@
|
||||
process.env.NODE_ENV = 'development';
|
||||
// import { mvUserAToUserB, backupUserA } from '../routes/file/module/get-minio-list.ts';
|
||||
|
||||
|
||||
// mvUserAToUserB('demo', 'demo2');
|
||||
|
||||
// backupUserA('demo', '123', '2025-04-02-16-00');
|
||||
// backupUserA('demo', '123', '2025-04-02-16-01');
|
||||
// backupUserA('demo', '123', '2025-04-02-16-02');
|
||||
// backupUserA('demo', '123', '2025-04-02-16-03');
|
||||
// backupUserA('demo', '123', '2025-04-02-16-04');
|
||||
// backupUserA('demo', '123', '2025-04-02-16-05');
|
||||
// backupUserA('demo', '123', '2025-04-02-16-06');
|
||||
// backupUserA('demo', '123', '2025-04-02-16-07');
|
||||
// backupUserA('demo', '123', '2025-04-02-16-08');
|
||||
@@ -1,8 +0,0 @@
|
||||
import { AppListModel } from '../routes/app-manager/module/index.ts';
|
||||
|
||||
const main = async () => {
|
||||
const list = await AppListModel.findAll();
|
||||
console.log(list.map((item) => item.key));
|
||||
};
|
||||
|
||||
main();
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Snippet } from '@/routes/snippet/snippet.ts';
|
||||
|
||||
const main = async () => {
|
||||
const snippet = await Snippet.findAndCountAll();
|
||||
|
||||
console.log(snippet.count);
|
||||
};
|
||||
|
||||
// main();
|
||||
|
||||
const addOne = async () => {
|
||||
const snippet = await Snippet.create({
|
||||
title: 'Hello',
|
||||
description: 'Hello World',
|
||||
snippet: 'console.log("Hello")',
|
||||
keyword: '!hello',
|
||||
user_id: '3f82e3ae-b7c2-4244-849f-d453f304b2f2',
|
||||
});
|
||||
console.log(snippet);
|
||||
};
|
||||
// await addOne();
|
||||
@@ -1,46 +0,0 @@
|
||||
import { useContextKey } from '@kevisual/use-config/context';
|
||||
import { sequelize } from '../modules/sequelize.ts';
|
||||
import { MarkModel, syncMarkModel } from '../routes/mark/model.ts';
|
||||
export const sequelize2 = useContextKey('sequelize', () => sequelize);
|
||||
|
||||
const main = async () => {
|
||||
// 把所有markmodel的表的source字段的类型改为jsonb
|
||||
// const marks = await MarkModel.findAll();
|
||||
// const mark = marks[0];
|
||||
|
||||
// for (const mark of marks) {
|
||||
// if (mark.source) {
|
||||
// try {
|
||||
// await MarkModel.update({ source: {} }, { where: { id: mark.id } });
|
||||
// } catch (e) {
|
||||
// console.error('update source error:', e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
console.log('update source success');
|
||||
// await MarkModel.sync({ alter: true, logging: true }).catch((e) => {
|
||||
// console.error('MarkModel.sync error:', e);
|
||||
// });
|
||||
await syncMarkModel({ alter: true, logging: true, sync: true });
|
||||
};
|
||||
|
||||
main();
|
||||
|
||||
const sql = `ALTER TABLE "micro_mark" ALTER COLUMN "source" DROP NOT NULL;ALTER TABLE "micro_mark" ALTER COLUMN "source" SET DEFAULT '{}';ALTER TABLE "micro_mark" ALTER COLUMN "source" TYPE JSONB ; COMMENT ON COLUMN "micro_mark"."source" IS '需要的数据的来源,作为一个备注使用。';`;
|
||||
|
||||
// sequelize
|
||||
/**
|
||||
* 失败
|
||||
*/
|
||||
const runSql = async () => {
|
||||
sequelize
|
||||
.query(sql)
|
||||
.then(() => {
|
||||
console.log('update source success');
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error('update source error:', e);
|
||||
});
|
||||
};
|
||||
|
||||
// runSql();
|
||||
@@ -1,48 +0,0 @@
|
||||
import { sequelize } from '../modules/sequelize.ts';
|
||||
import { User, UserInit, UserServices, Org, OrgInit } from '@kevisual/code-center-module/models';
|
||||
|
||||
// User.sync({ alter: true, logging: true }).then(() => {
|
||||
// console.log('sync user done');
|
||||
// });
|
||||
|
||||
// class UserChange extends User {
|
||||
// static async syncUser() {
|
||||
// await UserChange.sync({ alter: true, logging: false });
|
||||
// console.log('sync user done');
|
||||
// }
|
||||
// }
|
||||
export const main = async () => {
|
||||
await UserInit(sequelize, null, {
|
||||
alter: true,
|
||||
logging: false,
|
||||
});
|
||||
await OrgInit(sequelize, null, {
|
||||
alter: true,
|
||||
logging: false,
|
||||
});
|
||||
const user = await User.findAll({});
|
||||
for (const u of user) {
|
||||
console.log(u.username, u.type);
|
||||
}
|
||||
};
|
||||
|
||||
// main();
|
||||
export const changeRootPassword = async () => {
|
||||
await OrgInit(sequelize, null, {
|
||||
alter: true,
|
||||
logging: false,
|
||||
});
|
||||
await UserInit(sequelize, null, {
|
||||
alter: true,
|
||||
logging: false,
|
||||
});
|
||||
const user = await User.findOne({ where: { username: 'root' } });
|
||||
if (user) {
|
||||
await user.createPassword('Abear123456x');
|
||||
await user.save();
|
||||
console.log('change root password done');
|
||||
process.exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
changeRootPassword();
|
||||
@@ -1,12 +0,0 @@
|
||||
import { User } from '../models/user.ts';
|
||||
|
||||
const uid = '9b7b521d-082e-4a39-8410-9569c07e3e72';
|
||||
|
||||
User.findByPk(uid).then((user) => {
|
||||
console.log(user);
|
||||
});
|
||||
User.findAll().then((users) => {
|
||||
for (let user of users) {
|
||||
console.log(user.id, user.username);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user