instaserve 0.0.17 → 1.0.20
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/index.mjs +5 -3
- package/package.json +2 -4
- package/db.json +0 -1
- package/routes.mjs +0 -5
- package/vastdb.mjs +0 -42
package/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import http from 'node:http'
|
|
3
3
|
import fs from 'node:fs'
|
|
4
|
-
import {pathToFileURL
|
|
5
|
-
import {resolve} from 'node:path'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
5
|
+
import { resolve } from 'node:path'
|
|
6
6
|
|
|
7
7
|
const routesfile = resolve('routes.mjs')
|
|
8
|
+
const routesurl = pathToFileURL(routesfile).href
|
|
9
|
+
console.log(routesfile, routesurl)
|
|
8
10
|
|
|
9
11
|
if (!fs.existsSync(routesfile)) {
|
|
10
12
|
fs.writeFileSync(routesfile, `export default {
|
|
@@ -13,7 +15,7 @@ if (!fs.existsSync(routesfile)) {
|
|
|
13
15
|
'tables': name => ([k, v]) => k.match(name + ':')
|
|
14
16
|
}`)
|
|
15
17
|
}
|
|
16
|
-
const routes = (await import(
|
|
18
|
+
const routes = (await import(routesurl)).default
|
|
17
19
|
routes['/sw.js'] = e => {
|
|
18
20
|
e.s.writeHead(201, { 'Content-Type': 'application/javascript' })
|
|
19
21
|
e.s.end('self.addEventListener("fetch",e=>{e.respondWith(caches.open("e").then(function(t){return t.match(e.request).then(function(n){return n||fetch(e.request).then(function(n){return e.request.url.match(/\.js$|\.css$/)&&t.put(e.request,n.clone()),n})})}))});')
|
package/package.json
CHANGED
package/db.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[["user:admin",{"type":"user","name":"admin","pass":"01b613da484bee91c3f3806b52a6f40fd61ade874b5ffc0f62a2091cce38158b","id":"user:admin"}]]
|
package/routes.mjs
DELETED
package/vastdb.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
export default class VastDB extends Map {
|
|
3
|
-
constructor(v) {
|
|
4
|
-
super();
|
|
5
|
-
this.filename = `${process.cwd()}/db.json`;
|
|
6
|
-
this.views = v
|
|
7
|
-
if (!fs.existsSync(this.filename)) {
|
|
8
|
-
this.set({
|
|
9
|
-
type: 'user',
|
|
10
|
-
name: 'admin',
|
|
11
|
-
pass: '01b613da484bee91c3f3806b52a6f40fd61ade874b5ffc0f62a2091cce38158b',
|
|
12
|
-
});
|
|
13
|
-
console.log('creating db');
|
|
14
|
-
} else {
|
|
15
|
-
const sf = JSON.parse(fs.readFileSync(this.filename, 'utf8'));
|
|
16
|
-
sf.map(([k, v]) => {
|
|
17
|
-
v.id = k;
|
|
18
|
-
this.set(v);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
query(q = () => false) {
|
|
23
|
-
return [...this].filter(q).map(([k, v]) => v)
|
|
24
|
-
}
|
|
25
|
-
getView(name, param) {
|
|
26
|
-
const res = [...this].filter(this.views[name](param));
|
|
27
|
-
return res.map(([k, v]) => v);
|
|
28
|
-
}
|
|
29
|
-
set(arr) {
|
|
30
|
-
if (!arr.push) arr = [arr];
|
|
31
|
-
for (const o of arr) {
|
|
32
|
-
if (!o.name || !o.type) return false;
|
|
33
|
-
if (!o.id) o.id = o.type + ':' + o.name;
|
|
34
|
-
}
|
|
35
|
-
arr.map((o) => super.set(o.id, o));
|
|
36
|
-
if(this.event) this.event(arr)
|
|
37
|
-
this.save();
|
|
38
|
-
}
|
|
39
|
-
save() {
|
|
40
|
-
fs.writeFileSync(this.filename, JSON.stringify([...this.entries()]));
|
|
41
|
-
}
|
|
42
|
-
}
|