pinokiod 2.1.25 → 2.1.27
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/kernel/api/fs/index.js +11 -0
- package/kernel/index.js +1 -1
- package/kernel/util.js +21 -2
- package/package.json +1 -1
- package/server/index.js +16 -6
- package/server/public/opener.js +15 -1
- package/server/views/browser-experimental.ejs +2 -0
- package/server/views/partials/menu.ejs +4 -0
package/kernel/api/fs/index.js
CHANGED
|
@@ -54,6 +54,17 @@ class FS {
|
|
|
54
54
|
// await decompress(...req.params)
|
|
55
55
|
// }
|
|
56
56
|
|
|
57
|
+
async open(req, ondata, kernel) {
|
|
58
|
+
/*
|
|
59
|
+
params := {
|
|
60
|
+
path: <filepath>,
|
|
61
|
+
}
|
|
62
|
+
open finder/file explorer at path
|
|
63
|
+
*/
|
|
64
|
+
let dirPath = path.resolve(req.cwd, req.params.path)
|
|
65
|
+
ondata({ raw: `\r\nopening path: ${dirPath}\r\n` })
|
|
66
|
+
Util.openfs(dirPath)
|
|
67
|
+
}
|
|
57
68
|
|
|
58
69
|
async link(req, ondata, kernel) {
|
|
59
70
|
let response = await this.share(req, ondata, kernel)
|
package/kernel/index.js
CHANGED
package/kernel/util.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
|
+
const os = require('os')
|
|
2
3
|
const path = require('path')
|
|
3
4
|
const dotenv = require('dotenv')
|
|
4
|
-
|
|
5
|
+
const child_process = require('node:child_process');
|
|
5
6
|
const {auto: normalizeEOL} = require("eol");
|
|
6
7
|
const {EOL} = require("os");
|
|
7
8
|
const breakPattern = /\n/g;
|
|
@@ -21,6 +22,24 @@ const parse_env = async (filename) => {
|
|
|
21
22
|
return {}
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
const openfs = (dirPath) => {
|
|
26
|
+
let command = '';
|
|
27
|
+
const platform = os.platform()
|
|
28
|
+
switch (platform) {
|
|
29
|
+
case 'darwin':
|
|
30
|
+
command = 'open';
|
|
31
|
+
break;
|
|
32
|
+
case 'win32':
|
|
33
|
+
command = 'explorer';
|
|
34
|
+
break;
|
|
35
|
+
default:
|
|
36
|
+
command = 'xdg-open';
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
let c = `${command} "${dirPath}"`
|
|
40
|
+
console.log(c)
|
|
41
|
+
child_process.exec(c)
|
|
42
|
+
}
|
|
24
43
|
|
|
25
44
|
const parse_env_detail = async (filename) => {
|
|
26
45
|
// takes env and returns an array
|
|
@@ -123,5 +142,5 @@ const update_env = async (filepath, changes) => {
|
|
|
123
142
|
await fs.promises.writeFile(filepath, newval)
|
|
124
143
|
};
|
|
125
144
|
module.exports = {
|
|
126
|
-
parse_env, api_path, update_env, parse_env_detail
|
|
145
|
+
parse_env, api_path, update_env, parse_env_detail, openfs
|
|
127
146
|
}
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -1281,11 +1281,16 @@ class Server {
|
|
|
1281
1281
|
if (menuitem.href && !menuitem.href.startsWith("http")) {
|
|
1282
1282
|
|
|
1283
1283
|
// href resolution
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1284
|
+
if (menuitem.fs) {
|
|
1285
|
+
// file explorer
|
|
1286
|
+
config.menu[i].href = path.resolve(this.kernel.homedir, "api", name, menuitem.href)
|
|
1287
|
+
} else {
|
|
1288
|
+
let absolute = path.resolve(__dirname, ...pathComponents, menuitem.href)
|
|
1289
|
+
let seed = path.resolve(__dirname)
|
|
1290
|
+
let p = absolute.replace(seed, "")
|
|
1291
|
+
let link = p.split(/[\/\\]/).filter((x) => { return x }).join("/")
|
|
1292
|
+
config.menu[i].href = "/api/" + name + "/" + link
|
|
1293
|
+
}
|
|
1289
1294
|
}
|
|
1290
1295
|
}
|
|
1291
1296
|
|
|
@@ -1307,7 +1312,6 @@ class Server {
|
|
|
1307
1312
|
menuitem.src = u.pathname
|
|
1308
1313
|
}
|
|
1309
1314
|
|
|
1310
|
-
|
|
1311
1315
|
// check running
|
|
1312
1316
|
let fullpath = this.kernel.path(menuitem.src.slice(1))
|
|
1313
1317
|
if (this.kernel.api.running[fullpath]) {
|
|
@@ -2099,6 +2103,12 @@ class Server {
|
|
|
2099
2103
|
// }
|
|
2100
2104
|
}))
|
|
2101
2105
|
|
|
2106
|
+
this.app.post("/openfs", ex(async (req, res) => {
|
|
2107
|
+
console.log("openfs", req.body.path)
|
|
2108
|
+
Util.openfs(req.body.path)
|
|
2109
|
+
res.json({ success: true })
|
|
2110
|
+
}))
|
|
2111
|
+
|
|
2102
2112
|
this.app.post("/unpublish", ex(async (req, res) => {
|
|
2103
2113
|
/*
|
|
2104
2114
|
req.body := {
|
package/server/public/opener.js
CHANGED
|
@@ -7,9 +7,23 @@ document.addEventListener("click", async (e) => {
|
|
|
7
7
|
el = e.target
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
+
console.log({ el })
|
|
10
11
|
if (el) {
|
|
11
12
|
let filepath = el.getAttribute("data-filepath")
|
|
12
|
-
|
|
13
|
+
console.log("filepath", filepath)
|
|
14
|
+
await fetch("/openfs", {
|
|
15
|
+
method: "post",
|
|
16
|
+
headers: {
|
|
17
|
+
"Content-Type": "application/json"
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
path: filepath
|
|
21
|
+
})
|
|
22
|
+
}).then((res) => {
|
|
23
|
+
return res.json()
|
|
24
|
+
})
|
|
25
|
+
// let filepath = el.getAttribute("data-filepath")
|
|
26
|
+
// window.open("about:blank", "_blank", "file://" + filepath)
|
|
13
27
|
return
|
|
14
28
|
}
|
|
15
29
|
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
<div <%=item.default ? 'data-default' : ''%> data-action="<%=JSON.stringify(item.action)%>" class='btn header-item frame-link'>
|
|
15
15
|
<div class='tab'><%-item.btn%></div>
|
|
16
16
|
</div>
|
|
17
|
+
<% } else if (item.fs) { %>
|
|
18
|
+
<div data-filepath="<%=item.href%>" class='btn header-item frame-link'>
|
|
19
|
+
<div class='tab'><%-item.btn%></div>
|
|
20
|
+
</div>
|
|
17
21
|
<% } else if (item.target === "_blank") { %>
|
|
18
22
|
<a <%=item.default ? 'data-default' : ''%> data-confirm="<%=item.confirm%>" data-index="<%=index%>" target="<%=item.target%>" data-mode="<%=item.mode%>" href="<%=item.href%>" class='btn header-item frame-link'>
|
|
19
23
|
<div class='tab'><%-item.btn%></div>
|