midway-fatcms 0.0.1-beta.2 → 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: 'euhvfvv5sDt19dNoerVFamhNYlLJ8ZDDYcRZhMJWNRxALxtrxLPqJSks9sRZEpKY',
138
- headerSecret: 'IlddQO1fO8X7KSwnF3KazNaNHK05Y0kYaD+1z3yGlfZpz0+aAF5hDzf7KQk2dyx0',
137
+ headerKey: 'fatcmsDebug',
138
+ headerSecret: '111',
139
139
  },
140
140
  // 是否开启SA账号。只有账号密码没有用,必须通过ModHeader插件设置如下字段
141
141
  fatcmsSAEnable: {
142
- headerKey: 'WyuX2jf8hehgXAjV5Bf22hvbK/KTEiHCM8eiQeI0FETm/UFXkcLnn3GSTUfwVrrE',
143
- headerSecret: 'lzt19Ef6HxSqg2rp6Q1M3YT+uMrTecmAm3cX1mwFZGqoXknwWdj5fTJil1Vr9AeHDIUFuOOxrU1kSSVa6h/Ppw==',
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
- const remoteBaseUrl = remoteBaseUrlMap[ossName];
30
+ let remoteBaseUrl = remoteBaseUrlMap[ossName];
32
31
  if (!remoteBaseUrl) {
33
- throw new Error(`ossName: ${ossName} 未配置`);
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
- // 初始化:加载404列表
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;
@@ -0,0 +1,31 @@
1
+ <html dir="ltr" lang="zh">
2
+ <head>
3
+ <meta charset="utf-8">
4
+ <meta name="color-scheme" content="light dark">
5
+ <meta name="theme-color" content="#fff">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
7
+ <title>无法访问此应用</title>
8
+ <link rel="stylesheet" href="https://cdnjsx.oss-cn-shanghai.aliyuncs.com/styles/chrome-error.css">
9
+ </head>
10
+ <body class="neterror" style="font-family: system-ui,PingFang SC,STHeiti,sans-serif; font-size: 75%">
11
+
12
+ <div id="content">
13
+ <div id="main-frame-error" class="interstitial-wrapper ">
14
+ <div id="main-content">
15
+ <div class="icon icon-generic"></div>
16
+ <div id="main-message">
17
+ <h1><span>无法访问此应用</span></h1>
18
+ <p>此应用存在如下可能的状态导致无法访问:应用不存在、应用已下线、站点不支持</p>
19
+ <p>appCode: <%=appCode%></p>
20
+ <div>
21
+ <p>errorMsg: <%=errorMsg%></p>
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ </div>
27
+
28
+ </body>
29
+ </html>
30
+
31
+
@@ -0,0 +1,34 @@
1
+ <html dir="ltr" lang="zh">
2
+ <head>
3
+ <meta charset="utf-8">
4
+ <meta name="color-scheme" content="light dark">
5
+ <meta name="theme-color" content="#fff">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
7
+ <title>无法访问此网站</title>
8
+ <link rel="stylesheet" href="https://cdnjsx.oss-cn-shanghai.aliyuncs.com/styles/chrome-error.css">
9
+ </head>
10
+ <body class="neterror" style="font-family: system-ui,PingFang SC,STHeiti,sans-serif; font-size: 75%">
11
+
12
+ <div id="content">
13
+ <div id="main-frame-error" class="interstitial-wrapper ">
14
+ <div id="main-content">
15
+ <div class="icon icon-generic"></div>
16
+ <div id="main-message">
17
+ <h1>
18
+ <span>无法访问此网站</span>
19
+ </h1>
20
+ <p>检查 <span id="domain_span"><%-host%></span> 中是否有拼写错误。</p>
21
+ <div class="error-code" style="text-transform: none;"><%-errorInfo%></div>
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <script>
27
+ setTimeout(function () {
28
+ document.getElementById('domain_span').innerHTML = location.host
29
+ }, 10)
30
+ </script>
31
+ </body>
32
+ </html>
33
+
34
+
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midway-fatcms",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.4",
4
4
  "description": "This is a midway component sample",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -17,8 +17,12 @@
17
17
  "dist/**/*.txt",
18
18
  "dist/**/*.js",
19
19
  "dist/**/*.d.ts",
20
+ "dist/**/*.html",
21
+ "dist/**/*.ico",
20
22
  "src/**/*.ts",
21
23
  "src/**/*.txt",
24
+ "src/**/*.html",
25
+ "src/**/*.ico",
22
26
  "index.d.ts"
23
27
  ],
24
28
  "license": "MIT",
@@ -154,14 +154,14 @@ export default (appInfo: any) => {
154
154
  // 使用浏览器插件配置header信息:插件名:ModHeader - Modify HTTP headers
155
155
  // 默认值:配置key:fatcmsdebug, 配置value: headerSecret的值
156
156
  fatcmsDebug: {
157
- headerKey: 'euhvfvv5sDt19dNoerVFamhNYlLJ8ZDDYcRZhMJWNRxALxtrxLPqJSks9sRZEpKY',
158
- headerSecret: 'IlddQO1fO8X7KSwnF3KazNaNHK05Y0kYaD+1z3yGlfZpz0+aAF5hDzf7KQk2dyx0',
157
+ headerKey: 'fatcmsDebug',
158
+ headerSecret: '111',
159
159
  },
160
160
 
161
161
  // 是否开启SA账号。只有账号密码没有用,必须通过ModHeader插件设置如下字段
162
162
  fatcmsSAEnable: {
163
- headerKey: 'WyuX2jf8hehgXAjV5Bf22hvbK/KTEiHCM8eiQeI0FETm/UFXkcLnn3GSTUfwVrrE',
164
- headerSecret: 'lzt19Ef6HxSqg2rp6Q1M3YT+uMrTecmAm3cX1mwFZGqoXknwWdj5fTJil1Vr9AeHDIUFuOOxrU1kSSVa6h/Ppw==',
163
+ headerKey: 'fatcmsSAEnable',
164
+ headerSecret: '222',
165
165
  },
166
166
 
167
167
  // 是否启用内置的定时任务
@@ -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
- const remoteBaseUrl = remoteBaseUrlMap[ossName];
27
+ let remoteBaseUrl = remoteBaseUrlMap[ossName];
29
28
  if (!remoteBaseUrl) {
30
- throw new Error(`ossName: ${ossName} 未配置`);
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
- notFoundList = new Set(JSON.parse(data));
50
- console.log(`已加载${notFoundList.size}个404记录`);
51
- } catch (error) {
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);
@@ -0,0 +1,31 @@
1
+ <html dir="ltr" lang="zh">
2
+ <head>
3
+ <meta charset="utf-8">
4
+ <meta name="color-scheme" content="light dark">
5
+ <meta name="theme-color" content="#fff">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
7
+ <title>无法访问此应用</title>
8
+ <link rel="stylesheet" href="https://cdnjsx.oss-cn-shanghai.aliyuncs.com/styles/chrome-error.css">
9
+ </head>
10
+ <body class="neterror" style="font-family: system-ui,PingFang SC,STHeiti,sans-serif; font-size: 75%">
11
+
12
+ <div id="content">
13
+ <div id="main-frame-error" class="interstitial-wrapper ">
14
+ <div id="main-content">
15
+ <div class="icon icon-generic"></div>
16
+ <div id="main-message">
17
+ <h1><span>无法访问此应用</span></h1>
18
+ <p>此应用存在如下可能的状态导致无法访问:应用不存在、应用已下线、站点不支持</p>
19
+ <p>appCode: <%=appCode%></p>
20
+ <div>
21
+ <p>errorMsg: <%=errorMsg%></p>
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ </div>
27
+
28
+ </body>
29
+ </html>
30
+
31
+
@@ -0,0 +1,34 @@
1
+ <html dir="ltr" lang="zh">
2
+ <head>
3
+ <meta charset="utf-8">
4
+ <meta name="color-scheme" content="light dark">
5
+ <meta name="theme-color" content="#fff">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
7
+ <title>无法访问此网站</title>
8
+ <link rel="stylesheet" href="https://cdnjsx.oss-cn-shanghai.aliyuncs.com/styles/chrome-error.css">
9
+ </head>
10
+ <body class="neterror" style="font-family: system-ui,PingFang SC,STHeiti,sans-serif; font-size: 75%">
11
+
12
+ <div id="content">
13
+ <div id="main-frame-error" class="interstitial-wrapper ">
14
+ <div id="main-content">
15
+ <div class="icon icon-generic"></div>
16
+ <div id="main-message">
17
+ <h1>
18
+ <span>无法访问此网站</span>
19
+ </h1>
20
+ <p>检查 <span id="domain_span"><%-host%></span> 中是否有拼写错误。</p>
21
+ <div class="error-code" style="text-transform: none;"><%-errorInfo%></div>
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <script>
27
+ setTimeout(function () {
28
+ document.getElementById('domain_span').innerHTML = location.host
29
+ }, 10)
30
+ </script>
31
+ </body>
32
+ </html>
33
+
34
+
Binary file