fix: 修改uploadFiles和container上传
This commit is contained in:
@@ -2,10 +2,11 @@ import { CustomError } from '@abearxiong/router';
|
||||
import { app } from '../../app.ts';
|
||||
import { ContainerModel, ContainerData, Container } from './models/index.ts';
|
||||
import semver from 'semver';
|
||||
import { uploadMinioContainer } from '../page/module/cache-file.ts';
|
||||
const list = app.route({
|
||||
path: 'container',
|
||||
key: 'list',
|
||||
middleware: ['auth']
|
||||
middleware: ['auth'],
|
||||
});
|
||||
|
||||
list.run = async (ctx) => {
|
||||
@@ -106,12 +107,13 @@ app
|
||||
.route({
|
||||
path: 'container',
|
||||
key: 'publish',
|
||||
nextRoute: { path: 'resource', key: 'publishContainer' },
|
||||
// nextRoute: { path: 'resource', key: 'publishContainer' },
|
||||
middleware: ['auth'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const { data } = ctx.query;
|
||||
const { id, publish, type = 'patch', beta = false } = data;
|
||||
type PublishType = 'patch' | 'minor' | 'major';
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const { data, token } = ctx.query;
|
||||
const { id, publish } = data;
|
||||
if (!id) {
|
||||
throw new CustomError('id is required');
|
||||
}
|
||||
@@ -119,30 +121,31 @@ app
|
||||
if (!container) {
|
||||
throw new CustomError('container not found');
|
||||
}
|
||||
const { name, description } = publish;
|
||||
const oldPublish = container.publish;
|
||||
let _version = '';
|
||||
if (!oldPublish.version) {
|
||||
if (publish.name) {
|
||||
throw new CustomError('publish name is required');
|
||||
}
|
||||
container.publish = {
|
||||
name,
|
||||
description,
|
||||
version: '0.0.1',
|
||||
};
|
||||
} else {
|
||||
_version = semver.inc(oldPublish.version, type as PublishType, beta ? 'beta' : undefined);
|
||||
container.publish.version = _version;
|
||||
container.publish = publish;
|
||||
await container.save();
|
||||
const { title, description, key, version, fileName } = publish;
|
||||
ctx.body = container;
|
||||
if (!key || !version || !fileName) {
|
||||
return;
|
||||
}
|
||||
if (ctx.state) {
|
||||
ctx.state.container = container;
|
||||
} else {
|
||||
ctx.state = {
|
||||
container,
|
||||
};
|
||||
}
|
||||
// 执行下一步操作了
|
||||
ctx.body = 'run ok';
|
||||
const uploadResult = await uploadMinioContainer({
|
||||
key,
|
||||
tokenUser: ctx.state.tokenUser,
|
||||
version: version,
|
||||
code: container.code,
|
||||
filePath: fileName,
|
||||
});
|
||||
await ctx.call({
|
||||
path: 'app',
|
||||
key: 'uploadFiles',
|
||||
payload: {
|
||||
token,
|
||||
data: {
|
||||
appKey: key,
|
||||
version,
|
||||
files: [uploadResult],
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
Reference in New Issue
Block a user