添加删除文件

This commit is contained in:
2025-03-26 00:05:58 +08:00
parent 64c70ce527
commit 501a92eb88
10 changed files with 236 additions and 9 deletions

View File

@@ -0,0 +1,90 @@
import { app } from '@/app.ts';
import { AppModel } from '../module/app.ts';
import { AppDomainModel } from '../module/app-domain.ts';
app
.route({
path: 'app',
key: 'getDomainApp',
})
.define(async (ctx) => {
const { domain } = ctx.query.data;
// const query = {
// }
const domainInfo = await AppDomainModel.findOne({ where: { domain } });
if (!domainInfo || !domainInfo.appId) {
ctx.throw(404, 'app not found');
}
const app = await AppModel.findByPk(domainInfo.appId);
if (!app) {
ctx.throw(404, 'app not found');
}
ctx.body = app;
return ctx;
})
.addTo(app);
app
.route({
path: 'app-domain',
key: 'create',
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const uid = tokenUser.uid;
const { domain, appId } = ctx.query.data || {};
if (!domain || !appId) {
ctx.throw(400, 'domain and appId are required');
}
const domainInfo = await AppDomainModel.create({ domain, appId, uid });
ctx.body = domainInfo;
return ctx;
})
.addTo(app);
app
.route({
path: 'app-domain',
key: 'update',
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const uid = tokenUser.uid;
const { id, domain, appId, status } = ctx.query.data || {};
if (!domain && !id) {
ctx.throw(400, 'domain and id are required at least one');
}
if (!status) {
ctx.throw(400, 'status is required');
}
let domainInfo: AppDomainModel | null = null;
if (id) {
domainInfo = await AppDomainModel.findByPk(id);
}
if (!domainInfo && domain) {
domainInfo = await AppDomainModel.findOne({ where: { domain, appId } });
}
if (!domainInfo) {
ctx.throw(404, 'domain not found');
}
if (domainInfo.uid !== uid) {
ctx.throw(403, 'domain must be owned by the user');
}
if (!domainInfo.checkCanUpdateStatus(status)) {
ctx.throw(400, 'domain status can not be updated');
}
if (status) {
domainInfo.status = status;
}
if (appId) {
domainInfo.appId = appId;
}
await domainInfo.save({ fields: ['status', 'appId'] });
ctx.body = domainInfo;
return ctx;
})
.addTo(app);