diff --git a/src/routes/app-manager/list.ts b/src/routes/app-manager/list.ts index d985cc7..5507135 100644 --- a/src/routes/app-manager/list.ts +++ b/src/routes/app-manager/list.ts @@ -66,6 +66,7 @@ app const newData = { ...app.data, ...data }; const newApp = await app.update({ data: newData, ...rest }); ctx.body = newApp; + setExpire(newApp.id, tokenUser.username); } else { throw new CustomError('app not found'); } @@ -177,7 +178,7 @@ app const dataFiles = app.data.files || []; const newFiles = _.uniqBy([...dataFiles, ...files], 'name'); const res = await app.update({ data: { ...app.data, files: newFiles } }); - + setExpire(app.id, 'test'); ctx.body = prefixFix(res, tokenUser.username); } catch (e) { console.log('update error', e); diff --git a/src/routes/app-manager/module/app-list.ts b/src/routes/app-manager/module/app-list.ts index e32ebe9..f24f53a 100644 --- a/src/routes/app-manager/module/app-list.ts +++ b/src/routes/app-manager/module/app-list.ts @@ -5,7 +5,7 @@ import { AppData, AppType, AppStatus } from './app.ts'; export type AppList = Partial>; /** - * APP List 管理 + * APP List 管理 历史版本管理 */ export class AppListModel extends Model { declare id: string; diff --git a/src/routes/container/list.ts b/src/routes/container/list.ts index ebb2675..9c71dfd 100644 --- a/src/routes/container/list.ts +++ b/src/routes/container/list.ts @@ -46,28 +46,28 @@ const add = app.route({ add.run = async (ctx) => { const tokenUser = ctx.state.tokenUser; const data = ctx.query.data; - - const _data: Container = { - title: '', - description: '', - code: '', - type: '', - }; const container = { - ..._data, ...data, }; let containerModel: any = null; if (container.id) { containerModel = await ContainerModel.findByPk(container.id); if (containerModel) { - containerModel.update(container); - await containerModel.save(); - ctx.emit?.('pageEdit', { - source: 'container', - data: containerModel.toJSON(), - operation: 'edit', + containerModel.update({ + ...container, + publish: { + ...containerModel.publish, + ...container.publish, + }, }); + await containerModel.save(); + if (containerModel.code || containerModel.source || containerModel.sourceType) { + ctx.emit?.('pageEdit', { + source: 'container', + data: containerModel.toJSON(), + operation: 'edit', + }); + } } } else { try { @@ -123,7 +123,7 @@ app } container.publish = publish; await container.save(); - const { title, description, key, version, fileName } = publish; + const { title, description, key, version, fileName, saveHTML } = publish; ctx.body = container; if (!key || !version || !fileName) { return; @@ -134,6 +134,7 @@ app version: version, code: container.code, filePath: fileName, + saveHTML }); await ctx.call({ path: 'app', @@ -143,7 +144,7 @@ app data: { appKey: key, version, - files: [uploadResult], + files: uploadResult, }, }, }); diff --git a/src/routes/page/module/cache-file.ts b/src/routes/page/module/cache-file.ts index 52c10ad..185b662 100644 --- a/src/routes/page/module/cache-file.ts +++ b/src/routes/page/module/cache-file.ts @@ -5,7 +5,7 @@ import { Op } from 'sequelize'; import { getContainerData } from './get-container.ts'; import path from 'path'; import fs from 'fs'; -import { getHTML, getDataJs } from './file-template.ts'; +import { getHTML, getDataJs, getOneHTML } from './file-template.ts'; import { minioClient } from '@/app.ts'; import { bucketName } from '@/modules/minio.ts'; import { getContentType } from '@/utils/get-content-type.ts'; @@ -65,24 +65,43 @@ export const cachePage = async (page: PageModel, opts: { tokenUser: any; key; ve }, ]; }; -export const uploadMinioContainer = async ({ tokenUser, key, version, code, filePath }) => { +export const uploadMinioContainer = async ({ tokenUser, key, version, code, filePath, saveHTML }) => { if ((filePath as string).includes('..')) { throw new CustomError('file path is invalid'); } + const uploadFiles = []; const minioKeyVersion = `${tokenUser.username}/${key}/${version}`; const minioPath = path.join(minioKeyVersion, filePath); + const minioFileName = path.basename(minioPath); + if (!minioFileName.endsWith('.js')) { + saveHTML = false; + } console.log('minioPath', minioPath); // const isHTML = filePath.endsWith('.html'); const name = minioPath.replace(minioKeyVersion + '/', ''); await minioClient.putObject(bucketName, minioPath, code, code.length, { 'Content-Type': getContentType(filePath), 'app-source': 'user-app', - 'Cache-Control': 'no-cache', // 缓存一年 + 'Cache-Control': 'no-cache', // no-cache }); - return { + uploadFiles.push({ name, path: minioPath, - }; + }); + if (saveHTML) { + const htmlPath = minioPath.replace('.js', '.html'); + const code = getOneHTML({ title: 'Kevisual', file: minioFileName.replace('.js', '') }); + await minioClient.putObject(bucketName, htmlPath, code, code.length, { + 'Content-Type': 'text/html', + 'app-source': 'user-app', + 'Cache-Control': 'max-age=31536000, immutable', + }); + uploadFiles.push({ + name: 'index.html', + path: htmlPath, + }); + } + return uploadFiles; }; export const uploadMinio = async ({ tokenUser, key, version, path, filePath }) => { const minioPath = `${tokenUser.username}/${key}/${version}/${path}`; diff --git a/src/routes/page/module/file-template.ts b/src/routes/page/module/file-template.ts index 770d956..b353863 100644 --- a/src/routes/page/module/file-template.ts +++ b/src/routes/page/module/file-template.ts @@ -3,6 +3,11 @@ type HTMLOptions = { rootId: string; dataKey?: string; }; +/** + * data list + * @param opts + * @returns + */ export const getHTML = (opts: HTMLOptions) => { return ` @@ -45,3 +50,51 @@ export const getHTML = (opts: HTMLOptions) => { export const getDataJs = (result: any) => { return 'export const data=' + JSON.stringify(result); }; + +type OneHTMLOptions = { + title?: string; + file: string; +} +/** + * one data + * @param opts + * @returns + */ +export const getOneHTML = (opts: OneHTMLOptions) => { + return ` + + + + + + ${opts.title || 'Kevisual'} + + + + +
+ + + +`; +};