feat: 修改为bun,优化代码

This commit is contained in:
2025-05-20 00:36:32 +08:00
parent 3de5754f24
commit 1f4404fa5c
32 changed files with 618 additions and 1035 deletions

View File

@@ -0,0 +1,3 @@
import { CreateDemoUser } from '@/models/user.ts';
await CreateDemoUser();

21
src/test/container.ts Normal file
View File

@@ -0,0 +1,21 @@
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();

View File

@@ -0,0 +1,40 @@
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();

15
src/test/mv-minio.ts Normal file
View File

@@ -0,0 +1,15 @@
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');

View File

@@ -0,0 +1,8 @@
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();

21
src/test/sp-snippet.ts Normal file
View File

@@ -0,0 +1,21 @@
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();

46
src/test/sync-mark.ts Normal file
View File

@@ -0,0 +1,46 @@
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();

48
src/test/sync-user.ts Normal file
View File

@@ -0,0 +1,48 @@
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('');
await user.save();
console.log('change root password done');
process.exit(0);
}
};
// changeRootPassword();

View File

12
src/test/user.ts Normal file
View File

@@ -0,0 +1,12 @@
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);
}
});