luoyutianyang commited on
Commit
e033aca
·
verified ·
1 Parent(s): 774c3e6

Upload 795 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .editorconfig +35 -0
  2. .eslintignore +4 -0
  3. .eslintrc.cjs +23 -0
  4. .gitattributes +1 -0
  5. .gitignore +141 -0
  6. .npmrc +5 -0
  7. LICENSE +674 -0
  8. app.js +4 -0
  9. config/SSL/.keep +0 -0
  10. config/default_config/SSL/.keep +0 -0
  11. config/default_config/page/GTest.yaml +3 -0
  12. config/default_config/page/home.yaml +51 -0
  13. config/default_config/page/home/siteLinks.json +32 -0
  14. config/default_config/page/home/socialLinks.json +44 -0
  15. config/default_config/page/home/upData.json +14 -0
  16. config/default_config/page/music.yaml +19 -0
  17. config/default_config/pm2/pm2.json +10 -0
  18. config/default_config/redis.yaml +14 -0
  19. config/default_config/server.yaml +29 -0
  20. config/page/GTest.yaml +3 -0
  21. config/page/home.yaml +51 -0
  22. config/page/home/siteLinks.json +27 -0
  23. config/page/home/socialLinks.json +32 -0
  24. config/page/home/upData.json +14 -0
  25. config/page/music.yaml +19 -0
  26. config/pm2/pm2.json +10 -0
  27. config/redis.yaml +14 -0
  28. config/server.yaml +29 -0
  29. lib/application/WebSocketMethod.js +39 -0
  30. lib/application/setTrustProxy.js +8 -0
  31. lib/application/setViewEngine.js +30 -0
  32. lib/config/check.js +30 -0
  33. lib/config/config.js +76 -0
  34. lib/config/init.js +57 -0
  35. lib/config/log.js +98 -0
  36. lib/config/redis.js +73 -0
  37. lib/loader/listener.js +142 -0
  38. lib/loader/loader.js +206 -0
  39. lib/loader/plugin.js +125 -0
  40. lib/server.js +18 -0
  41. lib/service/handler.js +63 -0
  42. lib/service/service.js +36 -0
  43. lib/service/util.js +17 -0
  44. lib/service/websocket.js +25 -0
  45. package.json +43 -0
  46. plugins/example/GTest.js +120 -0
  47. plugins/example/home.js +23 -0
  48. plugins/example/mysSign.js +136 -0
  49. plugins/example/接口示例.js +27 -0
  50. plugins/hot/index.js +87 -0
.editorconfig ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ indent_size = 2
6
+ indent_style = space
7
+ tab_width = 2
8
+ insert_final_newline = true
9
+ end_of_line = lf
10
+ trim_trailing_whitespace = true
11
+ max_line_length = off
12
+ ij_any_space_before_colon = true
13
+ ij_any_space_after_colon = true
14
+ ij_any_keep_indents_on_empty_lines = false
15
+
16
+ [{*.cjs,*.js}]
17
+ ij_javascript_align_imports = false
18
+ ij_javascript_use_semicolon_after_statement = false
19
+ ij_javascript_use_double_quotes = false
20
+ ij_javascript_enforce_trailing_comma = keep
21
+ ij_javascript_space_before_method_parentheses = true
22
+ ij_javascript_spaces_within_object_literal_braces = true
23
+ ij_javascript_indent_chained_calls = true
24
+ ij_javascript_if_brace_force = if_multiline
25
+
26
+ [{*.json,*.json5}]
27
+ ij_json_keep_trailing_comma = false
28
+ ij_json_keep_blank_lines_in_code = 0
29
+ ij_json_keep_indents_on_empty_lines = false
30
+ ij_json_space_after_colon = true
31
+ ij_json_space_after_comma = true
32
+ ij_json_space_before_colon = false
33
+ ij_json_space_before_comma = false
34
+ ij_json_spaces_within_braces = false
35
+ ij_json_spaces_within_brackets = false
.eslintignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ plugins/music/NeteaseCloudMusicApi
2
+ config/
3
+ public/
4
+ logs/
.eslintrc.cjs ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports = {
2
+ env: {
3
+ es2021: true,
4
+ node: true
5
+ },
6
+ root: true,
7
+ extends: ['standard'],
8
+ parserOptions: {
9
+ ecmaVersion: 'latest',
10
+ sourceType: 'module'
11
+ },
12
+ globals: {
13
+ Server: true,
14
+ redis: true,
15
+ logger: true,
16
+ plugin: true
17
+ },
18
+ rules: {
19
+ eqeqeq: ['off'],
20
+ 'prefer-const': ['off'],
21
+ 'arrow-body-style': 'off'
22
+ }
23
+ }
.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ public/assets/fonts/NZBZ.ttf filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ lerna-debug.log*
8
+ .pnpm-debug.log*
9
+
10
+ # Diagnostic reports (https://nodejs.org/api/report.html)
11
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12
+
13
+ # Runtime data
14
+ pids
15
+ *.pid
16
+ *.seed
17
+ *.pid.lock
18
+
19
+ # Directory for instrumented libs generated by jscoverage/JSCover
20
+ lib-cov
21
+
22
+ # Coverage directory used by tools like istanbul
23
+ coverage
24
+ *.lcov
25
+
26
+ # nyc test coverage
27
+ .nyc_output
28
+
29
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30
+ .grunt
31
+
32
+ # Bower dependency directory (https://bower.io/)
33
+ bower_components
34
+
35
+ # node-waf configuration
36
+ .lock-wscript
37
+
38
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
39
+ build/Release
40
+
41
+ # Dependency directories
42
+ node_modules/
43
+ */node_modules/
44
+ jspm_packages/
45
+ pnpm-lock.yaml
46
+
47
+ # Snowpack dependency directory (https://snowpack.dev/)
48
+ web_modules/
49
+
50
+ # TypeScript cache
51
+ *.tsbuildinfo
52
+
53
+ # Optional npm cache directory
54
+ .npm
55
+
56
+ # Optional eslint cache
57
+ .eslintcache
58
+
59
+ # Optional stylelint cache
60
+ .stylelintcache
61
+
62
+ # Microbundle cache
63
+ .rpt2_cache/
64
+ .rts2_cache_cjs/
65
+ .rts2_cache_es/
66
+ .rts2_cache_umd/
67
+
68
+ # Optional REPL history
69
+ .node_repl_history
70
+
71
+ # Output of 'npm pack'
72
+ *.tgz
73
+
74
+ # Yarn Integrity file
75
+ .yarn-integrity
76
+
77
+ # dotenv environment variable files
78
+ .env
79
+ .env.development.local
80
+ .env.test.local
81
+ .env.production.local
82
+ .env.local
83
+
84
+ # parcel-bundler cache (https://parceljs.org/)
85
+ .cache
86
+ .parcel-cache
87
+
88
+ # Next.js build output
89
+ .next
90
+ out
91
+
92
+ # Nuxt.js build / generate output
93
+ .nuxt
94
+ dist
95
+
96
+ # Gatsby files
97
+ .cache/
98
+ # Comment in the public line in if your project uses Gatsby and not Next.js
99
+ # https://nextjs.org/blog/next-9-1#public-directory-support
100
+ # public
101
+
102
+ # vuepress build output
103
+ .vuepress/dist
104
+
105
+ # vuepress v2.x temp and cache directory
106
+ .temp
107
+ .cache
108
+
109
+ # Docusaurus cache and generated files
110
+ .docusaurus
111
+
112
+ # Serverless directories
113
+ .serverless/
114
+
115
+ # FuseBox cache
116
+ .fusebox/
117
+
118
+ # DynamoDB Local files
119
+ .dynamodb/
120
+
121
+ # TernJS port file
122
+ .tern-port
123
+
124
+ # Stores VSCode versions used for testing VSCode extensions
125
+ .vscode-test
126
+ .vscode/
127
+
128
+ # yarn v2
129
+ .yarn/cache
130
+ .yarn/unplugged
131
+ .yarn/build-state.yml
132
+ .yarn/install-state.gz
133
+ .pnp.*
134
+
135
+ # GT data
136
+ dump.rdb
137
+ data/
138
+ !config
139
+ config/*
140
+ !config/default_config/
141
+ logs/
.npmrc ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ registry=https://registry.npmmirror.com
2
+ node_sqlite3_binary_host_mirror=https://npmmirror.com/mirrors/sqlite3
3
+ canvas_binary_host_mirror=https://npmmirror.com/mirrors/canvas
4
+ sharp_binary_host=https://npmmirror.com/mirrors/sharp
5
+ sharp_libvips_binary_host=https://npmmirror.com/mirrors/sharp-libvips
LICENSE ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ <one line to give the program's name and a brief idea of what it does.>
635
+ Copyright (C) <year> <name of author>
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ <program> Copyright (C) <year> <name of author>
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <http://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
app.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ import server from './lib/server.js'
2
+
3
+ /** 全局变量 Server */
4
+ global.Server = await server.run()
config/SSL/.keep ADDED
File without changes
config/default_config/SSL/.keep ADDED
File without changes
config/default_config/page/GTest.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Key校验
2
+ ## 为/register接口添加?key=114514校验,若不需要,请设为空即可
3
+ REGISTER_KEY: '114514'
config/default_config/page/home.yaml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 站点信息
2
+ SITE_NAME: 'Hlhsの小破站' #标题
3
+ SITE_ANTHOR: 'Hlhs' # 作者
4
+ SITE_KEYWORDS: 'hlhs home page' # 关键词
5
+ SITE_DES: '除了时间,什么也没留下,风带来故事的种子,时间使其发芽。' # 站点简介
6
+ SITE_URL: 'Hlhs.com' # 站点地址
7
+ SITE_MAIN_LOGO: './images/icon/logo.png' # 主页图标, /public相对路径
8
+
9
+ # 简介文本
10
+ DESC_HELLO: 'Hello World !'
11
+ DESC_TEXT: '你们觉得彭于晏很帅吗,我觉得还行吧,可能是在一起久了没什么感觉了'
12
+ DESC_HELLO_OTHER: 'Oops !'
13
+ DESC_TEXT_OTHER: '哎呀,这都被你发现了( 再点击一次可关闭 )'
14
+
15
+ # 壁纸数量,按顺序从1开始background前缀
16
+ BACKGROUND_MAX: 11
17
+
18
+ # 社交链接
19
+ ## 请在 config/page/home/socialLinks.json 文件中配置
20
+
21
+ # 网站链接
22
+ ## 请在 siteLinks.json 文件中配置
23
+ ## 网站链接的图标名称可前往 https://www.xicons.org 自行挑选
24
+ ## 下载后在 config/page/home/siteLinks.json 中引入,/public相对路径
25
+ ## 图标颜色可在svg代码中`fill`标签修改,如fill: "#fff"
26
+
27
+ # 天气 Key
28
+ ## 请前往 高德开放平台注册 Web服务 Key
29
+ ## 请注意不是 Web端 (JS API),免费申请,每日上限 5000 次
30
+ ## 此处提供的服务可能会超量从而无法访问,请自行申请!请自行申请!请自行申请!
31
+ ## 若此处设为空则调用 教书先生 API https://api.oioweb.cn/doc/weather/GetWeather
32
+ WEATHER_KEY: ''
33
+
34
+ # 建站日期
35
+ ## 若不需要,请设为空即可
36
+ ## 请按照 YYYY-MM-DD 格式填写或者仅填写年份 YYYY
37
+ SITE_START: '2022-01-01'
38
+
39
+ # ICP 备案号 例如'粤ICP备2022010100号-1'
40
+ ## 国内域名主页必须设置, 若不需要,请设为空即可
41
+ SITE_ICP: ''
42
+
43
+ # MetingAPI 地址
44
+ SONG_API: "/music/api/meting"
45
+ # 歌曲服务器 ( netease: 网易云, tencent: qq音乐 )
46
+ ## 若使用 QQ 音乐歌单,歌曲数量最好不要超出 50 首
47
+ SONG_SERVER: 'netease'
48
+ # 播放类型 ( song-歌曲, playlist-播放列表, album-专辑, search-搜索, artist-艺术家 )
49
+ SONG_TYPE: 'album'
50
+ # 歌曲/歌单ID ( 若无需播放器,请设为空即可 )
51
+ SONG_ID: '175676520' # 枫丹音乐专辑
config/default_config/page/home/siteLinks.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "icon": "./images/icon/svg/Blog.svg",
4
+ "name": "博客×",
5
+ "link": "https://blog.example.com/"
6
+ },
7
+ {
8
+ "icon": "./images/icon/svg/Cloud.svg",
9
+ "name": "网盘×",
10
+ "link": "https://pan.example.com/"
11
+ },
12
+ {
13
+ "icon": "./images/icon/svg/Recording.svg",
14
+ "name": "音乐",
15
+ "link": "/music"
16
+ },
17
+ {
18
+ "icon": "./images/icon/svg/Compass.svg",
19
+ "name": "起始页×",
20
+ "link": "https://nav.example.com/"
21
+ },
22
+ {
23
+ "icon": "./images/icon/svg/Photo.svg",
24
+ "name": "图库×",
25
+ "link": "https://pic.example.com/"
26
+ },
27
+ {
28
+ "icon": "./images/icon/svg/Fire.svg",
29
+ "name": "今日热榜",
30
+ "link": "/hot"
31
+ }
32
+ ]
config/default_config/page/home/socialLinks.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "name": "Github",
4
+ "icon": "./images/icon/github.png",
5
+ "tip": "去 Github 看看",
6
+ "url": "https://github.com/"
7
+ },
8
+ {
9
+ "name": "Gitee",
10
+ "icon": "./images/icon/gitee.png",
11
+ "tip": "去 Gitee 看看",
12
+ "url": "https://gitee.com/"
13
+ },
14
+ {
15
+ "name": "BiliBili",
16
+ "icon": "./images/icon/bilibili.png",
17
+ "tip": "(゜-゜)つロ 干杯 ~",
18
+ "url": "https://bilibili.com/"
19
+ },
20
+ {
21
+ "name": "QQ",
22
+ "icon": "./images/icon/qq.png",
23
+ "tip": "有什么事吗",
24
+ "url": "https://res.abeim.cn/api/qq/?qq=1146638442"
25
+ },
26
+ {
27
+ "name": "Email",
28
+ "icon": "./images/icon/email.png",
29
+ "tip": "来封 Email ~",
30
+ "url": "mailto:user@example.com"
31
+ },
32
+ {
33
+ "name": "Twitter",
34
+ "icon": "./images/icon/twitter.png",
35
+ "tip": "你懂的 ~",
36
+ "url": "https://twitter.com/"
37
+ },
38
+ {
39
+ "name": "Telegram",
40
+ "icon": "./images/icon/telegram.png",
41
+ "tip": "你懂的 ~",
42
+ "url": "https://t.me/group_id"
43
+ }
44
+ ]
config/default_config/page/home/upData.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": "v1.0.0",
3
+ "title": "更新日志",
4
+ "new": [
5
+ "1",
6
+ "2",
7
+ "3"
8
+ ],
9
+ "fix": [
10
+ "木",
11
+ "头",
12
+ "人"
13
+ ]
14
+ }
config/default_config/page/music.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 站点信息
2
+ SITE_TITLE: 'SPlayer'
3
+ SITE_ANTHOR: 'Hlhs'
4
+ SITE_KEYWORDS: 'SPlayer,云音乐,播放器,在线音乐,在线播放器,音乐播放器'
5
+ SITE_DES: '一个简约的在线音乐播放器,具有音乐搜索、播放、每日推荐、私人FM、歌词显示、歌曲评论、网易云登录与云盘等功能'
6
+ SITE_URL: 'example.com'
7
+
8
+ # API 地址( 结尾不要加 / )
9
+ SERVER_URL: './api'
10
+
11
+ # 公告配置 (若无需公告,请将标题或内容任意一项设为空即可)
12
+ ## 公告类型 info、success、warning、error
13
+ ANN_TYPE: 'info'
14
+ ## 公告标题
15
+ ANN_TITLE: ''
16
+ ## 公告内容
17
+ ANN_CONTENT: ''
18
+ ## 公告时长(毫秒)不可超过 999999
19
+ ANN_DURATION: 8000
config/default_config/pm2/pm2.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "apps": [
3
+ {
4
+ "name": "GT-Manual",
5
+ "script": "./app.js",
6
+ "max_memory_restart": "512M",
7
+ "restart_delay": 60000
8
+ }
9
+ ]
10
+ }
config/default_config/redis.yaml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 是否连接redis
2
+ open: false
3
+
4
+ # redis地址
5
+ host: localhost
6
+
7
+ # redis端口
8
+ port: 6379
9
+
10
+ # redis密码,没有密码请留空
11
+ password: ''
12
+
13
+ # redis数据库
14
+ db: 0
config/default_config/server.yaml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # server地址,一般不用修改
2
+ HOST: '0.0.0.0'
3
+
4
+ # http端口
5
+ HTTP_PORT: 80
6
+ # https端口
7
+ HTTPS_PORT: 443
8
+
9
+ # 使用https
10
+ HTTPS: false
11
+ # http重定向https
12
+ HTTP_TO_HTTPS: true
13
+ # ssl证书crt文件路径
14
+ CA_CERTIFICATE: './config/SSL/certificate.crt'
15
+ # ssl证书key文件路径
16
+ CA_PRIVATE: './config/SSL/private.key'
17
+
18
+ # 启用 CORS 头部
19
+ CROSS_DOMAIN: true
20
+
21
+ # 信任代理
22
+ TRUST_PROXY: false
23
+ # 信任来自以下IP的代理
24
+ TRUST_PROXY_IP:
25
+ - '0.0.0.0'
26
+ - '123.123.123.123'
27
+
28
+ # 公众访问地址
29
+ PUBLIC_ADDRESS: 'http://example.com/'
config/page/GTest.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Key校验
2
+ ## 为/register接口添加?key=114514校验,若不需要,请设为空即可
3
+ REGISTER_KEY: '哼哼啊啊啊!!!'
config/page/home.yaml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 站点信息
2
+ SITE_NAME: '落雨天阳のGT-Manual' #标题
3
+ SITE_ANTHOR: '落雨天阳' # 作者
4
+ SITE_KEYWORDS: 'hlhs home page' # 关键词
5
+ SITE_DES: '除了时间,什么也没留下,风带来故事的种子,时间使其发芽。' # 站点简介
6
+ SITE_URL: 'botqsign.icu' # 站点地址
7
+ SITE_MAIN_LOGO: './images/icon/logo.png' # 主页图标, /public相对路径
8
+
9
+ # 简介文本
10
+ DESC_HELLO: 'Hello World !'
11
+ DESC_TEXT: '说不出来的才叫委屈,哭到笑的那种才叫痛'
12
+ DESC_HELLO_OTHER: 'Oops !'
13
+ DESC_TEXT_OTHER: '哎呀,这都被你发现了( 再点击一次可关闭 )'
14
+
15
+ # 壁纸数量,按顺序从1开始background前缀
16
+ BACKGROUND_MAX: 11
17
+
18
+ # 社交链接
19
+ ## 请在 config/page/home/socialLinks.json 文件中配置
20
+
21
+ # 网站链接
22
+ ## 请在 siteLinks.json 文件中配置
23
+ ## 网站链接的图标名称可前往 https://www.xicons.org 自行挑选
24
+ ## 下载后在 config/page/home/siteLinks.json 中引入,/public相对路径
25
+ ## 图标颜色可在svg代码中`fill`标签修改,如fill: "#fff"
26
+
27
+ # 天气 Key
28
+ ## 请前往 高德开放平台注册 Web服务 Key
29
+ ## 请注意不是 Web端 (JS API),免费申请,每日上限 5000 次
30
+ ## 此处提供的服务可能会超量从而无法访问,请自行申请!请自行申请!请自行申请!
31
+ ## 若此处设为空则调用 教书先生 API https://api.oioweb.cn/doc/weather/GetWeather
32
+ WEATHER_KEY: ''
33
+
34
+ # 建站日期
35
+ ## 若不需要,请设为空即可
36
+ ## 请按照 YYYY-MM-DD 格式填写或者仅填写年份 YYYY
37
+ SITE_START: '2024-05-09'
38
+
39
+ # ICP 备案号 例如'粤ICP备2022010100号-1'
40
+ ## 国内域名主页必须设置, 若不需要,请设为空即可
41
+ SITE_ICP: ''
42
+
43
+ # MetingAPI 地址
44
+ SONG_API: "/music/api/meting"
45
+ # 歌曲服务器 ( netease: 网易云, tencent: qq音乐 )
46
+ ## 若使用 QQ 音乐歌单,歌曲数量最好不要超出 50 首
47
+ SONG_SERVER: 'netease'
48
+ # 播放类型 ( song-歌曲, playlist-播放列表, album-专辑, search-搜索, artist-艺术家 )
49
+ SONG_TYPE: 'album'
50
+ # 歌曲/歌单ID ( 若无需播放器,请设为空即可 )
51
+ SONG_ID: '175676520' # 枫丹音乐专辑
config/page/home/siteLinks.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "icon": "./images/icon/svg/Blog.svg",
4
+ "name": "博客×",
5
+ "link": "https://botqsign.icu"
6
+ },
7
+ {
8
+ "icon": "./images/icon/svg/Cloud.svg",
9
+ "name": "网盘×",
10
+ "link": "https://alist.botqsign.icu/"
11
+ },
12
+ {
13
+ "icon": "./images/icon/svg/Recording.svg",
14
+ "name": "公共QSign",
15
+ "link": "https://botqsign.icu/qsign"
16
+ },
17
+ {
18
+ "icon": "./images/icon/svg/Photo.svg",
19
+ "name": "图库×",
20
+ "link": "https://api.botqsign.icu/"
21
+ },
22
+ {
23
+ "icon": "./images/icon/svg/Fire.svg",
24
+ "name": "今日热榜",
25
+ "link": "/hot"
26
+ }
27
+ ]
config/page/home/socialLinks.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "name": "Github",
4
+ "icon": "./images/icon/github.png",
5
+ "tip": "去 Github 看看",
6
+ "url": "https://github.com/Circle-money-run/Circle-money-run-plugin"
7
+ },
8
+ {
9
+ "name": "Gitee",
10
+ "icon": "./images/icon/gitee.png",
11
+ "tip": "去 Gitee 看看",
12
+ "url": "https://gitee.com/Circle-money-run/Circle-money-run-plugin/"
13
+ },
14
+ {
15
+ "name": "QQ",
16
+ "icon": "./images/icon/qq.png",
17
+ "tip": "有什么事吗",
18
+ "url": "http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=SZ34z6MDaoW6zrClfaKFgYVfRg7PaUeP&authKey=oo6Ki91%2Fc9XXxbDO1QFRXYtZygHZZ0DZIWNDfJgbYCKfNma60Cl5od8Og7Nb9Mr8&noverify=0&group_code=720290263"
19
+ },
20
+ {
21
+ "name": "Email",
22
+ "icon": "./images/icon/email.png",
23
+ "tip": "来封 Email ~",
24
+ "url": "mailto:user@example.com"
25
+ },
26
+ {
27
+ "name": "Telegram",
28
+ "icon": "./images/icon/telegram.png",
29
+ "tip": "你懂的 ~",
30
+ "url": "https://t.me/quanqianpaolu"
31
+ }
32
+ ]
config/page/home/upData.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": "v1.0.0",
3
+ "title": "更新日志",
4
+ "new": [
5
+ "1",
6
+ "2",
7
+ "3"
8
+ ],
9
+ "fix": [
10
+ "木",
11
+ "头",
12
+ "人"
13
+ ]
14
+ }
config/page/music.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 站点信息
2
+ SITE_TITLE: 'SPlayer'
3
+ SITE_ANTHOR: 'Hlhs'
4
+ SITE_KEYWORDS: 'SPlayer,云音乐,播放器,在线音乐,在线播放器,音乐播放器'
5
+ SITE_DES: '一个简约的在线音乐播放器,具有音乐搜索、播放、每日推荐、私人FM、歌词显示、歌曲评论、网易云登录与云盘等功能'
6
+ SITE_URL: 'example.com'
7
+
8
+ # API 地址( 结尾不要加 / )
9
+ SERVER_URL: './api'
10
+
11
+ # 公告配置 (若无需公告,请将标题或内容任意一项设为空即可)
12
+ ## 公告类型 info、success、warning、error
13
+ ANN_TYPE: 'info'
14
+ ## 公告标题
15
+ ANN_TITLE: ''
16
+ ## 公告内容
17
+ ANN_CONTENT: ''
18
+ ## 公告时长(毫秒)不可超过 999999
19
+ ANN_DURATION: 8000
config/pm2/pm2.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "apps": [
3
+ {
4
+ "name": "GT-Manual",
5
+ "script": "./app.js",
6
+ "max_memory_restart": "512M",
7
+ "restart_delay": 60000
8
+ }
9
+ ]
10
+ }
config/redis.yaml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 是否连接redis
2
+ open: true
3
+
4
+ # redis地址
5
+ host: localhost
6
+
7
+ # redis端口
8
+ port: 6379
9
+
10
+ # redis密码,没有密码请留空
11
+ password: ''
12
+
13
+ # redis数据库
14
+ db: 0
config/server.yaml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # server地址,一般不用修改
2
+ HOST: '0.0.0.0'
3
+
4
+ # http端口
5
+ HTTP_PORT: 7860
6
+ # https端口
7
+ HTTPS_PORT: 443
8
+
9
+ # 使用https
10
+ HTTPS: false
11
+ # http重定向https
12
+ HTTP_TO_HTTPS: true
13
+ # ssl证书crt文件路径
14
+ CA_CERTIFICATE: './config/SSL/certificate.crt'
15
+ # ssl证书key文件路径
16
+ CA_PRIVATE: './config/SSL/private.key'
17
+
18
+ # 启用 CORS 头部
19
+ CROSS_DOMAIN: true
20
+
21
+ # 信任代理
22
+ TRUST_PROXY: true
23
+ # 信任来自以下IP的代理
24
+ TRUST_PROXY_IP:
25
+ - '0.0.0.0'
26
+ - '123.123.123.123'
27
+
28
+ # 公众访问地址
29
+ PUBLIC_ADDRESS: 'https://luoyutianyang-gt-manual.hf.space'
lib/application/WebSocketMethod.js ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import url from 'node:url'
2
+ import { modifyUrl } from '../service/util.js'
3
+
4
+ export default new class WebSocketMethod {
5
+ handle ({ app, handler }) {
6
+ app.ws = (route, ...middlewares) => {
7
+ let path = route
8
+ if (typeof route == 'function') {
9
+ path = '/'
10
+ middlewares = [route, ...middlewares]
11
+ }
12
+ if (middlewares.length == 1 && Array.isArray(middlewares[0])) {
13
+ middlewares = middlewares[0]
14
+ }
15
+ middlewares.forEach(this.middlewareEach.bind({ handler, path }))
16
+ return app
17
+ }
18
+ }
19
+
20
+ middlewareEach (middleware, idx) {
21
+ let fn = (socket, request, next) => {
22
+ if (request.ws) {
23
+ /* eslint-disable n/no-deprecated-api */
24
+ let urlObj = url.parse(request.url, true)
25
+ request.query = urlObj.query
26
+ request.wsHandled = true
27
+ try {
28
+ middleware(socket, request, next)
29
+ } catch (err) {
30
+ next(err)
31
+ }
32
+ } else {
33
+ next()
34
+ }
35
+ }
36
+ /** 不走app.handle */
37
+ this.handler.add(modifyUrl(this.path), fn, idx)
38
+ }
39
+ }()
lib/application/setTrustProxy.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ export default new class setTrustProxy {
2
+ handle ({ app, cfg }) {
3
+ let { TRUST_PROXY, TRUST_PROXY_IP } = cfg.http
4
+ if (TRUST_PROXY) {
5
+ app.set('trust proxy', TRUST_PROXY_IP)
6
+ }
7
+ }
8
+ }()
lib/application/setViewEngine.js ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import template from 'art-template'
2
+ import { resolve } from 'node:path'
3
+ import fs from 'node:fs'
4
+ import md5 from 'md5'
5
+
6
+ export default new class SetViewEngine {
7
+ viewCache = {}
8
+
9
+ handle ({ app }) {
10
+ app.engine('html', this.renderView.bind(this))
11
+ app.set('views', resolve('public'))
12
+ app.set('view engine', 'html')
13
+ app.set('x-powered-by', false)
14
+ }
15
+
16
+ renderView (filename, opt, cb) {
17
+ try {
18
+ let tmp = md5(fs.readFileSync(filename))
19
+ let cache = this.viewCache[filename]
20
+ if (cache !== tmp) template.defaults.caches.set(filename, null)
21
+ this.viewCache[filename] = tmp
22
+ template.defaults.imports.indexCfg = Server.cfg.getConfig('page/home')
23
+ opt.cfg && (opt._cfg_base64 = Buffer.from(encodeURIComponent(JSON.stringify(opt.cfg))).toString('base64'))
24
+ let render = template.compile({ filename, debug: false })
25
+ cb(null, render(opt))
26
+ } catch (err) {
27
+ cb(err)
28
+ }
29
+ }
30
+ }()
lib/config/check.js ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fs from 'node:fs'
2
+ import { exec } from 'node:child_process'
3
+
4
+ export async function checkRun () {
5
+ if (process.argv[1].includes('pm2')) return
6
+ if (process.argv[1].includes('test')) return
7
+
8
+ let cfg = pm2Cfg()
9
+ let status = await execSync(`pm2 show ${cfg.apps[0].name}`)
10
+
11
+ if (status.stdout.includes('online')) {
12
+ logger.mark('检测到后台正在运行')
13
+ logger.mark('已停止后台进程,防止重复运行')
14
+ execSync(`pm2 stop ${cfg.apps[0].name}`)
15
+ }
16
+ }
17
+
18
+ async function execSync (cmd) {
19
+ return new Promise((resolve, reject) => {
20
+ exec(cmd, (error, stdout, stderr) => {
21
+ resolve({ error, stdout, stderr })
22
+ })
23
+ })
24
+ }
25
+
26
+ function pm2Cfg () {
27
+ let cfg = fs.readFileSync('./config/pm2/pm2.json')
28
+ cfg = JSON.parse(cfg)
29
+ return cfg
30
+ }
lib/config/config.js ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import YAML from 'yaml'
2
+ import fs from 'node:fs'
3
+
4
+ /** 配置文件 */
5
+ class Cfg {
6
+ /** 初始化配置 */
7
+ constructor () {
8
+ this.initCfg()
9
+ this.config = {}
10
+ }
11
+
12
+ /** 初始化配置 */
13
+ initCfg (pathDef = './config/default_config', path = './config') {
14
+ if (!fs.existsSync(path)) {
15
+ fs.mkdirSync(path)
16
+ }
17
+ fs.readdirSync(pathDef).forEach((file) => {
18
+ let sourcePath = `${pathDef}/${file}`
19
+ let targetPath = `${path}/${file}`
20
+ if (fs.lstatSync(sourcePath).isDirectory()) {
21
+ this.initCfg(sourcePath, targetPath)
22
+ } else {
23
+ if (!fs.existsSync(targetPath)) fs.copyFileSync(sourcePath, targetPath)
24
+ }
25
+ })
26
+ }
27
+
28
+ get http () {
29
+ let cfg = this.getConfig('server')
30
+ cfg.PUBLIC_ADDRESS = cfg.PUBLIC_ADDRESS.replace(/\/$/, '')
31
+ return cfg
32
+ }
33
+
34
+ get http_listen () {
35
+ return [this.http.HTTPS ? this.http.HTTPS_PORT : this.http.HTTP_PORT, this.http.HOST]
36
+ }
37
+
38
+ get redis () {
39
+ return this.getConfig('redis')
40
+ }
41
+
42
+ get cert () {
43
+ return {
44
+ cert: fs.readFileSync(this.http.CA_CERTIFICATE, 'utf8'),
45
+ key: fs.readFileSync(this.http.CA_PRIVATE, 'utf8')
46
+ }
47
+ }
48
+
49
+ /** package.json */
50
+ get package () {
51
+ if (this._package) return this._package
52
+
53
+ this._package = JSON.parse(fs.readFileSync('package.json', 'utf8'))
54
+ return this._package
55
+ }
56
+
57
+ /** 用户配置 */
58
+ getConfig (name, cache = true) {
59
+ return this.getYaml(name, cache)
60
+ }
61
+
62
+ /**
63
+ * 获取配置yaml
64
+ * @param type 默认跑配置-defSet,用户配置-config
65
+ * @param name 名称
66
+ */
67
+ getYaml (name, cache) {
68
+ let file = `config/${name}.yaml`
69
+ if (cache && this.config[name]) return this.config[name]
70
+ let ret = YAML.parse(fs.readFileSync(file, 'utf8'))
71
+ if (cache) this.config[name] = ret
72
+ return ret
73
+ }
74
+ }
75
+
76
+ export default new Cfg()
lib/config/init.js ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import setLog from './log.js'
2
+ import cfg from './config.js'
3
+ import redisInit from './redis.js'
4
+ import { checkRun } from './check.js'
5
+ import fs from 'node:fs'
6
+
7
+ /** 设置标题 */
8
+ process.title = cfg.package.name
9
+ /** 设置时区 */
10
+ process.env.TZ = 'Asia/Shanghai'
11
+
12
+ /** 捕获未处理的错误 */
13
+ process.on('uncaughtException', (error) => {
14
+ let err = error
15
+ if (global.logger) {
16
+ logger.error(err)
17
+ } else {
18
+ console.log(err)
19
+ }
20
+ })
21
+
22
+ /** 捕获未处理的Promise错误 */
23
+ process.on('unhandledRejection', (error, promise) => {
24
+ let err = error
25
+ if (global.logger) {
26
+ logger.error(err)
27
+ } else {
28
+ console.log(err)
29
+ }
30
+ })
31
+
32
+ /** 退出事件 */
33
+ process.on('exit', async (code) => {
34
+ if (typeof redis != 'undefined' && typeof test == 'undefined') {
35
+ await redis.save()
36
+ }
37
+ })
38
+
39
+ await checkInit()
40
+
41
+ /** 初始化事件 */
42
+ async function checkInit () {
43
+ /** 检查node_modules */
44
+ if (!fs.existsSync('./node_modules') || !fs.existsSync('./node_modules/express')) {
45
+ console.log('请先pnpm install -P安装')
46
+ process.exit()
47
+ }
48
+
49
+ /** 日志设置 */
50
+ setLog()
51
+
52
+ await redisInit()
53
+
54
+ await checkRun()
55
+
56
+ logger.info(`${cfg.package.name} 启动中...`)
57
+ }
lib/config/log.js ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import log4js from 'log4js'
2
+ import chalk from 'chalk'
3
+ import fs from 'node:fs'
4
+
5
+ /**
6
+ * 设置日志样式
7
+ */
8
+ export default function setLog () {
9
+ let file = './logs'
10
+ let level = 'info'
11
+ if (!fs.existsSync(file)) {
12
+ fs.mkdirSync(file)
13
+ }
14
+
15
+ /** 调整error日志等级 */
16
+ // log4js.levels.levels[5].level = Number.MAX_VALUE
17
+ // log4js.levels.levels.sort((a, b) => a.level - b.level)
18
+
19
+ log4js.configure({
20
+ appenders: {
21
+ console: {
22
+ type: 'console',
23
+ layout: {
24
+ type: 'pattern',
25
+ pattern: '%[[Server][%d{hh:mm:ss}][%4.4p]%] %m'
26
+ }
27
+ },
28
+ command: {
29
+ type: 'dateFile', // 可以是console,dateFile,file,Logstash等
30
+ filename: 'logs/command', // 将会按照filename和pattern拼接文件名
31
+ pattern: 'yyyy-MM-dd.log',
32
+ numBackups: 15,
33
+ alwaysIncludePattern: true,
34
+ layout: {
35
+ type: 'pattern',
36
+ pattern: '[%d{hh:mm:ss}][%4.4p] %m'
37
+ }
38
+ },
39
+ error: {
40
+ type: 'file',
41
+ filename: 'logs/error.log',
42
+ alwaysIncludePattern: true,
43
+ layout: {
44
+ type: 'pattern',
45
+ pattern: '[%d{hh:mm:ss}][%4.4p] %m'
46
+ }
47
+ }
48
+ },
49
+ categories: {
50
+ default: { appenders: ['console'], level },
51
+ command: { appenders: ['console', 'command'], level },
52
+ error: { appenders: ['console', 'command', 'error'], level: 'error' }
53
+ }
54
+ })
55
+
56
+ const defaultLogger = log4js.getLogger('message')
57
+ const commandLogger = log4js.getLogger('command')
58
+ const errorLogger = log4js.getLogger('error')
59
+
60
+ /* eslint-disable no-useless-call */
61
+ /** 全局变量 logger */
62
+ global.logger = {
63
+ trace () {
64
+ defaultLogger.trace.call(defaultLogger, ...arguments)
65
+ },
66
+ debug () {
67
+ defaultLogger.debug.call(defaultLogger, ...arguments)
68
+ },
69
+ info () {
70
+ defaultLogger.info.call(commandLogger, ...arguments)
71
+ },
72
+ // warn及以上的日志采用error策略
73
+ warn () {
74
+ commandLogger.warn.call(defaultLogger, ...arguments)
75
+ },
76
+ error () {
77
+ errorLogger.error.call(errorLogger, ...arguments)
78
+ },
79
+ fatal () {
80
+ errorLogger.fatal.call(errorLogger, ...arguments)
81
+ },
82
+ mark () {
83
+ errorLogger.mark.call(commandLogger, ...arguments)
84
+ }
85
+ }
86
+
87
+ logColor()
88
+ }
89
+
90
+ function logColor () {
91
+ logger.chalk = chalk
92
+ logger.red = chalk.red
93
+ logger.green = chalk.green
94
+ logger.yellow = chalk.yellow
95
+ logger.blue = chalk.blue
96
+ logger.magenta = chalk.magenta
97
+ logger.cyan = chalk.cyan
98
+ }
lib/config/redis.js ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cfg from './config.js'
2
+ import { createClient } from 'redis'
3
+ import { exec } from 'node:child_process'
4
+
5
+ /**
6
+ * 初始化全局redis客户端
7
+ */
8
+ export default async function redisInit () {
9
+ const rc = cfg.redis
10
+ if (!rc?.open) return
11
+ const redisUn = rc.username || ''
12
+ let redisPw = rc.password ? `:${rc.password}` : ''
13
+ if (rc.username || rc.password) redisPw += '@'
14
+ const redisUrl = `redis://${redisUn}${redisPw}${rc.host}:${rc.port}/${rc.db}`
15
+ let client = createClient({ url: redisUrl })
16
+
17
+ try {
18
+ logger.info(`正在连接 ${logger.blue(redisUrl)}`)
19
+ await client.connect()
20
+ } catch (err) {
21
+ logger.error(`Redis 错误:${logger.red(err)}`)
22
+
23
+ const cmd = 'redis-server --save 900 1 --save 300 10 --daemonize yes' + await aarch64()
24
+ logger.info('正在启动 Redis...')
25
+ await execSync(cmd)
26
+ await new Promise((resolve) => setTimeout(resolve, 1000))
27
+
28
+ try {
29
+ client = createClient({ url: redisUrl })
30
+ await client.connect()
31
+ } catch (err) {
32
+ logger.error(`Redis 错误:${logger.red(err)}`)
33
+ logger.error(`请先启动 Redis:${logger.blue(cmd)}`)
34
+ process.exit()
35
+ }
36
+ }
37
+
38
+ client.on('error', async err => {
39
+ logger.error(`Redis 错误:${logger.red(err)}`)
40
+ const cmd = 'redis-server --save 900 1 --save 300 10 --daemonize yes' + await aarch64()
41
+ logger.error(`请先启动 Redis:${cmd}`)
42
+ process.exit()
43
+ })
44
+
45
+ /** 全局变量 redis */
46
+ global.redis = client
47
+ logger.info('Redis 连接成功')
48
+ return client
49
+ }
50
+
51
+ async function aarch64 () {
52
+ if (process.platform == 'win32') return ''
53
+ /** 判断arch */
54
+ const arch = await execSync('uname -m')
55
+ if (arch.stdout && arch.stdout.includes('aarch64')) {
56
+ /** 判断redis版本 */
57
+ let v = await execSync('redis-server -v')
58
+ if (v.stdout) {
59
+ v = v.stdout.match(/v=(\d)./)
60
+ /** 忽略arm警告 */
61
+ if (v && v[1] >= 6) return ' --ignore-warnings ARM64-COW-BUG'
62
+ }
63
+ }
64
+ return ''
65
+ }
66
+
67
+ function execSync (cmd) {
68
+ return new Promise((resolve, reject) => {
69
+ exec(cmd, (error, stdout, stderr) => {
70
+ resolve({ error, stdout, stderr })
71
+ })
72
+ })
73
+ }
lib/loader/listener.js ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import PluginsLoader from './loader.js'
2
+ import Plugin from './plugin.js'
3
+ import Handler from '../service/handler.js'
4
+ import Service from '../service/service.js'
5
+ import WebSocket from '../service/websocket.js'
6
+ import util from 'node:util'
7
+ import fs from 'node:fs'
8
+
9
+ export default class ListenerLoader extends PluginsLoader {
10
+ constructor () {
11
+ global.plugin = Plugin
12
+ super()
13
+ }
14
+
15
+ static create (args) {
16
+ args.handler = new Handler(args)
17
+ args.server = new Service(args)
18
+ args.wss = new WebSocket(args)
19
+ return Object.assign(new ListenerLoader(), args)
20
+ }
21
+
22
+ async run () {
23
+ await this.applicationHandle()
24
+ await this.pluginsLoader()
25
+ await this.addListener()
26
+ this.server.listen(...this.cfg.http_listen)
27
+ }
28
+
29
+ async applicationHandle () {
30
+ let files = fs.readdirSync('./lib/application/').filter(v => v.endsWith('.js'))
31
+ for (let val of files) {
32
+ let application = (await import(`../application/${val}`)).default
33
+ await application.handle(this)
34
+ }
35
+ }
36
+
37
+ async addListener () {
38
+ for (let plugin of this.priority) {
39
+ if (plugin.rule) {
40
+ for (let v of plugin.rule) {
41
+ let middlewares = []
42
+
43
+ let path = ((plugin.self.route || '') + (v.path || '')) || '/'
44
+
45
+ if (v.use) {
46
+ if (typeof v.use == 'string' && plugin.self[v.use]) {
47
+ let result = await plugin.self[v.use]()
48
+ if (result) {
49
+ if (!Array.isArray(result)) {
50
+ result = [result]
51
+ }
52
+ middlewares.push(...result)
53
+ }
54
+ } else if (Array.isArray(v.use)) {
55
+ v.use.forEach(fn => {
56
+ if (fn && plugin.self[fn]) {
57
+ middlewares.push(plugin.self[fn])
58
+ }
59
+ })
60
+ }
61
+ }
62
+
63
+ if (v.fnc && plugin.self[v.fnc]) {
64
+ if (v.method == 'ws') {
65
+ middlewares.push(this.WebSocketEvent(plugin, v.fnc))
66
+ } else {
67
+ middlewares.push(this.HttpRequestEvent(plugin, v.fnc))
68
+ }
69
+ }
70
+
71
+ try {
72
+ let methods = Array.isArray(v.method) ? v.method : [v.method]
73
+ methods.forEach(method => this.app[method](path, middlewares))
74
+ } catch (err) {
75
+ logger.error(`routeError: [${v.method}]'${path}'`)
76
+ logger.error(err.stack)
77
+ continue
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }
83
+
84
+ HttpRequestEvent (plugin, fnc) {
85
+ return async (req, res, next) => {
86
+ let p = (this.priority.find(val => val.key == plugin.key))?.class
87
+ if (!p) return res.send({ status: 1, message: 'Error occurred!' })
88
+ let t = {
89
+ req,
90
+ res,
91
+ next,
92
+ param: req.params,
93
+ query: req.query,
94
+ cookie: req.cookies,
95
+ body: req.body,
96
+ end: res.end,
97
+ send: (data, status) => res.status(status || 200).send(data),
98
+ error: (msg, status) => res.status(status || 200).send({ status: 1, message: msg || 'Invalid request' }),
99
+ render: res.render
100
+ }
101
+ t.params = Object.assign({}, t.param, t.query, t.body, t.cookie)
102
+ /* eslint-disable new-cap */
103
+ let self = Object.assign(new p(), t)
104
+ try {
105
+ let res = self[fnc] && self[fnc]()
106
+ if (util.types.isPromise(res)) {
107
+ res = await res
108
+ }
109
+ } catch (err) {
110
+ if (err) logger.error(err)
111
+ }
112
+ }
113
+ }
114
+
115
+ WebSocketEvent (plugin, fnc) {
116
+ return async (socket, request, next) => {
117
+ let p = (this.priority.find(val => val.key == plugin.key))?.class
118
+ if (!p) return socket.close()
119
+ let t = {
120
+ socket,
121
+ request,
122
+ next,
123
+ send: (...args) => socket.send(...args),
124
+ close: () => socket.close(),
125
+ onMessage: (fn, on = 'on') => socket[on]('message', fn),
126
+ onClose: (fn, on = 'on') => socket[on]('close', fn),
127
+ onError: (fn, on = 'on') => socket[on]('error', fn)
128
+ }
129
+ /* eslint-disable new-cap */
130
+ let self = Object.assign(new p(), t)
131
+ self.onError(logger.error)
132
+ try {
133
+ let res = self[fnc] && self[fnc]()
134
+ if (util.types.isPromise(res)) {
135
+ res = await res
136
+ }
137
+ } catch (err) {
138
+ if (err) logger.error(err)
139
+ }
140
+ }
141
+ }
142
+ }
lib/loader/loader.js ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import chokidar from 'chokidar'
2
+ import moment from 'moment'
3
+ import fs from 'node:fs'
4
+ import util from 'node:util'
5
+ import lodash from 'lodash'
6
+ import schedule from 'node-schedule'
7
+
8
+ export default class PluginsLoader {
9
+ constructor () {
10
+ this.priority = []
11
+ this.task = []
12
+ this.watcher = {}
13
+ this.dir = './plugins'
14
+ }
15
+
16
+ async pluginsLoader () {
17
+ const files = this.getPlugins()
18
+
19
+ logger.info('加载插件中..')
20
+
21
+ let pluCount = 0
22
+
23
+ let packageErr = []
24
+ for (let File of files) {
25
+ try {
26
+ let tmp = await import(File.path)
27
+ if (tmp.apps) tmp = { ...tmp.apps }
28
+ let isAdd = false
29
+ lodash.forEach(tmp, (p, i) => {
30
+ if (!p.prototype) {
31
+ return
32
+ }
33
+ /* eslint-disable new-cap */
34
+ let plugin = new p()
35
+ if (!plugin.priority) return
36
+ isAdd = true
37
+ logger.debug(`载入插件 [${plugin.name}]`)
38
+ /** 执行初始化 */
39
+ this.runInit(plugin)
40
+ /** 初始化定时任务 */
41
+ this.collectTask(plugin.task)
42
+ this.priority.push({
43
+ class: p,
44
+ key: File.name,
45
+ self: plugin,
46
+ name: plugin.name,
47
+ protocol: plugin.protocol || 'http',
48
+ priority: plugin.priority,
49
+ rule: plugin.rule
50
+ })
51
+ })
52
+
53
+ if (isAdd) pluCount++
54
+ } catch (error) {
55
+ if (error.stack.includes('Cannot find package')) {
56
+ packageErr.push({ error, File })
57
+ } else {
58
+ logger.error(`载入插件错误:${File.name}`)
59
+ logger.error(decodeURI(error.stack))
60
+ }
61
+ }
62
+ }
63
+
64
+ this.packageTips(packageErr)
65
+ this.creatTask()
66
+ this.priority = lodash.orderBy(this.priority, ['priority'], ['asc'])
67
+ logger.info(`加载定时任务[${this.task.length}个]`)
68
+ logger.info(`加载插件完成[${pluCount}个]`)
69
+ logger.info('-----------')
70
+ }
71
+
72
+ getPlugins () {
73
+ let ignore = ['index.js']
74
+ let files = fs.readdirSync(this.dir, { withFileTypes: true })
75
+ let ret = []
76
+ for (let val of files) {
77
+ let filepath = '../../plugins/' + val.name
78
+ let tmp = {
79
+ name: val.name
80
+ }
81
+ if (val.isFile()) {
82
+ if (!val.name.endsWith('.js')) continue
83
+ if (ignore.includes(val.name)) continue
84
+ tmp.path = filepath
85
+ ret.push(tmp)
86
+ continue
87
+ }
88
+
89
+ if (fs.existsSync(`${this.dir}/${val.name}/index.js`)) {
90
+ tmp.path = filepath + '/index.js'
91
+ tmp.name = val.name + '/index.js'
92
+ ret.push(tmp)
93
+ continue
94
+ }
95
+
96
+ let apps = fs.readdirSync(`${this.dir}/${val.name}`, { withFileTypes: true })
97
+ for (let app of apps) {
98
+ if (!app.name.endsWith('.js')) continue
99
+ if (ignore.includes(app.name)) continue
100
+
101
+ ret.push({
102
+ name: `${val.name}/${app.name}`,
103
+ path: `../../plugins/${val.name}/${app.name}`
104
+ })
105
+
106
+ continue
107
+ }
108
+ }
109
+
110
+ /** 监听热更新 */
111
+ ret.forEach(v => {
112
+ this.watch(v.name, v.path)
113
+ })
114
+
115
+ return ret
116
+ }
117
+
118
+ async runInit (plugin) {
119
+ plugin.init && plugin.init()
120
+ }
121
+
122
+ packageTips (packageErr) {
123
+ if (!packageErr || packageErr.length <= 0) return
124
+ logger.mark('--------插件载入错误--------')
125
+ packageErr.forEach(v => {
126
+ let pack = v.error.stack.match(/'(.+?)'/g)[0].replace(/'/g, '')
127
+ logger.mark(`${v.File.name} 缺少依赖:${logger.red(pack)}`)
128
+ logger.mark(`请执行安装依赖命令:${logger.red('pnpm add ' + pack + ' -w')}`)
129
+ })
130
+ logger.mark('---------------------')
131
+ }
132
+
133
+ /** 收集定时任务 */
134
+ collectTask (task) {
135
+ if (Array.isArray(task)) {
136
+ task.forEach((val) => {
137
+ if (!val.cron) return
138
+ if (!val.name) throw new Error('插件任务名称错误')
139
+ this.task.push(val)
140
+ })
141
+ } else {
142
+ if (task.fnc && task.cron) {
143
+ if (!task.name) throw new Error('插件任务名称错误')
144
+ this.task.push(task)
145
+ }
146
+ }
147
+ }
148
+
149
+ /** 创建定时任务 */
150
+ creatTask () {
151
+ this.task.forEach((val) => {
152
+ val.job = schedule.scheduleJob(val.cron, async () => {
153
+ try {
154
+ if (val.log === true) {
155
+ logger.mark(`开始定时任务:${val.name}`)
156
+ }
157
+ let res = val.fnc()
158
+ if (util.types.isPromise(res)) res = await res
159
+ if (val.log === true) {
160
+ logger.mark(`定时任务完成:${val.name}`)
161
+ }
162
+ } catch (error) {
163
+ logger.error(`定时任务报错:${val.name}`)
164
+ logger.error(error)
165
+ }
166
+ })
167
+ })
168
+ }
169
+
170
+ /** 监听热更新 */
171
+ watch (appName, appPath) {
172
+ if (this.watcher[`${appName}`]) return
173
+
174
+ let file = `./plugins/${appName}`
175
+ const watcher = chokidar.watch(file)
176
+ let key = appName
177
+
178
+ /** 监听修改 */
179
+ watcher.on('change', async path => {
180
+ logger.mark(`[修改插件][${appName}]`)
181
+
182
+ let tmp = {}
183
+ try {
184
+ tmp = await import(`${appPath}?${moment().format('x')}`)
185
+ } catch (error) {
186
+ logger.error(`载入插件错误:${logger.red(appName)}`)
187
+ logger.error(decodeURI(error.stack))
188
+ return
189
+ }
190
+
191
+ if (tmp.apps) tmp = { ...tmp.apps }
192
+ lodash.forEach(tmp, (p) => {
193
+ /* eslint-disable new-cap */
194
+ let plugin = new p()
195
+ for (let i in this.priority) {
196
+ if (this.priority[i].key == key) {
197
+ this.priority[i].class = p
198
+ this.priority[i].rule = plugin.rule
199
+ }
200
+ }
201
+ })
202
+ })
203
+
204
+ this.watcher[`${appName}`] = watcher
205
+ }
206
+ }
lib/loader/plugin.js ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import YAML from 'yaml'
4
+ import multer from 'multer'
5
+ import rateLimit from 'express-rate-limit'
6
+
7
+ export default class plugin {
8
+ /**
9
+ * @param {string} name 插件名称
10
+ * @param {string} [dsc] 插件描述
11
+ * @param {number} [priority] 插件优先级
12
+ * @param {string} [route] 请求路径前缀
13
+ * @param {string} rule.method 请求方法
14
+ * * rule.method可以是数组,method[ws]属于自定义方法不经过app.handle所以不支持通配符
15
+ * @param {string} rule.path 请求路径
16
+ * * 有route前缀时请求路径=route+rule.path
17
+ * @param {string} [rule.use] 中间件路由
18
+ * * 匹配到的路由会在rule.fnc方法之前按顺序执行一遍rule.use中间件
19
+ * * rule.use是string时fn需要返回中间件函数, rule.use是数组时则直接传入req,res对象
20
+ * @param {string} rule.fnc 请求默认方法
21
+ * * 每个请求都是一个实例,可以打印this查看默认对象
22
+ * * 方法执行完成之前必须结束与客户端的连接
23
+ * * 或者调用next()将控制权交给下一个路由,否则客户端请求会一直处于挂起状态
24
+ */
25
+ constructor (data = {}) {
26
+ /** 插件名称 */
27
+ this.name = data.name || ''
28
+ /** 插件描述 */
29
+ this.dsc = data.dsc || ''
30
+ /** 插件优先级 */
31
+ this.priority = data.priority || 5
32
+ /** 请求路径前缀 */
33
+ this.route = data.route || ''
34
+ /** 路由规则 */
35
+ this.rule = data.rule || []
36
+ /** 定时任务,可以是数组 */
37
+ this.task = {
38
+ /** 任务名 */
39
+ name: '',
40
+ /** 任务方法名 */
41
+ fnc: data.task?.fnc || '',
42
+ /** 任务cron表达式 */
43
+ cron: data.task?.cron || ''
44
+ }
45
+ }
46
+
47
+ /** 读json */
48
+ readJson (filePath, format = 'json') {
49
+ try {
50
+ if (format == 'yaml') {
51
+ return YAML.parse(fs.readFileSync(filePath, 'utf8'))
52
+ }
53
+ return JSON.parse(fs.readFileSync(filePath, 'utf8'))
54
+ } catch (err) {
55
+ return false
56
+ }
57
+ }
58
+
59
+ /** 写json */
60
+ writeJson (savePath, data, format = 'json') {
61
+ this.mkdir(path.dirname(savePath))
62
+ if (format == 'yaml') return fs.writeFileSync(savePath, YAML.stringify(data))
63
+ return fs.writeFileSync(savePath, JSON.stringify(data, null, 2))
64
+ }
65
+
66
+ /** 创建文件夹 */
67
+ mkdir (dirname) {
68
+ if (fs.existsSync(dirname)) {
69
+ return true
70
+ } else {
71
+ if (this.mkdir(path.dirname(dirname))) {
72
+ fs.mkdirSync(dirname)
73
+ return true
74
+ }
75
+ }
76
+ }
77
+
78
+ /** 休眠函数 */
79
+ sleep (ms) {
80
+ return new Promise((resolve) => setTimeout(resolve, ms))
81
+ }
82
+
83
+ /** 速率限制 */
84
+ limiter (limit = 15, cd = 60, options = {}) {
85
+ options = {
86
+ limit,
87
+ windowMs: cd * 1000,
88
+ legacyHeaders: false,
89
+ message: { status: 1, message: 'Frequent requests, please try again later' },
90
+ ...options
91
+ }
92
+ return rateLimit(options)
93
+ }
94
+
95
+ /** 文件上传, single, array, any */
96
+ upload (savaPath = './public/upload', filename, options = {}) {
97
+ options = {
98
+ storage: multer.diskStorage({
99
+ destination: (req, file, cb) => {
100
+ cb(null, savaPath)
101
+ },
102
+ filename: filename || ((req, file, cb) => {
103
+ cb(null, Date.now() + path.extname(file.originalname))
104
+ })
105
+ }),
106
+ limits: { fileSize: 5 * 1024 * 1024, files: 1 },
107
+ ...options
108
+ }
109
+ return multer(options)
110
+ }
111
+
112
+ /** CORS头部 */
113
+ cors () {
114
+ return (req, res, next) => {
115
+ res.set({
116
+ 'Access-Control-Allow-Credentials': true,
117
+ 'Access-Control-Max-Age': 1728000,
118
+ 'Access-Control-Allow-Origin': req.headers.origin || '*',
119
+ 'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type',
120
+ 'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS'
121
+ })
122
+ req.method === 'OPTIONS' ? res.status(204).end() : next()
123
+ }
124
+ }
125
+ }
lib/server.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import './config/init.js'
2
+ import ListenerLoader from './loader/listener.js'
3
+ import cfg from './config/config.js'
4
+ import express from 'express'
5
+
6
+ export default class Server {
7
+ constructor (app) {
8
+ /** Express */
9
+ this.app = app
10
+ this.cfg = cfg
11
+ }
12
+
13
+ static async run () {
14
+ let server = new Server(express())
15
+ await ListenerLoader.create(server).run()
16
+ return server
17
+ }
18
+ }
lib/service/handler.js ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import util from 'node:util'
2
+
3
+ export default class Handler {
4
+ _events = {}
5
+
6
+ add (event, fn, id = 0) {
7
+ if (!event || !fn) {
8
+ return false
9
+ }
10
+ this.del(event, id)
11
+ this._events[event] = this._events[event] || []
12
+ this._events[event].push({ fn, id })
13
+ return true
14
+ }
15
+
16
+ del (event, id = 0) {
17
+ if (!this._events[event]) {
18
+ return false
19
+ } else if (id == 'all') {
20
+ delete this._events[event]
21
+ return true
22
+ } else {
23
+ let idx = this._events[event].findIndex(v => v.id == id)
24
+ if (idx) {
25
+ this._events[event].splice(idx, 1)
26
+ return true
27
+ }
28
+ }
29
+ }
30
+
31
+ async call (key, args, callback) {
32
+ let ret = false
33
+ if (!this._events[key]) {
34
+ callback(ret)
35
+ return ret
36
+ }
37
+ for (let event of this._events[key]) {
38
+ let fn = event.fn
39
+ let done = true
40
+ let reject = (msg = '') => {
41
+ if (msg) {
42
+ logger.error(new Error(msg))
43
+ return
44
+ }
45
+ done = false
46
+ }
47
+ ret = fn(...args, reject)
48
+ if (util.types.isPromise(ret)) {
49
+ ret = await ret
50
+ }
51
+ if (done) {
52
+ callback(ret)
53
+ return ret
54
+ }
55
+ }
56
+ callback(ret)
57
+ return ret
58
+ }
59
+
60
+ has (key) {
61
+ return !!this._events[key]
62
+ }
63
+ }
lib/service/service.js ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import http from 'node:http'
2
+ import https from 'node:https'
3
+
4
+ export default class Service {
5
+ constructor (args) {
6
+ let server = this.run(args)
7
+ server.on('error', this.rejectListen)
8
+ return server
9
+ }
10
+
11
+ run ({ app, cfg }) {
12
+ let { HTTPS, HTTP_TO_HTTPS, HTTP_PORT, PUBLIC_ADDRESS } = cfg.http
13
+ if (!HTTPS) {
14
+ return http.createServer(app)
15
+ } else {
16
+ if (HTTP_TO_HTTPS) {
17
+ http.createServer((req, res) => {
18
+ res.writeHead(307, {
19
+ Location: `${PUBLIC_ADDRESS}${req.url}`
20
+ }).end()
21
+ }).listen(HTTP_PORT)
22
+ }
23
+ return https.createServer(cfg.cert, app)
24
+ }
25
+ }
26
+
27
+ rejectListen (error) {
28
+ let { address, port, syscall } = error
29
+ if (syscall == 'listen' && address && port) {
30
+ logger.error(`服务启动失败: 地址/端口无访问权限或已被占用(${address}:${port})`)
31
+ process.exit()
32
+ } else {
33
+ logger.error(error)
34
+ }
35
+ }
36
+ }
lib/service/util.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export function modifyUrl (url) {
2
+ if (url?.includes('?')) {
3
+ let [baseUrl, query] = url.split('?')
4
+ return `${baseUrl.replace(/\/$/, '')}.websocket?${query}`
5
+ }
6
+ return `${url.replace(/\/$/, '')}.websocket`
7
+ }
8
+
9
+ export function rejectListen (error) {
10
+ let { address, port, syscall } = error
11
+ if (syscall == 'listen' && address && port) {
12
+ logger.error(`服务启动失败: 地址/端口无访问权限或已被占用(${address}:${port})`)
13
+ process.exit()
14
+ } else {
15
+ logger.error(error)
16
+ }
17
+ }
lib/service/websocket.js ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { WebSocketServer } from 'ws'
2
+ import { rejectListen, modifyUrl } from './util.js'
3
+
4
+ export default class WebSocket extends WebSocketServer {
5
+ constructor ({ server, handler }) {
6
+ super({ server })
7
+ this.#handleListen({ handler })
8
+ }
9
+
10
+ #handleListen (args) {
11
+ this.on('error', rejectListen)
12
+ this.on('connection', this.#onConnect.bind(args))
13
+ }
14
+
15
+ #onConnect (socket, request) {
16
+ if ('upgradeReq' in socket) {
17
+ request = socket.upgradeReq
18
+ }
19
+ request.ws = socket
20
+ request.url = modifyUrl(request.url)
21
+ this.handler.call(request.url.split('?')[0], [socket, request], () => {
22
+ if (!request.wsHandled) socket.close()
23
+ })
24
+ }
25
+ }
package.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "GT-Manual",
3
+ "version": "1.1.1",
4
+ "description": "GT-Manual,Server",
5
+ "author": "Hlhs",
6
+ "main": "app.js",
7
+ "type": "module",
8
+ "scripts": {
9
+ "app": "node app.js",
10
+ "start": "pm2 start ./config/pm2/pm2.json",
11
+ "stop": "pm2 stop ./config/pm2/pm2.json",
12
+ "restart": "pm2 restart ./config/pm2/pm2.json",
13
+ "log": "pm2 logs --lines 400 GT-Manual"
14
+ },
15
+ "dependencies": {
16
+ "art-template": "^4.13.2",
17
+ "chalk": "^5.0.1",
18
+ "cheerio": "1.0.0-rc.12",
19
+ "chokidar": "^3.5.3",
20
+ "content-disposition": "^0.5.4",
21
+ "cookie-parser": "^1.4.6",
22
+ "express": "^4.17.1",
23
+ "express-rate-limit": "^7.1.1",
24
+ "lodash": "^4.17.21",
25
+ "log4js": "^6.7.1",
26
+ "md5": "^2.3.0",
27
+ "moment": "^2.29.1",
28
+ "multer": "1.4.5-lts.1",
29
+ "node-fetch": "^2.6.7",
30
+ "node-schedule": "^2.1.1",
31
+ "pm2": "^5.2.0",
32
+ "redis": "^4.5.1",
33
+ "ws": "^8.14.2",
34
+ "yaml": "^2.1.1"
35
+ },
36
+ "devDependencies": {
37
+ "eslint": "^8.55.0",
38
+ "eslint-config-standard": "^17.1.0",
39
+ "eslint-plugin-import": "^2.29.0",
40
+ "eslint-plugin-n": "^16.3.1",
41
+ "eslint-plugin-promise": "^6.1.1"
42
+ }
43
+ }
plugins/example/GTest.js ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import lodash from 'lodash'
2
+
3
+ export class GTest extends plugin {
4
+ constructor () {
5
+ super({
6
+ name: 'GTest',
7
+ dsc: '手动过码',
8
+ route: '/GTest',
9
+ rule: [
10
+ {
11
+ method: 'get',
12
+ path: '/:key',
13
+ fnc: 'index'
14
+ },
15
+ {
16
+ method: 'get',
17
+ path: '/validate/:key',
18
+ fnc: 'result'
19
+ },
20
+ {
21
+ method: 'get',
22
+ path: '/register/:key',
23
+ fnc: 'get_register'
24
+ },
25
+ {
26
+ method: 'post',
27
+ path: '/register',
28
+ fnc: 'register'
29
+ },
30
+ {
31
+ method: 'post',
32
+ path: '/validate/:key',
33
+ fnc: 'validate'
34
+ }
35
+ ]
36
+ })
37
+ }
38
+
39
+ index () {
40
+ let copyright = GTest.cfg.Copyright
41
+ let { key } = this.params
42
+ if (!key || !GTest.users[key]) return this.error('验证信息不存在或已失效。')
43
+ this.render('GTest', { key, copyright })
44
+ }
45
+
46
+ register () {
47
+ let { gt, challenge, key } = this.params
48
+ if (GTest.cfg.REGISTER_KEY && key !== GTest.cfg.REGISTER_KEY) return this._send(null, 'please enter the correct key')
49
+ if (!(gt && challenge)) return this.error()
50
+ key = GTest.randomKey(6, GTest.users, { register: this.params })
51
+ setTimeout(() => delete GTest.users[key], 150000)
52
+ this._send({
53
+ link: `${Server.cfg.http.PUBLIC_ADDRESS}${this.route}/${key}`,
54
+ result: `${Server.cfg.http.PUBLIC_ADDRESS}${this.route}/validate/${key}`
55
+ })
56
+ }
57
+
58
+ async result () {
59
+ let { key } = this.params
60
+ if (!key) return this.error()
61
+ let data = null
62
+ if (GTest.users[key]) {
63
+ for (let i = 0; i < 240; i++) {
64
+ let result = GTest.users[key]?.result
65
+ if (result) {
66
+ data = result
67
+ break
68
+ }
69
+ await this.sleep(500)
70
+ }
71
+ if (!data) data = {}
72
+ delete GTest.users[key]
73
+ }
74
+ this._send(data)
75
+ }
76
+
77
+ /** 浏览器返回Validate */
78
+ validate () {
79
+ let { key } = this.params
80
+ if (!key || !GTest.users[key]) return this.error()
81
+ GTest.users[key].result = this.body
82
+ setTimeout(() => delete GTest.users[key], 30000)
83
+ this._send({})
84
+ logger.info(`[GTest] 验证成功, KEY: ${key}`)
85
+ }
86
+
87
+ /** 浏览器获取gt参数 */
88
+ get_register () {
89
+ let { key } = this.params
90
+ if (!key || !GTest.users[key]) return this.error()
91
+ let info = GTest.users[key].register
92
+ if (!info) return this._send(null, '该验证信息已被使用,若非本人操作请重新获取')
93
+ this.send(info)
94
+ delete GTest.users[key].register
95
+ }
96
+
97
+ _send (data, message = 'OK') {
98
+ return this.send({
99
+ status: Number(!data),
100
+ message,
101
+ data
102
+ })
103
+ }
104
+
105
+ static get cfg () {
106
+ if (!this.users) this.users = {}
107
+ if (!this.clients) this.clients = {}
108
+ return Server.cfg.getConfig('page/GTest', false)
109
+ }
110
+
111
+ static randomKey (length, checkObj, data) {
112
+ let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
113
+ let key = lodash.sampleSize(letters, length).join('')
114
+ while (checkObj[key]) {
115
+ key = lodash.sampleSize(letters, length).join('')
116
+ }
117
+ checkObj[key] = data || {}
118
+ return key
119
+ }
120
+ }
plugins/example/home.js ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export class HomePage extends plugin {
2
+ constructor () {
3
+ super({
4
+ name: 'HomePage',
5
+ rule: [
6
+ {
7
+ method: 'get',
8
+ path: '/',
9
+ fnc: 'home'
10
+ }
11
+ ]
12
+ })
13
+ }
14
+
15
+ /** 站点首页 */
16
+ home () {
17
+ let cfg = Server.cfg.getConfig('page/home', false)
18
+ for (let name of ['socialLinks', 'siteLinks', 'upData']) {
19
+ cfg[name] = this.readJson(`./config/page/home/${name}.json`)
20
+ }
21
+ this.render('index', { cfg })
22
+ }
23
+ }
plugins/example/mysSign.js ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import lodash from 'lodash'
2
+ import { GTest } from './GTest.js'
3
+
4
+ export class MysSign extends plugin {
5
+ constructor () {
6
+ super({
7
+ name: 'mysSign',
8
+ dsc: 'mys签到',
9
+ route: '/mysSign',
10
+ rule: [
11
+ {
12
+ method: 'get',
13
+ path: '/:key',
14
+ fnc: 'index'
15
+ },
16
+ {
17
+ method: ['get', 'post'],
18
+ path: '/:key/:uid',
19
+ fnc: 'bbsSign'
20
+ },
21
+ {
22
+ method: 'ws',
23
+ path: '/',
24
+ fnc: 'connection'
25
+ }
26
+ ]
27
+ })
28
+ }
29
+
30
+ index () {
31
+ let copyright = GTest.cfg.Copyright
32
+ let { key } = this.params
33
+ let user = this.getUser(key)
34
+ if (!user) {
35
+ this.error('UID列表不存在或已失效')
36
+ return
37
+ }
38
+ this.render('mysSign', { key, user, copyright })
39
+ }
40
+
41
+ async bbsSign () {
42
+ let { connect, id, key, uid, validate } = this.params
43
+ if (!validate && this.params['validate[geetest_validate]']) {
44
+ validate = {
45
+ geetest_challenge: this.params['validate[geetest_challenge]'],
46
+ geetest_validate: this.params['validate[geetest_validate]'],
47
+ geetest_seccode: this.params['validate[geetest_seccode]']
48
+ }
49
+ }
50
+ connect = GTest.clients[connect]
51
+ let user = connect?.[key]
52
+ let uidData = user?.uids.find(v => v.uid == uid)
53
+ if (!uidData) {
54
+ this.send({ msg: '签到失败:链接已失效,请重新获取' })
55
+ return
56
+ }
57
+ let data = uidData.status || await connect.self.socketSend('doSign', { id, validate, ...uidData }, `${new Date().getTime()}${uid}`)
58
+ if (!data) {
59
+ data = { msg: '签到失败:请求超时' }
60
+ } else if (data.retcode == 0) {
61
+ uidData.status = { ...data, msg: data.msg.replace('签到成功', '今天已签到') }
62
+ logger.info(`[mysSign] 签到成功, UID: ${uid}`)
63
+ }
64
+ this.send(data)
65
+ }
66
+
67
+ connection () {
68
+ if (GTest.cfg.REGISTER_KEY && this.request.query.key !== GTest.cfg.REGISTER_KEY) return this.close()
69
+ this._wait = this._wait || {}
70
+ this._key = GTest.randomKey(10, GTest.clients)
71
+ this.onClose(() => delete GTest.clients[this._key])
72
+ this.onMessage((data) => {
73
+ try {
74
+ data = JSON.parse(data)
75
+ let { id, cmd, payload } = data
76
+ this._wait[id] ? this._wait[id](payload) : this[cmd] && this[cmd](payload, id)
77
+ } catch (err) {
78
+ logger.error(err)
79
+ }
80
+ })
81
+ }
82
+
83
+ async createUser (data, id) {
84
+ let connect = GTest.clients[this._key]
85
+ if (!connect.self) {
86
+ connect.self = this
87
+ }
88
+ let key = this.hasUser(id)
89
+ if (!key) {
90
+ key = GTest.randomKey(6, connect, { connect: this._key, id, uids: data })
91
+ /** uid缓存10分钟 */
92
+ setTimeout(() => connect && delete connect[key], 600 * 1000)
93
+ }
94
+ let payload = { link: `${Server.cfg.http.PUBLIC_ADDRESS}${this.route}/${key}` }
95
+ this.socketWrite('createUser', payload, id)
96
+ }
97
+
98
+ hasUser (id) {
99
+ let ret = false
100
+ lodash.forEach(GTest.clients, (connect) => {
101
+ lodash.forEach(connect, (user, key) => {
102
+ if (user.id == id) {
103
+ ret = key
104
+ return false
105
+ }
106
+ })
107
+ })
108
+ return ret
109
+ }
110
+
111
+ getUser (key) {
112
+ let ret = false
113
+ if (key) {
114
+ lodash.forEach(GTest.clients, (connect) => {
115
+ if (connect[key]) {
116
+ ret = connect[key]
117
+ return false
118
+ }
119
+ })
120
+ }
121
+ return ret
122
+ }
123
+
124
+ socketWrite (cmd, payload, id) {
125
+ if (!id || (typeof id == 'number' && String(id).length == 13)) id = new Date().getTime()
126
+ return this.socket.send(JSON.stringify({ id, cmd, payload, key: this._key }))
127
+ }
128
+
129
+ socketSend (cmd, payload, id) {
130
+ return new Promise((resolve, reject) => {
131
+ this.socketWrite(cmd, payload, `${id}`)
132
+ this._wait[id] = resolve
133
+ setTimeout(() => resolve(false) && delete this._wait[id], 5 * 1000)
134
+ })
135
+ }
136
+ }
plugins/example/接口示例.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { resolve } from 'node:path'
2
+
3
+ export class example extends plugin {
4
+ constructor () {
5
+ super({
6
+ /** 插件名称 */
7
+ name: 'HelloWorld',
8
+ rule: [
9
+ {
10
+ /** 请求方法 */
11
+ method: 'get',
12
+ /** 请求路径 */
13
+ path: '/hello',
14
+ /** 执行方法 */
15
+ fnc: 'hello'
16
+ }
17
+ ]
18
+ })
19
+ }
20
+
21
+ /** 请求处理 */
22
+ hello () {
23
+ let i = Math.floor(Math.random() * 11 + 1)
24
+ /** 随机返回一张背景图 */
25
+ this.res.sendFile(resolve(`./public/images/background${i}.jpg`))
26
+ }
27
+ }
plugins/hot/index.js ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fs from 'node:fs'
2
+ import lodash from 'lodash'
3
+
4
+ export class DailyHot extends plugin {
5
+ constructor () {
6
+ super({
7
+ /** 插件名称 */
8
+ name: 'DailyHot',
9
+ route: '/hot',
10
+ rule: [
11
+ {
12
+ method: 'get',
13
+ path: '/',
14
+ fnc: 'hotPage'
15
+ },
16
+ {
17
+ method: ['get', 'post'],
18
+ path: '/api/:key',
19
+ fnc: 'hotApi'
20
+ }
21
+ ]
22
+ })
23
+ /* eslint-disable no-throw-literal */
24
+ if (!global.redis) throw { stack: '未启用redis' }
25
+ }
26
+
27
+ async init () {
28
+ if (!DailyHot.provider) {
29
+ DailyHot.provider = {}
30
+ let path = './plugins/hot/provider'
31
+ let files = fs.readdirSync(path).filter(name => name.endsWith('.js') && name !== 'index.js')
32
+ for (let file of files) {
33
+ let module = (await import(`./provider/${file}`)).default
34
+ if (!module.info) continue
35
+ DailyHot.provider[module.info.name] = module
36
+ }
37
+ }
38
+ }
39
+
40
+ hotPage () {
41
+ let cfg = Server.cfg.getConfig('page/home', false)
42
+ this.render('hot', { cfg })
43
+ }
44
+
45
+ /**
46
+ * 通过 '/hot/api'/ + 接口地址 访问hotAPI接口,访问 '/hot/api/all' 可获取全部hot接口信息
47
+ * @param {string} [isNew] 是否从服务器获取最新
48
+ * @param {string} [date] 历史上的今天接口参数,格式 'MMDD'
49
+ */
50
+ async hotApi () {
51
+ await this.init()
52
+ let { key } = this.params
53
+ if (key === 'all') {
54
+ await this.allInfo()
55
+ return
56
+ }
57
+ let provider = DailyHot.provider[key]
58
+ if (!provider) return this.next()
59
+ let body = await provider.get(this.params)
60
+ this.send({
61
+ status: Number(body.code !== 200),
62
+ message: body.message,
63
+ data: {
64
+ ...provider.info,
65
+ updateTime: provider.updateTime,
66
+ from: body.from,
67
+ total: body.data.length || 0,
68
+ list: body.data
69
+ }
70
+ }, body.code)
71
+ }
72
+
73
+ allInfo () {
74
+ let data = []
75
+ lodash.forEach(DailyHot.provider, (ds, name) => {
76
+ data.push({
77
+ ...ds.info,
78
+ path: `/${name}`
79
+ })
80
+ })
81
+ this.send({
82
+ status: 0,
83
+ message: '获取成功',
84
+ data
85
+ })
86
+ }
87
+ }