fix: fix error

This commit is contained in:
2025-01-03 21:33:01 +08:00
parent edde6181f7
commit a97bb5f732
8 changed files with 468 additions and 104 deletions

View File

@@ -26,6 +26,8 @@ app
path: item.path,
key: item.key,
description: item.description,
validator: item.validator,
// schema: item.schema,
};
});
})

View File

@@ -9,7 +9,7 @@ import { app, minioClient } from '@/app.ts';
import { bucketName } from '@/modules/minio.ts';
import { getContentType } from '@/utils/get-content-type.ts';
import { hash } from 'crypto';
import { MicroAppModel } from '@/routes/micro-app/models.ts';
import { MicroAppUploadModel } from '@/routes/micro-app/models.ts';
const cacheFilePath = useFileStore('cache-file', { needExists: true });
router.post('/api/micro-app/upload', async (req, res) => {
@@ -137,7 +137,7 @@ router.get('/api/micro-app/download/:id', async (req, res) => {
tokenUser = auth.tokenUser;
if (!tokenUser) return;
}
const file = await MicroAppModel.findByPk(id);
const file = await MicroAppUploadModel.findByPk(id);
if (!DEV_SERVER) {
file.uid !== tokenUser.id && res.end(error('No permission', 403));
return;

View File

@@ -1 +1,2 @@
import './list.ts';
import './list.ts';
import './upload-list.ts'

View File

@@ -1,5 +1,5 @@
import { app } from '@/app.ts';
import { MicroAppModel } from './models.ts';
import { MicroAppUploadModel } from './models.ts';
import { appPathCheck, installApp } from './module/install-app.ts';
import { manager } from './manager-app.ts';
@@ -21,7 +21,7 @@ app
if (collection?.tags) {
tags.push(...collection.tags);
}
const microApp = await MicroAppModel.create({
const microApp = await MicroAppUploadModel.create({
title: name,
description: collection?.readme || '',
type: 'micro-app',
@@ -63,7 +63,7 @@ app
if (!id) {
ctx.throw(400, 'Invalid id');
}
const microApp = await MicroAppModel.findByPk(id);
const microApp = await MicroAppUploadModel.findByPk(id);
const { file } = microApp.data || {};
const path = file?.path;
if (!path) {

View File

@@ -1,7 +1,7 @@
import { sequelize } from '@/modules/sequelize.ts';
import { DataTypes, Model } from 'sequelize';
export type MicroApp = Partial<InstanceType<typeof MicroAppModel>>;
export type MicroApp = Partial<InstanceType<typeof MicroAppUploadModel>>;
type MicroAppData = {
file?: {
@@ -14,7 +14,7 @@ type MicroAppData = {
data?: any;
collection?: any; // 上传的信息汇总
};
export class MicroAppModel extends Model {
export class MicroAppUploadModel extends Model {
declare id: string;
declare title: string;
declare description: string;
@@ -29,7 +29,7 @@ export class MicroAppModel extends Model {
declare uname: string;
}
MicroAppModel.init(
MicroAppUploadModel.init(
{
id: {
type: DataTypes.UUID,
@@ -76,11 +76,11 @@ MicroAppModel.init(
},
{
sequelize,
tableName: 'micro_apps',
tableName: 'micro_apps_upload',
// paranoid: true,
},
);
MicroAppModel.sync({ alter: true, logging: false }).catch((e) => {
console.error('MicroAppModel sync', e);
MicroAppUploadModel.sync({ alter: true, logging: false }).catch((e) => {
console.error('MicroAppUploadModel sync', e);
});

View File

@@ -0,0 +1,57 @@
import { app } from '@/app.ts';
import { MicroAppUploadModel } from './models.ts';
// 获取MicroAppUpload的uploadList的接口
app
.route({
path: 'micro-app-upload',
key: 'list',
middleware: ['auth'],
description: 'Get micro app upload list',
})
.define(async (ctx) => {
const { uid } = ctx.state.tokenUser;
const uploadList = await MicroAppUploadModel.findAll({
where: { uid },
});
ctx.body = uploadList;
})
.addTo(app);
// 获取单个MicroAppUpload的接口
app
.route({
path: 'micro-app-upload',
key: 'get',
middleware: ['auth'],
description: 'Get a single micro app upload',
})
.define(async (ctx) => {
const { id } = ctx.query;
const upload = await MicroAppUploadModel.findOne({
where: { id },
});
if (upload) {
ctx.body = upload;
} else {
ctx.throw(404, 'Not found');
}
})
.addTo(app);
// 删除MicroAppUpload的接口
app
.route({
path: 'micro-app-upload',
key: 'delete',
middleware: ['auth'],
description: 'Delete a micro app upload',
})
.define(async (ctx) => {
const { id } = ctx.query;
const deleted = await MicroAppUploadModel.destroy({
where: { id },
});
ctx.body = { deleted };
})
.addTo(app);