midway-fatcms 0.0.1-beta.3 → 0.0.1-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -134,13 +134,13 @@ exports.default = (appInfo) => {
|
|
|
134
134
|
// 使用浏览器插件配置header信息:插件名:ModHeader - Modify HTTP headers
|
|
135
135
|
// 默认值:配置key:fatcmsdebug, 配置value: headerSecret的值
|
|
136
136
|
fatcmsDebug: {
|
|
137
|
-
headerKey: '
|
|
138
|
-
headerSecret: '
|
|
137
|
+
headerKey: 'fatcmsDebug',
|
|
138
|
+
headerSecret: '111',
|
|
139
139
|
},
|
|
140
140
|
// 是否开启SA账号。只有账号密码没有用,必须通过ModHeader插件设置如下字段
|
|
141
141
|
fatcmsSAEnable: {
|
|
142
|
-
headerKey: '
|
|
143
|
-
headerSecret: '
|
|
142
|
+
headerKey: 'fatcmsSAEnable',
|
|
143
|
+
headerSecret: '222',
|
|
144
144
|
},
|
|
145
145
|
// 是否启用内置的定时任务
|
|
146
146
|
fatcmsScheduleService: true,
|
|
@@ -11,6 +11,9 @@ interface HttpGetRes {
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class StaticController extends BaseApiController {
|
|
13
13
|
protected ctx: Context;
|
|
14
|
+
constructor();
|
|
15
|
+
private getLocalPaths;
|
|
16
|
+
private initNotFoundList;
|
|
14
17
|
private responseLocalFile;
|
|
15
18
|
proxyStaticFile(ossName: string, relativePath: string): Promise<string>;
|
|
16
19
|
saveNotFoundList(): Promise<void>;
|
|
@@ -20,17 +20,17 @@ const fs2 = require("fs");
|
|
|
20
20
|
const path = require("path");
|
|
21
21
|
const https = require("https");
|
|
22
22
|
const functions_1 = require("../../libs/utils/functions");
|
|
23
|
-
const localDir = path.join(__dirname, '../../../public/static'); // 本地文件存储目录
|
|
24
|
-
const notFoundListFile = path.join(localDir, '__404__list.json'); // 404列表文件
|
|
25
23
|
function getPathConfig(ossName) {
|
|
26
24
|
const remoteBaseUrlMap = {
|
|
27
25
|
"cdnjsx": 'https://cdnjsx.oss-cn-shanghai.aliyuncs.com',
|
|
28
26
|
"i.alicdn.com": "https://i.alicdn.com",
|
|
29
27
|
"img.alicdn.com": "https://img.alicdn.com",
|
|
28
|
+
"at.alicdn.com": "https://at.alicdn.com",
|
|
30
29
|
};
|
|
31
|
-
|
|
30
|
+
let remoteBaseUrl = remoteBaseUrlMap[ossName];
|
|
32
31
|
if (!remoteBaseUrl) {
|
|
33
|
-
|
|
32
|
+
console.error(`getPathConfig ossName: ${ossName} 未配置`);
|
|
33
|
+
remoteBaseUrl = `https://${ossName}`;
|
|
34
34
|
}
|
|
35
35
|
return {
|
|
36
36
|
remoteBaseUrl,
|
|
@@ -38,26 +38,43 @@ function getPathConfig(ossName) {
|
|
|
38
38
|
}
|
|
39
39
|
// 404列表缓存
|
|
40
40
|
let notFoundList = new Set();
|
|
41
|
-
|
|
42
|
-
async function init() {
|
|
43
|
-
try {
|
|
44
|
-
// 确保本地存储目录存在
|
|
45
|
-
await fs.mkdir(localDir, { recursive: true });
|
|
46
|
-
const data = await fs.readFile(notFoundListFile, 'utf8');
|
|
47
|
-
notFoundList = new Set(JSON.parse(data));
|
|
48
|
-
console.log(`已加载${notFoundList.size}个404记录`);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
if (error.code !== 'ENOENT') {
|
|
52
|
-
console.error('读取404列表失败:', error);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
init();
|
|
41
|
+
let notFoundListIsInit = false;
|
|
57
42
|
/**
|
|
58
43
|
* 静态文件代理功能
|
|
59
44
|
*/
|
|
60
45
|
let StaticController = class StaticController extends BaseApiController_1.BaseApiController {
|
|
46
|
+
constructor() {
|
|
47
|
+
super();
|
|
48
|
+
this.initNotFoundList();
|
|
49
|
+
}
|
|
50
|
+
getLocalPaths() {
|
|
51
|
+
const appDir = this.app.getAppDir();
|
|
52
|
+
const localDir = path.join(appDir, './public/static'); // 本地文件存储目录
|
|
53
|
+
const notFoundListFile = path.join(localDir, '__404__list.json'); // 404列表文件
|
|
54
|
+
return {
|
|
55
|
+
localDir,
|
|
56
|
+
notFoundListFile
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async initNotFoundList() {
|
|
60
|
+
if (notFoundListIsInit) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
notFoundListIsInit = true;
|
|
64
|
+
const { localDir, notFoundListFile } = this.getLocalPaths();
|
|
65
|
+
try {
|
|
66
|
+
// 确保本地存储目录存在
|
|
67
|
+
await fs.mkdir(localDir, { recursive: true });
|
|
68
|
+
const data = await fs.readFile(notFoundListFile, 'utf8');
|
|
69
|
+
notFoundList = new Set(JSON.parse(data));
|
|
70
|
+
console.log(`已加载${notFoundList.size}个404记录`);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error.code !== 'ENOENT') {
|
|
74
|
+
console.error('读取404列表失败:', error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
61
78
|
async responseLocalFile(localFilePath, localHeaderPath, relativePath) {
|
|
62
79
|
const headers = {
|
|
63
80
|
"Cache-Control": 'public, max-age=31536000',
|
|
@@ -107,6 +124,7 @@ let StaticController = class StaticController extends BaseApiController_1.BaseAp
|
|
|
107
124
|
return false;
|
|
108
125
|
}
|
|
109
126
|
async proxyStaticFile(ossName, relativePath) {
|
|
127
|
+
const { localDir } = this.getLocalPaths();
|
|
110
128
|
const PATH_CONFIG = getPathConfig(ossName);
|
|
111
129
|
// 构建本地路径和远程路径
|
|
112
130
|
const localFilePath = path.join(localDir, ossName, "files", relativePath);
|
|
@@ -161,6 +179,7 @@ let StaticController = class StaticController extends BaseApiController_1.BaseAp
|
|
|
161
179
|
}
|
|
162
180
|
// 保存404列表
|
|
163
181
|
async saveNotFoundList() {
|
|
182
|
+
const { notFoundListFile } = this.getLocalPaths();
|
|
164
183
|
try {
|
|
165
184
|
// 确保存储404列表的目录存在
|
|
166
185
|
const dir = path.dirname(notFoundListFile);
|
|
@@ -260,6 +279,7 @@ __decorate([
|
|
|
260
279
|
__metadata("design:returntype", Promise)
|
|
261
280
|
], StaticController.prototype, "proxyStaticFile", null);
|
|
262
281
|
StaticController = __decorate([
|
|
263
|
-
(0, core_1.Controller)('/ns/static')
|
|
282
|
+
(0, core_1.Controller)('/ns/static'),
|
|
283
|
+
__metadata("design:paramtypes", [])
|
|
264
284
|
], StaticController);
|
|
265
285
|
exports.StaticController = StaticController;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { All, Controller, Inject, Param } from '@midwayjs/core';
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
3
|
import { BaseApiController } from '../base/BaseApiController';
|
|
4
|
+
import * as _ from 'lodash';
|
|
4
5
|
import * as fs from 'fs/promises';
|
|
5
6
|
import * as fs2 from 'fs';
|
|
6
7
|
import * as path from 'path';
|
|
@@ -15,19 +16,18 @@ interface HttpGetRes {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
const localDir = path.join(__dirname, '../../../public/static'); // 本地文件存储目录
|
|
19
|
-
const notFoundListFile = path.join(localDir, '__404__list.json') // 404列表文件
|
|
20
|
-
|
|
21
19
|
|
|
22
20
|
function getPathConfig(ossName: string) {
|
|
23
21
|
const remoteBaseUrlMap = {
|
|
24
22
|
"cdnjsx": 'https://cdnjsx.oss-cn-shanghai.aliyuncs.com',
|
|
25
|
-
"i.alicdn.com":"https://i.alicdn.com",
|
|
26
|
-
"img.alicdn.com":"https://img.alicdn.com",
|
|
23
|
+
"i.alicdn.com": "https://i.alicdn.com",
|
|
24
|
+
"img.alicdn.com": "https://img.alicdn.com",
|
|
25
|
+
"at.alicdn.com": "https://at.alicdn.com",
|
|
27
26
|
};
|
|
28
|
-
|
|
27
|
+
let remoteBaseUrl = remoteBaseUrlMap[ossName];
|
|
29
28
|
if (!remoteBaseUrl) {
|
|
30
|
-
|
|
29
|
+
console.error(`getPathConfig ossName: ${ossName} 未配置`);
|
|
30
|
+
remoteBaseUrl = `https://${ossName}`
|
|
31
31
|
}
|
|
32
32
|
return {
|
|
33
33
|
remoteBaseUrl,
|
|
@@ -35,28 +35,13 @@ function getPathConfig(ossName: string) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
// 404列表缓存
|
|
39
|
-
let notFoundList = new Set();
|
|
40
|
-
|
|
41
38
|
|
|
42
|
-
// 初始化:加载404列表
|
|
43
|
-
async function init() {
|
|
44
|
-
try {
|
|
45
|
-
// 确保本地存储目录存在
|
|
46
|
-
await fs.mkdir(localDir, { recursive: true });
|
|
47
|
-
const data = await fs.readFile(notFoundListFile, 'utf8');
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (error.code !== 'ENOENT') {
|
|
53
|
-
console.error('读取404列表失败:', error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
40
|
+
// 404列表缓存
|
|
41
|
+
let notFoundList = new Set();
|
|
42
|
+
let notFoundListIsInit = false;
|
|
57
43
|
|
|
58
44
|
|
|
59
|
-
init();
|
|
60
45
|
|
|
61
46
|
/**
|
|
62
47
|
* 静态文件代理功能
|
|
@@ -66,6 +51,44 @@ export class StaticController extends BaseApiController {
|
|
|
66
51
|
@Inject()
|
|
67
52
|
protected ctx: Context;
|
|
68
53
|
|
|
54
|
+
constructor() {
|
|
55
|
+
super();
|
|
56
|
+
this.initNotFoundList();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
private getLocalPaths(): any {
|
|
61
|
+
const appDir = this.app.getAppDir();
|
|
62
|
+
const localDir = path.join(appDir, './public/static'); // 本地文件存储目录
|
|
63
|
+
const notFoundListFile = path.join(localDir, '__404__list.json') // 404列表文件
|
|
64
|
+
return {
|
|
65
|
+
localDir,
|
|
66
|
+
notFoundListFile
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
private async initNotFoundList() {
|
|
72
|
+
if (notFoundListIsInit) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
notFoundListIsInit = true;
|
|
76
|
+
|
|
77
|
+
const { localDir, notFoundListFile } = this.getLocalPaths();
|
|
78
|
+
try {
|
|
79
|
+
// 确保本地存储目录存在
|
|
80
|
+
await fs.mkdir(localDir, { recursive: true });
|
|
81
|
+
const data = await fs.readFile(notFoundListFile, 'utf8');
|
|
82
|
+
|
|
83
|
+
notFoundList = new Set(JSON.parse(data));
|
|
84
|
+
console.log(`已加载${notFoundList.size}个404记录`);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error.code !== 'ENOENT') {
|
|
87
|
+
console.error('读取404列表失败:', error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
69
92
|
private async responseLocalFile(localFilePath: string, localHeaderPath: string, relativePath: string): Promise<boolean> {
|
|
70
93
|
|
|
71
94
|
const headers = {
|
|
@@ -128,6 +151,7 @@ export class StaticController extends BaseApiController {
|
|
|
128
151
|
@All('/:ossName/:relativePath+')
|
|
129
152
|
async proxyStaticFile(@Param('ossName') ossName: string, @Param('relativePath') relativePath: string) {
|
|
130
153
|
|
|
154
|
+
const { localDir } = this.getLocalPaths();
|
|
131
155
|
const PATH_CONFIG = getPathConfig(ossName);
|
|
132
156
|
|
|
133
157
|
|
|
@@ -195,6 +219,7 @@ export class StaticController extends BaseApiController {
|
|
|
195
219
|
|
|
196
220
|
// 保存404列表
|
|
197
221
|
async saveNotFoundList() {
|
|
222
|
+
const { notFoundListFile } = this.getLocalPaths();
|
|
198
223
|
try {
|
|
199
224
|
// 确保存储404列表的目录存在
|
|
200
225
|
const dir = path.dirname(notFoundListFile);
|