feat: add demo user and fix __dirname and fix cdn for panel upload
This commit is contained in:
parent
03c473d24a
commit
44d8a831c2
@ -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",
|
||||
|
@ -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 = [
|
||||
|
@ -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();
|
||||
|
@ -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' });
|
||||
|
||||
|
@ -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
|
||||
|
3
src/scripts/add-demo-user.ts
Normal file
3
src/scripts/add-demo-user.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { CreateDemoUser } from '@/models/user.ts';
|
||||
|
||||
await CreateDemoUser();
|
Loading…
x
Reference in New Issue
Block a user