pinokiod 0.1.25 → 0.1.28

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/index.js CHANGED
@@ -135,17 +135,19 @@ class Kernel {
135
135
  async init() {
136
136
  let home = this.store.get("home")
137
137
  if (home) {
138
+ this.homedir = home
138
139
 
139
- // check if the path exists
140
- let exists = fs.existsSync(home)
141
- if (exists) {
142
- this.homedir = home
143
- } else {
144
- // if it doesn't exists, means there was some error, so just delete this entry from the store, and set the default home as the home
145
- this.store.delete("home")
146
- this.homedir = path.resolve(os.homedir(), "pinokio")
147
- }
140
+ // // check if the path exists
141
+ // let exists = fs.existsSync(home)
142
+ // if (exists) {
143
+ // this.homedir = home
144
+ // } else {
145
+ // // if it doesn't exist, means there was some error, so just delete this entry from the store, and set the default home as the home
146
+ // this.store.delete("home")
147
+ // this.homedir = path.resolve(os.homedir(), "pinokio")
148
+ // }
148
149
  } else {
150
+ // this.homedir = null
149
151
  this.homedir = path.resolve(os.homedir(), "pinokio")
150
152
  }
151
153
  console.log("homedir", this.homedir)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "0.1.25",
3
+ "version": "0.1.28",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/script/index.js CHANGED
@@ -26,7 +26,9 @@ class Store {
26
26
  try {
27
27
  let str = fs.readFileSync(path.resolve(__dirname, "pinokio.json"), "utf8")
28
28
  let o = JSON.parse(str)
29
+ console.log("before delete", o)
29
30
  delete o[key]
31
+ console.log("after delete", o)
30
32
  fs.writeFileSync(path.resolve(__dirname, "pinokio.json"), JSON.stringify(o, null, 2))
31
33
  } catch (e) {
32
34
  }
package/server/index.js CHANGED
@@ -1246,6 +1246,40 @@ class Server {
1246
1246
  })
1247
1247
  return response
1248
1248
  }
1249
+ async mv(existing_home, new_home) {
1250
+ //// Next, empty the bin folder => need to reinitialize because of symlinks, etc. with the package managers
1251
+ console.log("RUNNING RM BIN")
1252
+ const path_to_delete = path.resolve(existing_home, "bin")
1253
+ let del_cmd
1254
+ if (this.kernel.platform === "win32") {
1255
+ del_cmd = `rd /s /q ${path_to_delete}`
1256
+ } else {
1257
+ del_cmd = `rm -rf ${path_to_delete}`
1258
+ }
1259
+ console.log("del_cmd", del_cmd)
1260
+
1261
+ await this.sudo_exec(del_cmd, new_home)
1262
+ console.log("FINISHED RM BIN")
1263
+
1264
+ console.log("RUNNING MV")
1265
+ let mv_cmd
1266
+ if (this.kernel.platform === "win32") {
1267
+ // robocoyp returns 1 when successful
1268
+ //mv_cmd = `start /wait (robocopy ${existing_home} ${new_home} /E /MOVE /NFL /NDL) ^& IF %ERRORLEVEL% LEQ 1 exit 0`
1269
+ //mv_cmd = `start /wait robocopy ${existing_home} ${new_home} /E /MOVE /NFL /NDL`
1270
+ mv_cmd = `start /wait robocopy ${existing_home} ${new_home} /E /MOVE /NFL`
1271
+ //mv_cmd = `start /wait robocopy ${existing_home} ${new_home} /E /MOVE /NFL`
1272
+ } else {
1273
+ mv_cmd = `mv ${existing_home} ${new_home}`
1274
+ }
1275
+ try {
1276
+ await this.sudo_exec(mv_cmd, existing_home)
1277
+ } catch (e) {
1278
+ console.log("ROBOCOPY RESULT", e)
1279
+ }
1280
+ console.log("FINISHED MV")
1281
+ }
1282
+
1249
1283
  async syncConfig() {
1250
1284
  // 1. THEME
1251
1285
  this.theme = this.kernel.store.get("theme") || "light"
@@ -1263,61 +1297,91 @@ class Server {
1263
1297
  //this.logo = (this.theme === 'dark' ? "<img class='icon' src='/pinokio-white.png'>" : "<img class='icon' src='/pinokio-black.png'>")
1264
1298
  this.logo = '<i class="fa-solid fa-house"></i>'
1265
1299
 
1300
+ // 4. existing home is set + new home is set + existing home does NOT exist => delete the "home" field and DO NOT go through with the move command
1301
+ // 5. existing home is NOT set + new home is set => go through with the "home" setting procedure
1302
+ // 6. existing home is NOT set + new home is NOT set => don't touch anything => the homedir will be the default home
1303
+
1266
1304
  // 2. HOME
1267
1305
  // 2.1. Check if the config includes NEW_HOME => if so,
1268
1306
  // - move the HOME folder to NEW_HOME
1269
1307
  // - set HOME=NEW_HOME
1270
1308
  // - remove NEW_HOME
1309
+ let existing_home = this.kernel.store.get("home")
1271
1310
  let new_home = this.kernel.store.get("new_home")
1272
- console.log("new_home", new_home)
1273
- if (new_home) {
1274
- // move the home folder to new_home
1275
-
1276
- let existing_home = this.kernel.store.get("home")
1277
-
1278
- console.log({ existing_home, new_home })
1279
-
1280
- if (existing_home) {
1281
- // if the home is already set, move
1282
-
1283
- //// Next, empty the bin folder => need to reinitialize because of symlinks, etc. with the package managers
1284
- console.log("RUNNING RM BIN")
1285
- const path_to_delete = path.resolve(existing_home, "bin")
1286
- let del_cmd
1287
- if (this.kernel.platform === "win32") {
1288
- del_cmd = `rd /s /q ${path_to_delete}`
1311
+ console.log("syncConfig", { existing_home, new_home })
1312
+
1313
+ if (existing_home) {
1314
+ let exists = await fse.pathExists(existing_home)
1315
+ console.log("#A", { exists })
1316
+ if (exists) {
1317
+ console.log("#B", { new_home })
1318
+ if (new_home) {
1319
+ let new_home_exists = await fse.pathExists(new_home)
1320
+ console.log("#C", { new_home_exists })
1321
+ if (new_home_exists) {
1322
+ console.log("#D")
1323
+ // - existing home is set
1324
+ // - existing home exists
1325
+ // - new home is set
1326
+ // - new home exists already
1327
+ // => delete store.new_home ==> will load at store.home
1328
+ this.kernel.store.delete("new_home")
1329
+ } else {
1330
+ console.log("#E")
1331
+ // - existing home is set
1332
+ // - existing home exists
1333
+ // - new home is set
1334
+ // - new home does not exist
1335
+ // => run mv()
1336
+ // => update store.home
1337
+ // => delete store.new_home
1338
+ await this.mv(existing_home, new_home)
1339
+ this.kernel.store.set("home", new_home)
1340
+ this.kernel.store.delete("new_home")
1341
+ }
1289
1342
  } else {
1290
- del_cmd = `rm -rf ${path_to_delete}`
1343
+ console.log("#F")
1344
+ // - existing home is set
1345
+ // - existing home exists
1346
+ // - new home is not set
1347
+ // => This is most typical scenario => don't touch anything => the homedir will be the existing home
1291
1348
  }
1292
- console.log("del_cmd", del_cmd)
1293
-
1294
- await this.sudo_exec(del_cmd, new_home)
1295
- console.log("FINISHED RM BIN")
1296
-
1297
- console.log("RUNNING MV")
1298
- let mv_cmd
1299
- if (this.kernel.platform === "win32") {
1300
- // robocoyp returns 1 when successful
1301
- //mv_cmd = `start /wait (robocopy ${existing_home} ${new_home} /E /MOVE /NFL /NDL) ^& IF %ERRORLEVEL% LEQ 1 exit 0`
1302
- mv_cmd = `start /wait robocopy ${existing_home} ${new_home} /E /MOVE /NFL /NDL`
1303
- //mv_cmd = `start /wait robocopy ${existing_home} ${new_home} /E /MOVE /NFL`
1349
+ } else {
1350
+ console.log("#G", { new_home })
1351
+ if (new_home) {
1352
+ console.log("#H")
1353
+ // - existing home is set
1354
+ // - but the existing home path DOES NOT exist
1355
+ // - new home is set
1356
+ // => This is an invalid scenario => Just to avoid disaster, just delete store.home and delete store.new_home
1357
+ // => the app will load at ~/pinokio
1358
+ this.kernel.store.delete("home")
1359
+ this.kernel.store.delete("new_home")
1304
1360
  } else {
1305
- mv_cmd = `mv ${existing_home} ${new_home}`
1306
- }
1307
- try {
1308
- await this.sudo_exec(mv_cmd, existing_home)
1309
- } catch (e) {
1310
- console.log("E", e)
1361
+ console.log("#I")
1362
+ // - existing home is set
1363
+ // - but the existing home path DOES NOT exist
1364
+ // - new home is NOT set
1365
+ // => This is an invalid scenario => just delete store.home
1366
+ // => the app will load at ~/pinokio
1367
+ this.kernel.store.delete("home")
1311
1368
  }
1312
- console.log("FINISHED MV")
1313
-
1314
- // set home=new_home
1369
+ }
1370
+ } else {
1371
+ console.log("#J", { new_home })
1372
+ if (new_home) {
1373
+ console.log("#K")
1374
+ // - existing home is NOT set
1375
+ // - new home is set
1376
+ // => update store.home
1377
+ // => delete store.new_home
1315
1378
  this.kernel.store.set("home", new_home)
1316
- // delete new_home
1317
- console.log("STORE", this.kernel.store)
1318
1379
  this.kernel.store.delete("new_home")
1319
1380
  } else {
1320
- // if the home is not already set, don't need to do anything
1381
+ console.log("#L")
1382
+ // - existing home is NOT set
1383
+ // - new home is NOT set
1384
+ // => don't touch anything => will load at ~/pinokio
1321
1385
  }
1322
1386
  }
1323
1387
  }
@@ -1351,6 +1415,8 @@ class Server {
1351
1415
  throw new Error(`The path ${config.home} already exists. Please remove the folder and retry`)
1352
1416
  }
1353
1417
 
1418
+ console.log("set new home", config.home)
1419
+
1354
1420
  this.kernel.store.set("new_home", config.home)
1355
1421
  }
1356
1422
 
@@ -1358,7 +1424,8 @@ class Server {
1358
1424
 
1359
1425
  home = this.kernel.store.get("home")
1360
1426
  theme = this.kernel.store.get("theme")
1361
- console.log("after setting config", { home, theme })
1427
+ let new_home = this.kernel.store.get("new_home")
1428
+ console.log("after setting config", { home, theme, new_home })
1362
1429
  }
1363
1430
  async start(debug) {
1364
1431
 
@@ -1435,7 +1502,8 @@ class Server {
1435
1502
  this.app.use(cookieParser());
1436
1503
  this.app.use(session({secret: "secret" }))
1437
1504
 
1438
- let home = this.kernel.homedir
1505
+ //let home = this.kernel.homedir
1506
+ let home = this.kernel.store.get("home")
1439
1507
  this.app.get("/", async (req, res) => {
1440
1508
  console.log("### req.headers", req.headers)
1441
1509
 
@@ -575,7 +575,10 @@ body.dark header {
575
575
  background: var(--dark-nav-bg);
576
576
  }
577
577
  header {
578
+ /*
578
579
  background: var(--light-nav-bg);
580
+ */
581
+ background: white;
579
582
  position: sticky;
580
583
  padding: 10px;
581
584
  top: 0;
@@ -632,9 +635,9 @@ body.dark header a.path {
632
635
  header a.path {
633
636
  text-decoration: none;
634
637
  /*
635
- color: var(--light-color);
636
- */
637
638
  color: var(--light-link-color);
639
+ */
640
+ color: var(--light-color);
638
641
  padding: 0 5px;
639
642
  word-wrap: break-word;
640
643
  max-width: 100%;
@@ -87,7 +87,9 @@ body.dark .item select {
87
87
  padding: 10px;
88
88
  flex-grow: 1;
89
89
  border: none;
90
+ /*
90
91
  background: rgba(0,0,0,0.05);
92
+ */
91
93
  width: 100%;
92
94
  }
93
95
  .item select {
@@ -125,7 +127,9 @@ body.dark .item select {
125
127
  text-align: center;
126
128
  }
127
129
  body.light {
130
+ /*
128
131
  background: var(--light-nav-bg);
132
+ */
129
133
  }
130
134
  /*
131
135
  form {