update new way

This commit is contained in:
2024-11-17 01:35:05 +08:00
parent 7ec8a001de
commit dc69b95f39
13 changed files with 463 additions and 1030 deletions

View File

@@ -1,7 +1,6 @@
import { CustomError } from '@kevisual/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',
@@ -49,7 +48,7 @@ add.run = async (ctx) => {
const container = {
...data,
};
let containerModel: any = null;
let containerModel: ContainerModel | null = null;
if (container.id) {
containerModel = await ContainerModel.findByPk(container.id);
if (containerModel) {
@@ -134,7 +133,7 @@ app
version: version,
code: container.code,
filePath: fileName,
saveHTML
saveHTML,
});
await ctx.call({
path: 'app',

View File

@@ -1,9 +1,9 @@
import { sequelize } from '../../../modules/sequelize.ts';
import { DataTypes, Model } from 'sequelize';
import crypto from 'crypto';
export interface ContainerData {}
export type ContainerPublish = {
key: string;
key: string;
title?: string;
description?: string;
fileName?: string;
@@ -21,11 +21,20 @@ export class ContainerModel extends Model {
declare type: string;
declare tags: string[];
declare code: string;
declare hash: string;
declare source: string;
declare sourceType: string;
declare data: ContainerData;
declare publish: ContainerPublish;
declare uid: string;
declare updatedAt: Date;
declare createdAt: Date;
createHash() {
const { code } = this;
const hash = crypto.createHash('md5');
hash.update(code);
this.hash = hash.digest('hex');
}
}
ContainerModel.init(
{
@@ -55,6 +64,10 @@ ContainerModel.init(
type: DataTypes.TEXT,
defaultValue: '',
},
hash: {
type: DataTypes.TEXT,
defaultValue: '',
},
source: {
type: DataTypes.STRING,
defaultValue: '',

View File

@@ -0,0 +1,11 @@
import { ContainerModel } from '../models/index.ts';
export const getContainerById = async (id: string) => {
const container = await ContainerModel.findByPk(id);
const code = container?.code;
return {
code,
id: container?.id,
updatedAt: new Date(container?.updatedAt).getTime(),
};
};