Skip to content

Commit f06b3af

Browse files
committed
feat: 优化部分代码
1 parent 1cc6dfb commit f06b3af

File tree

7 files changed

+30
-60
lines changed

7 files changed

+30
-60
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# 更新日志
22

3+
## 1.3.0
4+
5+
- 优化资源加载方式,大幅度提升加载速度
6+
- 支持 .env 后缀文件
7+
- 修复 IOS 飞牛客户端打开文件传递参数非 / 前缀的问题
8+
39
## 1.2.2
410

511
- 优化 CGI 参数获取代码

app/app/ui/config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"title": "代码编辑器",
55
"icon": "images/icon_{0}.png",
66
"type": "iframe",
7-
"url": "/cgi/ThirdParty/code.editor/index.cgi",
7+
"url": "/cgi/ThirdParty/code.editor/api.cgi/",
88
"allUsers": true,
99
"noDisplay": false,
1010
"fileTypes": [
@@ -35,6 +35,7 @@
3535
"yaml",
3636
"yml",
3737
"vue",
38+
"env",
3839
"cgi"
3940
]
4041
}

app/app/ui/index.cgi

Lines changed: 0 additions & 18 deletions
This file was deleted.

backend/src/cgi.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ const exec = require("./utils/exec");
66
async function getData() {
77
const env = process.env;
88

9+
const assets = env.PATH_INFO.replace(
10+
"/cgi/ThirdParty/code.editor/api.cgi",
11+
""
12+
);
13+
14+
if (assets) {
15+
const path = assets === "/" ? "/index.html" : assets;
16+
17+
return {
18+
api: "assets",
19+
query: { path: `/var/apps/code.editor/target/server/dist${path}` },
20+
body: {},
21+
};
22+
}
23+
924
const result = {
1025
api: env.HTTP_API_PATH || "",
1126
query: querystring.parse(env.QUERY_STRING || ""),
@@ -58,9 +73,6 @@ async function main() {
5873
if (type) {
5974
console.log(`Content-Type: ${type}`);
6075
console.log(`Content-Length: ${body.size}`);
61-
console.log(
62-
`Content-Disposition: attachment; filename="${body.filename}"`
63-
);
6476
console.log("");
6577
body.stream.pipe(process.stdout);
6678
} else {

backend/src/router/read.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const fs = require("fs");
22

33
module.exports = async function read({ query }) {
4-
const { path } = query;
5-
6-
if (!path) {
4+
if (!query.path) {
75
return { code: 400, msg: "缺少文件路径参数", data: query };
86
}
97

8+
const path = query.path[0] === "/" ? query.path : `/${query.path}`;
9+
1010
try {
1111
if (!fs.existsSync(path)) {
1212
return { code: 404, msg: "文件不存在", data: query };

backend/src/utils/exec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const getType = require("./type");
22

33
const router = {
4+
assets: { type: "file", run: require("../router/read") },
45
read: { type: "file", run: require("../router/read") },
56
save: { run: require("../router/save") },
67
};

frontend/vite.config.ts

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,14 @@ import AutoImport from 'unplugin-auto-import/vite'
1010
import Components from 'unplugin-vue-components/vite'
1111
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
1212

13-
// 这里是服务器的地址
14-
const CGI_PATH = '/cgi/ThirdParty/code.editor/api.cgi'
15-
const FILE_PATH = '_api=read&path=/var/apps/code.editor/target/server/dist'
13+
const CGI_PATH = '/cgi/ThirdParty/code.editor/api.cgi/'
1614

1715
export default defineConfig({
16+
base: CGI_PATH,
17+
1818
build: {
1919
outDir: path.join(__dirname, '../app/app/server/dist'),
2020
emptyOutDir: true,
21-
22-
rollupOptions: {
23-
output: {
24-
manualChunks: undefined,
25-
inlineDynamicImports: true,
26-
},
27-
},
2821
},
2922

3023
plugins: [
@@ -38,31 +31,6 @@ export default defineConfig({
3831
Components({
3932
resolvers: [ElementPlusResolver()],
4033
}),
41-
42-
process.env.NODE_ENV === 'development'
43-
? undefined
44-
: {
45-
name: 'replace-file-loader',
46-
transformIndexHtml(html) {
47-
return html.replace(/(src|href)="([^"]*\.(js|css|ico))"/g, (match, attr, path) => {
48-
return `${attr}="${CGI_PATH}?${FILE_PATH}${path}"`
49-
})
50-
},
51-
generateBundle(_, bundle) {
52-
Object.keys(bundle).forEach((fileName) => {
53-
const chunk = bundle[fileName] as any
54-
55-
if (fileName.endsWith('.css')) {
56-
chunk.source = chunk.source.replace(
57-
/url\(\s*['"]?(\/assets\/[^'")]*)['"]?\s*\)/g,
58-
(match: string, path: string) => {
59-
return match.replace(path, `${CGI_PATH}?${FILE_PATH}${path}`)
60-
},
61-
)
62-
}
63-
})
64-
},
65-
},
6634
],
6735

6836
resolve: {

0 commit comments

Comments
 (0)