feat: add demo user and fix __dirname and fix cdn for panel upload

This commit is contained in:
2024-10-09 18:10:21 +08:00
parent 03c473d24a
commit 44d8a831c2
6 changed files with 31 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ import { bucketName } from '@/modules/minio.ts';
import { getContentType } from '@/utils/get-content-type.ts';
import archiver from 'archiver';
import { CustomError } from '@abearxiong/router';
import { nanoid } from 'nanoid';
export const cacheFile = useFileStore('cache-file', {
needExists: true,
@@ -44,21 +45,22 @@ export const getDeck = async (page: PageModel) => {
export const cachePage = async (page: PageModel, opts: { tokenUser: any; key; version }) => {
const _result = await getDeck(page);
const result = getContainerData(_result);
const html = getHTML({ rootId: page.id, title: page?.publish?.key });
const key = 'data-' + nanoid(6);
const html = getHTML({ rootId: page.id, title: page?.publish?.key, dataKey: key });
const dataJs = getDataJs(result);
const htmlPath = path.resolve(cacheFile, `${page.id}.html`);
const dataJsPath = path.resolve(cacheFile, `${page.id}.js`);
fs.writeFileSync(htmlPath, html);
fs.writeFileSync(dataJsPath, dataJs);
const minioHTML = await uploadMinio({ ...opts, path: `index.html`, filePath: htmlPath });
const minioData = await uploadMinio({ ...opts, path: `data.js`, filePath: dataJsPath });
const minioData = await uploadMinio({ ...opts, path: `${key || 'data'}.js`, filePath: dataJsPath });
return [
{
name: 'index.html',
path: minioHTML,
},
{
name: 'data.js',
name: `${key || 'data'}.js`,
path: minioData,
},
];
@@ -135,7 +137,7 @@ export const getZip = async (page: PageModel, opts: { tokenUser: any }) => {
// 添加 JavaScript 字符串作为文件到 zip 中
zip.append(dataJs, { name: 'data.js' });
zip.append(JSON.stringify(page), { name: 'app.config.json5' });
// 可以继续添加更多内容,文件或目录等
// zip.append('Another content', { name: 'other.txt' });

View File

@@ -1,6 +1,7 @@
type HTMLOptions = {
title?: string;
rootId: string;
dataKey?: string;
};
export const getHTML = (opts: HTMLOptions) => {
return `<!DOCTYPE html>
@@ -29,7 +30,7 @@ export const getHTML = (opts: HTMLOptions) => {
<div id="root"></div>
<script type="module">
import { Container } from 'https://kevisual.xiongxiao.me/root/container/index.js'
import { data } from './data.js'
import { data } from './${opts.dataKey || 'data'}.js'
const container = new Container({
root: 'root',
data: data