feat: 上传文件到minio
This commit is contained in:
@@ -10,10 +10,15 @@ app
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const data = ctx.query.data || {};
|
||||
if (!data.key) {
|
||||
throw new CustomError('key is required');
|
||||
}
|
||||
const list = await AppListModel.findAll({
|
||||
order: [['updatedAt', 'DESC']],
|
||||
where: {
|
||||
uid: tokenUser.id,
|
||||
key: data.key,
|
||||
},
|
||||
});
|
||||
ctx.body = list;
|
||||
@@ -61,6 +66,10 @@ app
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rest.key) {
|
||||
throw new CustomError('key is required');
|
||||
}
|
||||
const app = await AppListModel.create({ data, ...rest, uid: tokenUser.id });
|
||||
ctx.body = app;
|
||||
return ctx;
|
||||
@@ -82,7 +91,9 @@ app
|
||||
if (!app) {
|
||||
throw new CustomError('app not found');
|
||||
}
|
||||
await app.destroy();
|
||||
await app.destroy({
|
||||
force: true,
|
||||
});
|
||||
ctx.body = 'success';
|
||||
return ctx;
|
||||
})
|
||||
|
||||
@@ -11,8 +11,7 @@ export class AppListModel extends Model {
|
||||
declare id: string;
|
||||
declare data: AppData;
|
||||
declare version: string;
|
||||
declare appType: AppType;
|
||||
declare type: string;
|
||||
declare key: string;
|
||||
declare uid: string;
|
||||
}
|
||||
|
||||
@@ -32,13 +31,8 @@ AppListModel.init(
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '',
|
||||
},
|
||||
appType: {
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '',
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '',
|
||||
},
|
||||
uid: {
|
||||
type: DataTypes.UUID,
|
||||
|
||||
@@ -14,6 +14,8 @@ export type App = Partial<InstanceType<typeof AppModel>>;
|
||||
export class AppModel extends Model {
|
||||
declare id: string;
|
||||
declare data: AppData;
|
||||
declare title: string;
|
||||
declare description: string;
|
||||
declare version: string;
|
||||
declare domain: string;
|
||||
declare appType: string;
|
||||
@@ -21,6 +23,7 @@ export class AppModel extends Model {
|
||||
declare type: string;
|
||||
declare uid: string;
|
||||
declare user: string;
|
||||
declare status: string;
|
||||
}
|
||||
AppModel.init(
|
||||
{
|
||||
@@ -30,6 +33,14 @@ AppModel.init(
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
comment: 'id',
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '',
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '',
|
||||
},
|
||||
data: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: {},
|
||||
@@ -48,7 +59,7 @@ AppModel.init(
|
||||
},
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
unique: true,
|
||||
// 和 uid 组合唯一
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.STRING,
|
||||
@@ -58,11 +69,25 @@ AppModel.init(
|
||||
type: DataTypes.UUID,
|
||||
allowNull: true,
|
||||
},
|
||||
user: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: 'running', // stop, running
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'kv_app',
|
||||
paranoid: true,
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['key', 'uid'],
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ app
|
||||
middleware: ['auth'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
|
||||
const { data, id, ...rest } = ctx.query.data;
|
||||
if (id) {
|
||||
const app = await AppModel.findByPk(id);
|
||||
@@ -60,8 +62,19 @@ app
|
||||
}
|
||||
return;
|
||||
}
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const app = await AppModel.create({ data, ...rest, uid: tokenUser.id });
|
||||
if (!rest.key) {
|
||||
throw new CustomError('key is required');
|
||||
}
|
||||
const findApp = await AppModel.findOne({ where: { key: rest.key, uid: tokenUser.id } });
|
||||
if (findApp) {
|
||||
throw new CustomError('key already exists');
|
||||
}
|
||||
const app = await AppModel.create({
|
||||
data: { files: [] },
|
||||
...rest,
|
||||
uid: tokenUser.id,
|
||||
user: tokenUser.username,
|
||||
});
|
||||
ctx.body = app;
|
||||
return ctx;
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user