pinokiod 1.2.52 → 1.2.54

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.
@@ -19,7 +19,8 @@ class FS {
19
19
  }
20
20
  */
21
21
  let cwd = (req.cwd ? req.cwd : kernel.api.userdir)
22
- let filepath = path.resolve(cwd, req.params.path)
22
+ let filepath = kernel.api.filePath(req.params.path, cwd)
23
+ //let filepath = path.resolve(cwd, req.params.path)
23
24
  let data = await fs.promises.readFile(filepath, req.params.encoding)
24
25
  return data
25
26
  }
@@ -252,7 +253,8 @@ class FS {
252
253
  }
253
254
  async rm(req, ondata, kernel) {
254
255
  let cwd = (req.cwd ? req.cwd : kernel.api.userdir)
255
- let filepath = path.resolve(cwd, req.params.path)
256
+ //let filepath = path.resolve(cwd, req.params.path)
257
+ let filepath = kernel.api.filePath(req.params.path, cwd)
256
258
  // await fs.promises.rm(filepath)
257
259
  ondata({ raw: "\r\nremoving:\r\n" + filepath + "\r\n" })
258
260
  await rimraf(filepath)
@@ -260,8 +262,11 @@ class FS {
260
262
  }
261
263
  async copy(req, ondata, kernel) {
262
264
  let cwd = (req.cwd ? req.cwd : kernel.api.userdir)
263
- let src = path.resolve(cwd, req.params.src)
264
- let dest = path.resolve(cwd, req.params.dest)
265
+ //let src = path.resolve(cwd, req.params.src)
266
+ //let dest = path.resolve(cwd, req.params.dest)
267
+
268
+ let src = kernel.api.filePath(req.params.src, cwd)
269
+ let dest = kernel.api.filePath(req.params.dest, cwd)
265
270
  let options = req.params.options
266
271
  ondata({ raw: "\r\ncopying:\r\nfrom: " + src + "\r\nto: " + dest + "\r\n" })
267
272
  await fs.promises.cp(src, dest, options)
@@ -270,7 +275,8 @@ class FS {
270
275
 
271
276
  async init(req, kernel) {
272
277
  let cwd = (req.cwd ? req.cwd : kernel.api.userdir)
273
- let filepath = path.resolve(cwd, req.params.path)
278
+ //let filepath = path.resolve(cwd, req.params.path)
279
+ let filepath = kernel.api.filePath(req.params.path, cwd)
274
280
  let folder = path.dirname(filepath)
275
281
  await fs.promises.mkdir(folder, { recursive: true }).catch((e) => { })
276
282
  return filepath
@@ -282,7 +288,7 @@ class FS {
282
288
  } else if (typeof req.params.join === 'string') {
283
289
  await fs.promises.appendFile(filepath, req.params.join, "utf8")
284
290
  } else {
285
- await fs.promises.appendFile(filepath, Strin(req.params.join), "utf8")
291
+ await fs.promises.appendFile(filepath, String(req.params.join), "utf8")
286
292
  }
287
293
  }
288
294
  }
@@ -20,5 +20,5 @@ module.exports = async (req, ondata, kernel) => {
20
20
  }
21
21
  }
22
22
  }
23
- return req.params.input
23
+ return req.params.params || req.params.input
24
24
  }
@@ -196,6 +196,7 @@ class Api {
196
196
  async linkGit() {
197
197
  // iterate through all userdir folders and check for gitconfig
198
198
  // if they exist, add to this.gitPath
199
+ this.gitPath = {}
199
200
  let files
200
201
  try {
201
202
  files = await fs.promises.readdir(this.userdir, { withFileTypes: true })
@@ -516,6 +517,7 @@ class Api {
516
517
  let { cwd, script } = await this.resolveScript(request.path)
517
518
 
518
519
  let memory = {
520
+ script: this.kernel.script,
519
521
  input,
520
522
  args,
521
523
  global: (this.kernel.memory.global[request.path] || {}),
@@ -41,6 +41,30 @@ class Script {
41
41
  - absolute path
42
42
  - http path
43
43
  */
44
+ let uri = await this.download(req, ondata, kernel)
45
+ let res = await new Promise((resolve, reject) => {
46
+ kernel.api.process({
47
+ uri,
48
+ input: req.params.params,
49
+ client: req.client,
50
+ caller: req.parent.path,
51
+ }, (r) => {
52
+ resolve(r.input)
53
+ })
54
+ })
55
+ // need to call api.linkGit() so the git repositories list is up to date
56
+ return res
57
+ }
58
+ async return(req, ondata, kernel) {
59
+ /*
60
+ {
61
+ "method": "script.return",
62
+ "params": <RETURN OBJECT>
63
+ }
64
+ */
65
+ return req.params
66
+ }
67
+ async download(req, ondata, kernel) {
44
68
  let uri
45
69
  if (req.params.uri.startsWith("http")) {
46
70
  uri = req.params.uri
@@ -94,27 +118,7 @@ class Script {
94
118
  } else {
95
119
  uri = path.resolve(req.cwd, req.params.uri)
96
120
  }
97
- let res = await new Promise((resolve, reject) => {
98
- kernel.api.process({
99
- uri,
100
- input: req.params.params,
101
- client: req.client,
102
- caller: req.parent.path,
103
- }, (r) => {
104
- resolve(r.input)
105
- })
106
- })
107
- // need to call api.linkGit() so the git repositories list is up to date
108
- return res
109
- }
110
- async return(req, ondata, kernel) {
111
- /*
112
- {
113
- "method": "script.return",
114
- "params": <RETURN OBJECT>
115
- }
116
- */
117
- return req.params
121
+ return uri
118
122
  }
119
123
  }
120
124
  module.exports = Script
package/kernel/index.js CHANGED
@@ -17,6 +17,7 @@ const Python = require("./python")
17
17
  const Template = require('jimini')
18
18
  const Shells = require("./shells")
19
19
  const Key = require("./key")
20
+ const Script = require('./script')
20
21
  const Config = require("./pinokio.json")
21
22
  const VARS = {
22
23
  pip: {
@@ -204,6 +205,7 @@ class Kernel {
204
205
  // this.homedir = path.resolve(os.homedir(), "pinokio")
205
206
  // }
206
207
  // console.log("homedir", this.homedir)
208
+ this.script = new Script(this)
207
209
  this.loader = new Loader()
208
210
  this.bin = new Bin(this)
209
211
  this.api = new Api(this)
@@ -277,7 +279,6 @@ class Kernel {
277
279
  let info = sysinfo.info
278
280
  this.template.update(info)
279
281
  this.sysinfo = info
280
- console.log("running", this.api.running)
281
282
  } catch (e) {
282
283
  console.log("sysinfo error", e)
283
284
  }
@@ -0,0 +1,75 @@
1
+ const path = require('path')
2
+ const fs = require('fs')
3
+ class Script {
4
+ constructor(kernel) {
5
+ this.kernel = kernel
6
+ }
7
+ // script.resolve('https://github.com/cocktailpeanutlabs/comfyui.git', 'start.json')
8
+ // script.resolve('~/api/comfyui.git', 'start.json')
9
+ // script.resolve(cwd, 'start.json')
10
+ resolve(...chunks) {
11
+ let [base, ...relative] = chunks
12
+ let p = this.kernel.api.filePath(base)
13
+ if (p) {
14
+ return path.resolve(p, ...relative)
15
+ } else {
16
+ return false
17
+ }
18
+ }
19
+ exists(...chunks) {
20
+ let abspath = this.resolve(...chunks)
21
+ if (abspath) {
22
+ return fs.existsSync(abspath)
23
+ } else {
24
+ return false
25
+ }
26
+ }
27
+ // script.running('https://github.com/cocktailpeanutlabs/comfyui.git/start.json')
28
+ // script.running('~/api/comfyui.git/start.json')
29
+ // script.running(cwd, 'start.json')
30
+ running(...chunks) {
31
+ let id = this.resolve(...chunks)
32
+ if (id) {
33
+ if (this.kernel.api.running[id]) {
34
+ return true
35
+ } else {
36
+ return false
37
+ }
38
+ } else {
39
+ return false
40
+ }
41
+ }
42
+ // script.local('https://github.com/cocktailpeanutlabs/comfyui.git/start.json')
43
+ // script.local('~/api/comfyui.git/start.json')
44
+ // script.local(cwd, 'start.json')
45
+ local(...chunks) {
46
+ let id = this.resolve(...chunks)
47
+ if (id) {
48
+ let v = this.kernel.memory.local[id]
49
+ if (v) {
50
+ return v
51
+ } else {
52
+ return {}
53
+ }
54
+ } else {
55
+ return null
56
+ }
57
+ }
58
+ // script.global('https://github.com/cocktailpeanutlabs/comfyui.git/start.json')
59
+ // script.global('~/api/comfyui.git/start.json')
60
+ // script.global(cwd, 'start.json')
61
+ global(...chunks) {
62
+ let id = this.resolve(...chunks)
63
+ if (id) {
64
+ let v = this.kernel.memory.global[id]
65
+ if (v) {
66
+ return v
67
+ } else {
68
+ return {}
69
+ }
70
+ } else {
71
+ return null
72
+ }
73
+ }
74
+ }
75
+ module.exports = Script
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "1.2.52",
3
+ "version": "1.2.54",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -223,7 +223,7 @@ class Server {
223
223
  path: 'remote.origin.url'
224
224
  })
225
225
  } catch (e) {
226
- console.log("ERROR", e)
226
+ // console.log("ERROR", e)
227
227
  }
228
228
  }
229
229
 
@@ -922,6 +922,7 @@ class Server {
922
922
 
923
923
 
924
924
  let index = 0
925
+ console.log({ items })
925
926
  for(let i=0; i<items.length; i++) {
926
927
  let item = items[i]
927
928
  let p = path.resolve(uri, item.name, "pinokio.js")
@@ -937,19 +938,6 @@ class Server {
937
938
  error = `Please update Pinokio to the latest version (current script version: ${config.version}, supported: ${this.kernel.schema}`
938
939
  }
939
940
  }
940
- /*
941
- if (config.pinokiod) {
942
- // if the script contains a 'pinokiod' field, compare it against the current version
943
- // if the current version satisfies the pinokiod field, move forward
944
- // otherwise display an "upgrade" message
945
- if (semver.satisfies(this.version.pinokiod, config.pinokiod)) {
946
- console.log("semver satisfied", this.version.pinokiod, config.pinokiod)
947
- } else {
948
- console.log("semver NOT satisfied", this.version.pinokiod, config.pinokiod)
949
- error = `Please update Pinokio to the latest version (current pinokiod: ${this.version.pinokiod}, required: ${config.pinokiod}`
950
- }
951
- }
952
- */
953
941
  if (config.menu) {
954
942
  if (typeof config.menu === "function") {
955
943
  if (config.menu.constructor.name === "AsyncFunction") {
@@ -1132,6 +1120,8 @@ class Server {
1132
1120
  for(let i=0; i<config.menu.length; i++) {
1133
1121
  let menuitem = config.menu[i]
1134
1122
 
1123
+ console.log({ menuitem })
1124
+
1135
1125
  if (menuitem.menu) {
1136
1126
  let m = await this.renderMenu(uri, name, { menu: menuitem.menu }, pathComponents)
1137
1127
  menuitem.menu = m.menu
@@ -1854,6 +1844,21 @@ class Server {
1854
1844
  }
1855
1845
  }
1856
1846
 
1847
+ let uri = this.kernel.path("api")
1848
+ await this.renderMenu(uri, name, config, [])
1849
+ } else {
1850
+ // if there is no menu, display all files
1851
+ let p = this.kernel.path("api", name)
1852
+ let files = await fs.promises.readdir(p, { withFileTypes: true })
1853
+ config = {
1854
+ title: name,
1855
+ menu: files.map((file) => {
1856
+ return {
1857
+ text: file.name,
1858
+ href: file.name
1859
+ }
1860
+ })
1861
+ }
1857
1862
  let uri = this.kernel.path("api")
1858
1863
  await this.renderMenu(uri, name, config, [])
1859
1864
  }
@@ -1962,6 +1967,21 @@ class Server {
1962
1967
  let uri = this.kernel.path("api")
1963
1968
  await this.renderMenu(uri, name, config, [])
1964
1969
 
1970
+ } else {
1971
+ // if there is no menu, display all files
1972
+ let p = this.kernel.path("api", name)
1973
+ let files = await fs.promises.readdir(p, { withFileTypes: true })
1974
+ config = {
1975
+ title: name,
1976
+ menu: files.map((file) => {
1977
+ return {
1978
+ text: file.name,
1979
+ href: file.name
1980
+ }
1981
+ })
1982
+ }
1983
+ let uri = this.kernel.path("api")
1984
+ await this.renderMenu(uri, name, config, [])
1965
1985
  }
1966
1986
  let platform = os.platform()
1967
1987
  res.render("browser", {
@@ -1261,6 +1261,11 @@ document.querySelector("aside").addEventListener("click", async (e) => {
1261
1261
  })
1262
1262
  const refresh = async () => {
1263
1263
  console.log("REFRESH")
1264
+ await new Promise((resolve, reject) => {
1265
+ setTimeout(() => {
1266
+ resolve()
1267
+ }, 1000)
1268
+ })
1264
1269
  const html = await fetch("<%=sidebar%>").then((res) => {
1265
1270
  return res.text()
1266
1271
  })