temp
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { App } from '@kevisual/router';
|
||||
import { app } from './app.ts';
|
||||
|
||||
import './route/system-config/index.ts';
|
||||
|
||||
type Message = {
|
||||
path: string;
|
||||
key?: string;
|
||||
|
||||
@@ -21,6 +21,9 @@ export const pollLoginStatus = async (token: string, opts: PollLoginOptions) =>
|
||||
load.load(
|
||||
async () => {
|
||||
const res = await queryLogin.checkLoginStatus(token);
|
||||
if (res.code === 500) {
|
||||
load.cancel('check-login-status');
|
||||
}
|
||||
return res;
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
import './list.ts'
|
||||
@@ -1,57 +0,0 @@
|
||||
import { app } from '@/app.ts';
|
||||
import { Config } from './model/config.ts';
|
||||
app
|
||||
.route({
|
||||
path: 'config',
|
||||
key: 'list',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
ctx.body = await Config.findAll();
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'config',
|
||||
key: 'meGet',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const config = await Config.findOne({
|
||||
where: {
|
||||
key: 'me',
|
||||
},
|
||||
logging: false,
|
||||
});
|
||||
ctx.body = config;
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'config',
|
||||
key: 'meSet',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const { data } = ctx.query;
|
||||
if (!data) {
|
||||
ctx.throw(400, 'data is required');
|
||||
}
|
||||
let config = await Config.findOne({
|
||||
where: { key: 'me' }, // 自定义条件
|
||||
logging: false,
|
||||
});
|
||||
|
||||
if (!config) {
|
||||
config = await Config.create({
|
||||
key: 'me',
|
||||
value: data,
|
||||
});
|
||||
ctx.body = config;
|
||||
return;
|
||||
} else {
|
||||
config.value = data;
|
||||
await config.save();
|
||||
ctx.body = config;
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
@@ -1,39 +0,0 @@
|
||||
import { sequelize } from '@/app.ts';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
|
||||
// Define the system config model
|
||||
|
||||
export class Config extends Model {
|
||||
declare id: number;
|
||||
declare key: string;
|
||||
declare value: string;
|
||||
}
|
||||
|
||||
Config.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
},
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
value: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: {},
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'system_config',
|
||||
},
|
||||
);
|
||||
|
||||
await Config.sync({
|
||||
alter: true,
|
||||
logging: false,
|
||||
}).catch((e) => {
|
||||
console.error('Config table sync error', e);
|
||||
});
|
||||
Reference in New Issue
Block a user