wiki-plugin-mech 0.1.18 → 0.1.19
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/client/mech.js +2 -2
- package/package.json +1 -1
- package/server/server.js +34 -8
package/client/mech.js
CHANGED
|
@@ -522,7 +522,7 @@
|
|
|
522
522
|
const site = state.context.site
|
|
523
523
|
const slug = state.context.slug
|
|
524
524
|
const itemId = state.context.itemId
|
|
525
|
-
const query = `
|
|
525
|
+
const query = `mech=${btoa(JSON.stringify(body))}`
|
|
526
526
|
const url = `//${site}/plugin/mech/run/${slug}/${itemId}?${query}`
|
|
527
527
|
elem.innerHTML = command + ` ⇒ in progress`
|
|
528
528
|
const start = Date.now()
|
|
@@ -534,7 +534,7 @@
|
|
|
534
534
|
return trouble(elem,`RUN failed with "${err.message}"`)
|
|
535
535
|
}
|
|
536
536
|
state.result = result
|
|
537
|
-
for(const arg of result.
|
|
537
|
+
for(const arg of result.mech.flat(9)){
|
|
538
538
|
const elem = document.getElementById(arg.key)
|
|
539
539
|
if('status' in arg) elem.innerHTML = arg.command + ` ⇒ ${arg.status}`
|
|
540
540
|
if('trouble' in arg) trouble(elem,arg.trouble)
|
package/package.json
CHANGED
package/server/server.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
(function() {
|
|
6
6
|
|
|
7
7
|
const fs = require('fs')
|
|
8
|
+
const path = require('path')
|
|
8
9
|
const process = require('process')
|
|
9
10
|
|
|
10
11
|
function startServer(params) {
|
|
@@ -16,17 +17,16 @@
|
|
|
16
17
|
try {
|
|
17
18
|
const slug = req.params.slug
|
|
18
19
|
const itemId = req.params.itemId
|
|
19
|
-
const
|
|
20
|
-
const path = `${argv.db}/${slug}`
|
|
20
|
+
const mech = JSON.parse(atob(req.query.mech || 'W10='))
|
|
21
21
|
// fs.readFile(path,(err,data) => {
|
|
22
22
|
// const page = JSON.parse(data)
|
|
23
23
|
// const item = page.story.find(item => item.id == itemId) || null
|
|
24
|
-
// return res.json({err,item,
|
|
24
|
+
// return res.json({err,item,mech});
|
|
25
25
|
// })
|
|
26
|
-
const context = {
|
|
27
|
-
const state = {context
|
|
28
|
-
run(
|
|
29
|
-
.then(() => {return res.json({
|
|
26
|
+
const context = {argv,slug}
|
|
27
|
+
const state = {context}
|
|
28
|
+
run(mech,state)
|
|
29
|
+
.then(() => {delete state.context; return res.json({mech,state})})
|
|
30
30
|
.catch(err => {console.log(err); return res.json({err:err.message+' from promise'})})
|
|
31
31
|
} catch(err) {
|
|
32
32
|
return res.json({err:err.message+' from try'})
|
|
@@ -98,13 +98,39 @@
|
|
|
98
98
|
})
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
async function commons_emit ({elem,args,state}) {
|
|
102
|
+
const readdir = dir => new Promise((res,rej) =>
|
|
103
|
+
fs.readdir(dir,(e,v) => e ? rej(e) : res(v)));
|
|
104
|
+
const stat = file => new Promise((res,rej) =>
|
|
105
|
+
fs.stat(file,(e,v) => e ? rej(e) : res(v)));
|
|
106
|
+
const tally = async dir => {
|
|
107
|
+
const count = {files:0,bytes:0}
|
|
108
|
+
const items = await readdir(dir)
|
|
109
|
+
for(const item of items) {
|
|
110
|
+
const itemPath = path.join(dir, item)
|
|
111
|
+
const stats = await stat(itemPath)
|
|
112
|
+
if (state.debug) console.log({itemPath,stats})
|
|
113
|
+
if (stats.isFile()) {
|
|
114
|
+
count.files++
|
|
115
|
+
count.bytes+=stats.size
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return count
|
|
119
|
+
}
|
|
120
|
+
const all = await tally(state.context.argv.commons)
|
|
121
|
+
const here = await tally(path.join(state.context.argv.data,'assets','plugins','image'))
|
|
122
|
+
state.commons = {all,here}
|
|
123
|
+
status(elem,`${(all.bytes/1000000).toFixed(3)} mb in ${all.files} files`)
|
|
124
|
+
}
|
|
125
|
+
|
|
101
126
|
|
|
102
127
|
// C A T A L O G
|
|
103
128
|
|
|
104
129
|
const blocks = {
|
|
105
130
|
HELLO: {emit:hello_emit},
|
|
106
131
|
UPTIME: {emit:uptime_emit},
|
|
107
|
-
SLEEP: {emit:sleep_emit}
|
|
132
|
+
SLEEP: {emit:sleep_emit},
|
|
133
|
+
COMMONS: {emit:commons_emit}
|
|
108
134
|
}
|
|
109
135
|
|
|
110
136
|
|