暂存
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);
|
||||
|
||||
@@ -7,16 +7,14 @@ export interface ContainerData {
|
||||
showChild?: boolean;
|
||||
shadowRoot?: boolean;
|
||||
}
|
||||
export type Container = {
|
||||
id?: string;
|
||||
title?: string;
|
||||
export type ContainerPublish = {
|
||||
rid?: string; // resource id
|
||||
name?: string;
|
||||
description?: string;
|
||||
type?: string;
|
||||
code?: string;
|
||||
source?: string;
|
||||
sourceType?: string;
|
||||
data?: ContainerData;
|
||||
version?: string;
|
||||
};
|
||||
export type Container = Partial<InstanceType<typeof ContainerModel>>;
|
||||
|
||||
export class ContainerModel extends Model {
|
||||
declare id: string;
|
||||
declare title: string;
|
||||
@@ -26,6 +24,12 @@ export class ContainerModel extends Model {
|
||||
declare source: string;
|
||||
declare sourceType: string;
|
||||
declare data: ContainerData;
|
||||
declare publish: ContainerPublish;
|
||||
declare uid: string;
|
||||
|
||||
// timestamps
|
||||
public readonly createdAt!: Date;
|
||||
public readonly updatedAt!: Date;
|
||||
}
|
||||
ContainerModel.init(
|
||||
{
|
||||
@@ -63,6 +67,11 @@ ContainerModel.init(
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: {},
|
||||
},
|
||||
publish: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: {},
|
||||
},
|
||||
|
||||
uid: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: true,
|
||||
|
||||
Reference in New Issue
Block a user