-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathfs-provider.js
More file actions
39 lines (37 loc) · 867 Bytes
/
fs-provider.js
File metadata and controls
39 lines (37 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var fs = require("node:fs");
/**
* Create directory
*
* @param directory
*/
function mkdirSyncRecursive(directory) {
var path = directory.replace(/\/$/, "").split("/");
for (var i = 1; i <= path.length; i++) {
var segment = path.slice(0, i).join("/");
segment.length > 0 && !fs.existsSync(segment)
? fs.mkdirSync(segment)
: null;
}
}
class fsProvider {
constructor(path) {
if (!fs.existsSync(path)) {
mkdirSyncRecursive(path);
}
if (path.substr(-1) !== "/") {
path += "/";
}
this.path = path;
}
getToken(hashName) {
if (fs.existsSync(this.path + hashName)) {
return fs.readFileSync(this.path + hashName, { encoding: "utf8" });
} else {
return "";
}
}
setToken(hashName, token) {
fs.writeFileSync(this.path + hashName, token);
}
}
exports.fsProvider = fsProvider;