diff --git a/package.json b/package.json index 76e6d17..cb4ba25 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "docker:build:gitea": "docker build -t git.xiongxiao.me/abearxiong/code-flow:v0.0.2 .", "docker:push:gitea": "docker push git.xiongxiao.me/abearxiong/code-flow:v0.0.2", "dts": "./node_modules/.bin/dts-bundle-generator -o types/index.d.ts src/type.ts", - "postinstall2": "patch-package" + "postinstall2": "patch-package", + "pub": "npm run build && npm run deploy && npm run reload" }, "keywords": [], "types": "types/index.d.ts", diff --git a/src/lib/dynamic-import.ts b/src/lib/dynamic-import.ts index 345bfe2..37f7dd7 100644 --- a/src/lib/dynamic-import.ts +++ b/src/lib/dynamic-import.ts @@ -1,8 +1,11 @@ -import path from 'path'; +import path, { dirname } from 'path'; +import { fileURLToPath } from 'url'; export const getRequire = () => { return eval('require') as NodeRequire; }; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); export const directoryPath = path.resolve(__dirname); export const defaultImportModules = [ diff --git a/src/models/user.ts b/src/models/user.ts index f173cbc..48af790 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -190,5 +190,18 @@ export const initializeUser = async () => { console.info('new Users id', root.id, org.id); } }; - +export const CreateDemoUser = async () => { + const w = await User.findAndCountAll({ + logging: false, + }); + console.info('[User count]', w.count); + const username = 'dmeo'; + const u = await User.findOne({ where: { username }, logging: false }); + if (!u) { + const user = await User.createUser(username, '', 'demo'); + console.info('new Users name', user.username); + } else { + console.info('Users has been created', u.username); + } +}; // initializeUser(); diff --git a/src/routes/page/module/cache-file.ts b/src/routes/page/module/cache-file.ts index 99de843..05fc9f5 100644 --- a/src/routes/page/module/cache-file.ts +++ b/src/routes/page/module/cache-file.ts @@ -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' }); diff --git a/src/routes/page/module/file-template.ts b/src/routes/page/module/file-template.ts index 5ee76dd..770d956 100644 --- a/src/routes/page/module/file-template.ts +++ b/src/routes/page/module/file-template.ts @@ -1,6 +1,7 @@ type HTMLOptions = { title?: string; rootId: string; + dataKey?: string; }; export const getHTML = (opts: HTMLOptions) => { return ` @@ -29,7 +30,7 @@ export const getHTML = (opts: HTMLOptions) => {