verteilen-core 1.3.21 → 1.3.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/analysis.js +6 -8
- package/dist/client/client.d.ts +2 -2
- package/dist/client/client.js +1 -1
- package/dist/client/job_execute.d.ts +2 -2
- package/dist/interface/base.d.ts +9 -6
- package/dist/interface/base.js +10 -1
- package/dist/interface/bus.d.ts +2 -5
- package/dist/interface/execute.d.ts +1 -1
- package/dist/interface/log.d.ts +51 -0
- package/dist/interface/log.js +2 -0
- package/dist/interface/plugin.d.ts +79 -0
- package/dist/interface/plugin.js +2 -0
- package/dist/interface/record.d.ts +0 -49
- package/dist/interface/struct.d.ts +2 -80
- package/dist/interface/table.d.ts +2 -1
- package/dist/interface.d.ts +4 -2
- package/dist/interface.js +4 -2
- package/dist/lan/en.json +7 -2
- package/dist/lan/zh_TW.json +7 -2
- package/dist/plugins/i18n.d.ts +20 -0
- package/dist/server/detail/console_handle.d.ts +20 -0
- package/dist/server/detail/console_handle.js +244 -0
- package/dist/server/detail/log_handle.d.ts +23 -0
- package/dist/server/detail/log_handle.js +224 -0
- package/dist/server/detail.d.ts +6 -4
- package/dist/server/detail.js +54 -52
- package/dist/server/plugin.d.ts +3 -5
- package/dist/server/plugin.js +68 -158
- package/dist/server/server.js +0 -1
- package/package.json +1 -1
- package/src/client/analysis.ts +10 -12
- package/src/client/client.ts +3 -3
- package/src/client/cluster.ts +2 -2
- package/src/client/job_execute.ts +3 -3
- package/src/interface/base.ts +19 -7
- package/src/interface/bus.ts +2 -5
- package/src/interface/execute.ts +1 -1
- package/src/interface/log.ts +63 -0
- package/src/interface/plugin.ts +247 -0
- package/src/interface/record.ts +0 -62
- package/src/interface/struct.ts +2 -112
- package/src/interface/table.ts +2 -1
- package/src/interface.ts +4 -2
- package/src/lan/en.json +7 -2
- package/src/lan/zh_TW.json +7 -2
- package/src/{util → server/detail}/console_handle.ts +3 -3
- package/src/{util → server/detail}/log_handle.ts +2 -2
- package/src/server/detail.ts +74 -60
- package/src/server/io.ts +3 -0
- package/src/server/plugin.ts +118 -166
- package/src/server/server.ts +0 -1
package/src/server/plugin.ts
CHANGED
|
@@ -8,20 +8,18 @@ import {
|
|
|
8
8
|
Header,
|
|
9
9
|
DatabaseContainer,
|
|
10
10
|
Plugin,
|
|
11
|
-
|
|
11
|
+
PluginContainer,
|
|
12
12
|
PluginPageData,
|
|
13
13
|
PluginWithToken,
|
|
14
|
-
Project,
|
|
15
|
-
TemplateData,
|
|
16
|
-
TemplateDataDatabase,
|
|
17
|
-
TemplateDataProject,
|
|
18
|
-
TemplateGroup,
|
|
19
|
-
TemplateGroup2,
|
|
14
|
+
Project,
|
|
20
15
|
ToastData,
|
|
21
16
|
WebsocketPack
|
|
22
17
|
} from "../interface";
|
|
23
18
|
import { PluginFeedback } from "./server";
|
|
24
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Get socket from websocket client method
|
|
22
|
+
*/
|
|
25
23
|
export type SocketGetter = (uuid:string) => WebsocketPack | undefined
|
|
26
24
|
|
|
27
25
|
/**
|
|
@@ -29,15 +27,52 @@ export type SocketGetter = (uuid:string) => WebsocketPack | undefined
|
|
|
29
27
|
* Use for access the plugin store function
|
|
30
28
|
*/
|
|
31
29
|
export interface PluginLoader {
|
|
30
|
+
/**
|
|
31
|
+
* Loading all plugins
|
|
32
|
+
*/
|
|
32
33
|
load_all: () => Promise<PluginPageData>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Loading plugins from cache
|
|
36
|
+
*/
|
|
37
|
+
get_plugins: () => Promise<PluginPageData>
|
|
38
|
+
/**
|
|
39
|
+
* Get project template
|
|
40
|
+
* @param name Plugin name
|
|
41
|
+
* @param group Group search
|
|
42
|
+
* @param filename Template filename
|
|
43
|
+
*/
|
|
44
|
+
get_project: (name:string, group:string, filename:string) => string | undefined
|
|
45
|
+
/**
|
|
46
|
+
* Get database template
|
|
47
|
+
* @param name Plugin name
|
|
48
|
+
* @param group Group search
|
|
49
|
+
* @param filename Template filename
|
|
50
|
+
*/
|
|
51
|
+
get_database: (name:string, group:string, filename:string) => string | undefined
|
|
52
|
+
/**
|
|
53
|
+
* Import plugin from web
|
|
54
|
+
* @param name Plugin name
|
|
55
|
+
* @param url The URL for plugin manifest
|
|
56
|
+
* @param token Token list, use space to seperate
|
|
57
|
+
*/
|
|
37
58
|
import_plugin: (name:string, url:string, token:string) => Promise<PluginPageData>
|
|
38
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Delete plugin by name
|
|
61
|
+
* @param name Plugin name
|
|
62
|
+
*/
|
|
39
63
|
delete_plugin: (name:string) => Promise<void>
|
|
64
|
+
/**
|
|
65
|
+
* Telling node Download plugin
|
|
66
|
+
* @param uuid Node ID
|
|
67
|
+
* @param plugin Plugin name
|
|
68
|
+
* @param token Token list, use space to seperate
|
|
69
|
+
*/
|
|
40
70
|
plugin_download: (uuid:string, plugin:string, tokens:string) => Promise<void>
|
|
71
|
+
/**
|
|
72
|
+
* Telling node Remove plugin
|
|
73
|
+
* @param uuid Node ID
|
|
74
|
+
* @param plugin Plugin name
|
|
75
|
+
*/
|
|
41
76
|
plugin_remove: (uuid:string, plugin:string) => Promise<void>
|
|
42
77
|
}
|
|
43
78
|
|
|
@@ -49,50 +84,42 @@ export interface PluginLoader {
|
|
|
49
84
|
export const GetCurrentPlugin = async (loader:RecordIOBase):Promise<PluginPageData> => {
|
|
50
85
|
return new Promise<PluginPageData>(async (resolve) => {
|
|
51
86
|
const b:PluginPageData = {
|
|
52
|
-
plugins: []
|
|
53
|
-
templates: []
|
|
87
|
+
plugins: []
|
|
54
88
|
}
|
|
55
|
-
const root = loader.join(loader.root, '
|
|
56
|
-
const root2 = loader.join(loader.root, 'plugin')
|
|
89
|
+
const root = loader.join(loader.root, 'plugin')
|
|
57
90
|
if(!loader.exists(root)) await loader.mkdir(root)
|
|
58
|
-
if(!loader.exists(root2)) await loader.mkdir(root2)
|
|
59
91
|
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
92
|
+
const plugin_folder = await loader.read_dir_dir(root)
|
|
93
|
+
const plugin_folder_files = await Promise.all(plugin_folder.map(x => loader.read_dir_file(x)))
|
|
94
|
+
for(let i = 0; i < plugin_folder_files.length; i++){
|
|
95
|
+
const files = plugin_folder_files[i]
|
|
96
|
+
const dirname = plugin_folder[i]
|
|
97
|
+
if(!files.includes("manifest.json")) continue
|
|
98
|
+
|
|
99
|
+
const manifest_path = loader.join(root, dirname, "manifest.json")
|
|
100
|
+
const manifest = await loader.read_string(manifest_path)
|
|
101
|
+
let header:PluginContainer | undefined = undefined
|
|
102
|
+
try{
|
|
103
|
+
header = JSON.parse(manifest)
|
|
104
|
+
}catch(e:any){
|
|
105
|
+
console.warn(`Reading file error: ${manifest_path}`)
|
|
106
|
+
continue
|
|
107
|
+
}
|
|
108
|
+
if(header == undefined) continue
|
|
109
|
+
header.gen_projects = header.projects.map(x => ({
|
|
66
110
|
value: -1,
|
|
67
111
|
group: x.group,
|
|
68
112
|
filename: x.filename,
|
|
69
113
|
title: x.title
|
|
70
114
|
}))
|
|
71
|
-
|
|
115
|
+
header.gen_databases = header.databases.map(x => ({
|
|
72
116
|
value: -1,
|
|
73
117
|
group: x.group,
|
|
74
118
|
filename: x.filename,
|
|
75
119
|
title: x.title
|
|
76
120
|
}))
|
|
77
|
-
b.templates.push({
|
|
78
|
-
name: files[index].replace('.json', ''),
|
|
79
|
-
project: ps,
|
|
80
|
-
database: ps2,
|
|
81
|
-
url: config.url
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
121
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const p_config2 = files2.map(file => {
|
|
88
|
-
return loader.read_string(loader.join(root2, file), { encoding: 'utf-8' })
|
|
89
|
-
})
|
|
90
|
-
const configs2:Array<PluginList> = (await Promise.all(p_config2)).map(x => JSON.parse(x))
|
|
91
|
-
|
|
92
|
-
for(let index = 0; index < configs2.length; index++){
|
|
93
|
-
const config = configs2[index]
|
|
94
|
-
config.title = files2[index].replace('.json', '')
|
|
95
|
-
b.plugins.push(config)
|
|
122
|
+
b.plugins.push(header)
|
|
96
123
|
}
|
|
97
124
|
resolve(b)
|
|
98
125
|
return b
|
|
@@ -103,75 +130,62 @@ export const CreatePluginLoader = (loader:RecordIOBase, memory:PluginPageData, s
|
|
|
103
130
|
return {
|
|
104
131
|
load_all: async ():Promise<PluginPageData> => {
|
|
105
132
|
const cp = await GetCurrentPlugin(loader)
|
|
106
|
-
memory.templates = cp.templates
|
|
107
133
|
memory.plugins = cp.plugins
|
|
108
134
|
return cp
|
|
109
135
|
},
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
let result:string | undefined = undefined
|
|
113
|
-
for(let x of memory.templates){
|
|
114
|
-
for(let y of x.project){
|
|
115
|
-
if(y.group == group && y.filename == filename){
|
|
116
|
-
result = JSON.stringify(y)
|
|
117
|
-
find = true
|
|
118
|
-
break
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if(find) break
|
|
122
|
-
}
|
|
123
|
-
return result
|
|
136
|
+
get_plugins: async ():Promise<PluginPageData> => {
|
|
137
|
+
return memory
|
|
124
138
|
},
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
result = JSON.stringify(y)
|
|
132
|
-
find = true
|
|
133
|
-
break
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if(find) break
|
|
137
|
-
}
|
|
138
|
-
return result
|
|
139
|
+
get_project: (name:string, group:string, filename:string):string | undefined => {
|
|
140
|
+
const plugin = memory.plugins.find(x => x.title == name)
|
|
141
|
+
if(plugin == undefined) return undefined
|
|
142
|
+
const result = plugin.projects.find(x => x.group == group && x.filename == filename)
|
|
143
|
+
if(result == undefined) return undefined
|
|
144
|
+
return JSON.stringify(result)
|
|
139
145
|
},
|
|
140
|
-
|
|
141
|
-
|
|
146
|
+
get_database: (name:string, group:string, filename:string):string | undefined => {
|
|
147
|
+
const plugin = memory.plugins.find(x => x.title == name)
|
|
148
|
+
if(plugin == undefined) return undefined
|
|
149
|
+
const result = plugin.databases.find(x => x.group == group && x.filename == filename)
|
|
150
|
+
if(result == undefined) return undefined
|
|
151
|
+
return JSON.stringify(result)
|
|
142
152
|
},
|
|
143
|
-
|
|
144
|
-
const root = loader.join(loader.root, 'template')
|
|
153
|
+
import_plugin: async (name:string, url:string, token:string):Promise<PluginPageData> => {
|
|
145
154
|
const error_children:Array<[string, string]> = []
|
|
155
|
+
const root = loader.join(loader.root, 'plugin')
|
|
156
|
+
const project_folder = loader.join(root, name, 'project')
|
|
157
|
+
const database_folder = loader.join(root, name, 'database')
|
|
158
|
+
if (!loader.exists(root)) await loader.mkdir(root);
|
|
159
|
+
if (!loader.exists(project_folder)) await loader.mkdir(project_folder)
|
|
160
|
+
if (!loader.exists(database_folder)) await loader.mkdir(database_folder)
|
|
161
|
+
// Trying no token first
|
|
146
162
|
const tokens = [undefined, ...token.split(' ')]
|
|
147
|
-
const content_folder = loader.join(root, name)
|
|
148
|
-
const project_folder = loader.join(content_folder, 'project')
|
|
149
|
-
const database_folder = loader.join(content_folder, 'database')
|
|
150
|
-
if (!loader.exists(root)) await loader.mkdir(root)
|
|
151
163
|
let req:RequestInit = {}
|
|
152
|
-
let ob:
|
|
164
|
+
let ob:PluginContainer | undefined = undefined
|
|
153
165
|
for(let t of tokens){
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
// Do not store cache
|
|
167
|
+
// Even tho, some website have it's own CDN policy, You might still get old data
|
|
168
|
+
// But most of them only sustained couple minutes
|
|
169
|
+
req = t == undefined ? { method: 'GET', cache: "no-store" } : {
|
|
170
|
+
method: 'GET',
|
|
171
|
+
cache: "no-store",
|
|
172
|
+
headers: {
|
|
173
|
+
"Authorization": t ? `Bearer ${t}` : ''
|
|
174
|
+
}}
|
|
175
|
+
// Get data
|
|
176
|
+
let tex = ""
|
|
165
177
|
try{
|
|
166
178
|
const res = await fetch(url, req)
|
|
167
|
-
|
|
179
|
+
tex = await res.text()
|
|
168
180
|
ob = JSON.parse(tex)
|
|
181
|
+
console.log("Fetch plugin json successfully")
|
|
169
182
|
break
|
|
170
183
|
}catch (error){
|
|
171
|
-
console.
|
|
184
|
+
console.warn(error, tex)
|
|
172
185
|
}
|
|
173
186
|
}
|
|
174
187
|
if(ob == undefined) {
|
|
188
|
+
// Query data failed
|
|
175
189
|
const p:ToastData = { title: "Import Failed", type: "error", message: `Cannot find the json from url ${url}, or maybe just the wrong token` }
|
|
176
190
|
const h:Header = { name: "makeToast", data: JSON.stringify(p) }
|
|
177
191
|
if (feedback.electron){
|
|
@@ -181,19 +195,14 @@ export const CreatePluginLoader = (loader:RecordIOBase, memory:PluginPageData, s
|
|
|
181
195
|
feedback.socket(JSON.stringify(h))
|
|
182
196
|
}
|
|
183
197
|
return memory
|
|
184
|
-
}
|
|
198
|
+
}
|
|
185
199
|
ob.url = url
|
|
186
|
-
loader.write_string(loader.join(root, name
|
|
187
|
-
if(!loader.exists(content_folder)) loader.mkdir(content_folder)
|
|
188
|
-
if(!loader.exists(project_folder)) loader.mkdir(project_folder)
|
|
189
|
-
if(!loader.exists(database_folder)) loader.mkdir(database_folder)
|
|
190
|
-
const folder = url.substring(0, url.lastIndexOf('/'))
|
|
191
|
-
const project_calls:Array<Promise<Response>> = []
|
|
192
|
-
const database_calls:Array<Promise<Response>> = []
|
|
200
|
+
loader.write_string(loader.join(root, name, 'manifest.json'), JSON.stringify(ob, null, 4))
|
|
193
201
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
202
|
+
const folder = url.substring(0, url.lastIndexOf('/'))
|
|
203
|
+
const project_calls:Array<Promise<Response>> = ob.projects.map(p => fetch(folder + "/" + p.filename + '.json', req))
|
|
204
|
+
const database_calls:Array<Promise<Response>> = ob.databases.map(p => fetch(folder + "/" + p.filename + '.json', req))
|
|
205
|
+
// * Project template query
|
|
197
206
|
const pss = await Promise.all(project_calls)
|
|
198
207
|
const project_calls2:Array<Promise<string>> = pss.map(x => x.text())
|
|
199
208
|
const pss_result = await Promise.all(project_calls2)
|
|
@@ -207,10 +216,7 @@ export const CreatePluginLoader = (loader:RecordIOBase, memory:PluginPageData, s
|
|
|
207
216
|
error_children.push([`Import Project ${n} Error`, error.message])
|
|
208
217
|
}
|
|
209
218
|
})
|
|
210
|
-
|
|
211
|
-
ob.databases.forEach((p:TemplateDataDatabase) => {
|
|
212
|
-
database_calls.push(fetch(folder + "/" + p.filename + '.json', req))
|
|
213
|
-
})
|
|
219
|
+
// * Database template query
|
|
214
220
|
const pss2 = await Promise.all(database_calls)
|
|
215
221
|
const database_calls2:Array<Promise<string>> = pss2.map(x => x.text())
|
|
216
222
|
const pss_result2 = await Promise.all(database_calls2)
|
|
@@ -235,69 +241,15 @@ export const CreatePluginLoader = (loader:RecordIOBase, memory:PluginPageData, s
|
|
|
235
241
|
}
|
|
236
242
|
return memory
|
|
237
243
|
}
|
|
244
|
+
|
|
238
245
|
const cp = await GetCurrentPlugin(loader)
|
|
239
|
-
memory.templates = cp.templates
|
|
240
|
-
memory.plugins = cp.plugins
|
|
241
|
-
return cp
|
|
242
|
-
},
|
|
243
|
-
import_plugin: async (name:string, url:string, token:string):Promise<PluginPageData> => {
|
|
244
|
-
const root = loader.join(loader.root, 'plugin')
|
|
245
|
-
const tokens = [undefined, ...token.split(' ')]
|
|
246
|
-
if (!loader.exists(root)) await loader.mkdir(root);
|
|
247
|
-
let req:RequestInit = {}
|
|
248
|
-
let ob:PluginList | undefined = undefined
|
|
249
|
-
for(let t of tokens){
|
|
250
|
-
if(t == undefined){
|
|
251
|
-
req = { method: 'GET', cache: "no-store" }
|
|
252
|
-
}else{
|
|
253
|
-
req = {
|
|
254
|
-
method: 'GET',
|
|
255
|
-
cache: "no-store",
|
|
256
|
-
headers: {
|
|
257
|
-
"Authorization": t ? `Bearer ${t}` : ''
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
let tex = ""
|
|
262
|
-
try{
|
|
263
|
-
const res = await fetch(url, req)
|
|
264
|
-
tex = await res.text()
|
|
265
|
-
ob = JSON.parse(tex)
|
|
266
|
-
console.log("Fetch plugin json successfully")
|
|
267
|
-
break
|
|
268
|
-
}catch (error){
|
|
269
|
-
console.warn(error, tex)
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if(ob == undefined) {
|
|
273
|
-
const p:ToastData = { title: "Import Failed", type: "error", message: `Cannot find the json from url ${url}, or maybe just the wrong token` }
|
|
274
|
-
const h:Header = { name: "makeToast", data: JSON.stringify(p) }
|
|
275
|
-
if (feedback.electron){
|
|
276
|
-
feedback.electron()?.send("makeToast", JSON.stringify(p))
|
|
277
|
-
}
|
|
278
|
-
if (feedback.socket){
|
|
279
|
-
feedback.socket(JSON.stringify(h))
|
|
280
|
-
}
|
|
281
|
-
return memory
|
|
282
|
-
}
|
|
283
|
-
ob.url = url
|
|
284
|
-
loader.write_string(loader.join(root, name + '.json'), JSON.stringify(ob, null, 4))
|
|
285
|
-
const cp = await GetCurrentPlugin(loader)
|
|
286
|
-
memory.templates = cp.templates
|
|
287
246
|
memory.plugins = cp.plugins
|
|
288
247
|
return cp
|
|
289
248
|
},
|
|
290
|
-
delete_template: async (name:string):Promise<void> => {
|
|
291
|
-
const root = loader.join(loader.root, 'template')
|
|
292
|
-
if(loader.exists(loader.join(root, name + '.json')))
|
|
293
|
-
await loader.rm(loader.join(root, name + '.json'));
|
|
294
|
-
if(loader.exists(loader.join(root, name)))
|
|
295
|
-
await loader.rm(loader.join(root, name));
|
|
296
|
-
},
|
|
297
249
|
delete_plugin: async (name:string):Promise<void> => {
|
|
298
|
-
const root = loader.join(loader.root, 'plugin')
|
|
299
|
-
if(loader.exists(
|
|
300
|
-
await loader.rm(
|
|
250
|
+
const root = loader.join(loader.root, 'plugin', name)
|
|
251
|
+
if(loader.exists(root))
|
|
252
|
+
await loader.rm(root);
|
|
301
253
|
},
|
|
302
254
|
plugin_download: async (uuid:string, plugin:string, tokens:string):Promise<void> => {
|
|
303
255
|
const p:Plugin = JSON.parse(plugin)
|