fkg 1.0.8 → 1.0.9
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/lib/index.js +17 -24
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const {
|
|
3
|
-
isDir,
|
|
4
3
|
link,
|
|
4
|
+
isDir,
|
|
5
5
|
addDir,
|
|
6
6
|
addJson,
|
|
7
|
-
readJson,
|
|
8
7
|
delFile,
|
|
8
|
+
readJson,
|
|
9
9
|
readdirSync
|
|
10
10
|
} = require('./utils/fs');
|
|
11
11
|
const {md5,ekey,dkey} = require('rrid');
|
|
12
12
|
const {str,obj,arr} = require('./utils/type');
|
|
13
|
-
const getTime = ()=>{ return new Date().getTime();}
|
|
14
13
|
class fkg {
|
|
15
14
|
constructor(arg) {
|
|
16
15
|
this.close();
|
|
@@ -22,12 +21,20 @@ class fkg {
|
|
|
22
21
|
if(arg.key&&str(arg.key)) this.key = md5(arg.key+'fkg');
|
|
23
22
|
if(arg.dbName&&arr(arg.dbName)&&arr.length>0){
|
|
24
23
|
this.setList = {};
|
|
25
|
-
setInterval(() => {
|
|
24
|
+
const timer = setInterval(() => {
|
|
25
|
+
if(!this.dir) {
|
|
26
|
+
clearInterval(timer);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
26
29
|
for (const keys in this.setList) {
|
|
27
|
-
const {n,id} = this.setList[keys];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const {n,id,s} = this.setList[keys];
|
|
31
|
+
if(s){
|
|
32
|
+
let d = this.data[n][id];
|
|
33
|
+
if(this.key) d = ekey(JSON.stringify(d),this.key+id);
|
|
34
|
+
addJson(link(this.dirs[n],'./'+id),d);
|
|
35
|
+
}else{
|
|
36
|
+
delFile(link(this.dirs[n],'./'+id));
|
|
37
|
+
}
|
|
31
38
|
delete this.setList[keys];
|
|
32
39
|
}
|
|
33
40
|
}, 3000);
|
|
@@ -56,7 +63,6 @@ class fkg {
|
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
close(){
|
|
59
|
-
this.lock = {};
|
|
60
66
|
this.data = {};
|
|
61
67
|
this.dirs = {};
|
|
62
68
|
this.dir = null;
|
|
@@ -65,7 +71,6 @@ class fkg {
|
|
|
65
71
|
const that = this;
|
|
66
72
|
if(!n||!str(n)) return;
|
|
67
73
|
if(!that.data[n]) that.data[n] = {};
|
|
68
|
-
if(!that.lock[n]) that.lock[n] = {};
|
|
69
74
|
return {
|
|
70
75
|
list(page){
|
|
71
76
|
function getOBJ(obj, n) {
|
|
@@ -86,31 +91,19 @@ class fkg {
|
|
|
86
91
|
list = null;
|
|
87
92
|
}
|
|
88
93
|
delete that.data[n];
|
|
89
|
-
delete that.lock[n];
|
|
90
94
|
return true;
|
|
91
95
|
},
|
|
92
96
|
get(id){
|
|
93
|
-
if(that.lock[n][id]){
|
|
94
|
-
const time = getTime();
|
|
95
|
-
while (that.lock[n][id]) {
|
|
96
|
-
// 等待解锁
|
|
97
|
-
if(getTime()-time>3000) {
|
|
98
|
-
delete that.lock[n][id];
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
97
|
return that.data[n][id];
|
|
103
98
|
},
|
|
104
99
|
set(id,d){
|
|
105
|
-
that.
|
|
100
|
+
if(that.dirs[n]) that.setList[n+id] = {n,id,s:1};
|
|
106
101
|
that.data[n][id] = d;
|
|
107
|
-
if(that.dirs[n]) that.setList[n+id] = {n,id};
|
|
108
|
-
delete that.lock[n][id];
|
|
109
102
|
return true;
|
|
110
103
|
},
|
|
111
104
|
del(id){
|
|
112
105
|
delete that.data[n][id];
|
|
113
|
-
if(that.dirs[n])
|
|
106
|
+
if(that.dirs[n]) that.setList[n+id] = {n,id,s:0};
|
|
114
107
|
return true;
|
|
115
108
|
}
|
|
116
109
|
}
|