暂存
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { CustomError } from '@abearxiong/router';
|
||||
import { app } from '../../app.ts';
|
||||
import { ContainerModel, ContainerData, Container } from './models/index.ts';
|
||||
|
||||
import semver from 'semver';
|
||||
const list = app.route({
|
||||
path: 'container',
|
||||
key: 'list',
|
||||
});
|
||||
list.run = async (ctx) => {
|
||||
const list = await ContainerModel.findAll();
|
||||
const list = await ContainerModel.findAll({
|
||||
order: [['updatedAt', 'DESC']],
|
||||
});
|
||||
ctx.body = list;
|
||||
return ctx;
|
||||
};
|
||||
@@ -91,3 +93,49 @@ deleteRoute.run = async (ctx) => {
|
||||
return ctx;
|
||||
};
|
||||
deleteRoute.addTo(app);
|
||||
|
||||
const publish = app.route({
|
||||
path: 'container',
|
||||
key: 'publish',
|
||||
});
|
||||
publish.nextRoute = { path: 'resource', key: 'publishContainer' };
|
||||
|
||||
publish
|
||||
.define(async (ctx) => {
|
||||
const { data } = ctx.query;
|
||||
const { id, publish, type = 'patch', beta = false } = data;
|
||||
type PublishType = 'patch' | 'minor' | 'major';
|
||||
if (!id) {
|
||||
throw new CustomError('id is required');
|
||||
}
|
||||
const container = await ContainerModel.findByPk(id);
|
||||
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;
|
||||
}
|
||||
if (ctx.state) {
|
||||
ctx.state.container = container;
|
||||
} else {
|
||||
ctx.state = {
|
||||
container,
|
||||
};
|
||||
}
|
||||
// 执行下一步操作了
|
||||
ctx.body = 'run ok';
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
Reference in New Issue
Block a user