hfs 0.49.0-alpha2 → 0.49.0-alpha4
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/README.md +8 -17
- package/admin/Thumbs.db +0 -0
- package/admin/assets/{index-6afd4b06.js → index-5436e6f5.js} +78 -73
- package/admin/assets/{sha512-f5f12dc1.js → sha512-c4295d63.js} +1 -1
- package/admin/index.html +1 -1
- package/admin/win-shell.png +0 -0
- package/central.json +12 -0
- package/frontend/assets/{index-3a379840.js → index-3c132d35.js} +3 -3
- package/frontend/assets/{sha512-3392c31f.js → sha512-60af0ce6.js} +1 -1
- package/frontend/index.html +1 -1
- package/package.json +1 -1
- package/src/acme.js +115 -0
- package/src/adminApis.js +11 -3
- package/src/api.file_list.js +7 -13
- package/src/api.net.js +42 -226
- package/src/api.vfs.js +40 -7
- package/src/apiMiddleware.js +2 -2
- package/src/commands.js +3 -10
- package/src/config.js +9 -6
- package/src/const.js +7 -30
- package/src/cross-const.js +31 -0
- package/src/cross.js +18 -3
- package/src/frontEndApis.js +1 -1
- package/src/index.js +5 -3
- package/src/listen.js +25 -11
- package/src/middlewares.js +4 -4
- package/src/misc.js +1 -1
- package/src/nat.js +101 -0
- package/src/perm.js +16 -1
- package/src/plugins.js +2 -1
- package/src/selfCheck.js +60 -0
- package/src/serveFile.js +1 -1
- package/src/serveGuiFiles.js +2 -1
- package/src/update.js +13 -5
- package/src/util-files.js +4 -5
- package/src/util-http.js +1 -3
- package/src/vfs.js +6 -2
- package/src/watchLoad.js +6 -2
package/src/serveFile.js
CHANGED
|
@@ -38,7 +38,7 @@ function serveFileNode(ctx, node) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
exports.serveFileNode = serveFileNode;
|
|
41
|
-
const mimeCfg = (0, config_1.defineConfig)('mime', { '*':
|
|
41
|
+
const mimeCfg = (0, config_1.defineConfig)('mime', { '*': vfs_1.MIME_AUTO });
|
|
42
42
|
async function serveFile(ctx, source, mime, content) {
|
|
43
43
|
if (!source)
|
|
44
44
|
return;
|
package/src/serveGuiFiles.js
CHANGED
|
@@ -42,6 +42,7 @@ const customHtml_1 = require("./customHtml");
|
|
|
42
42
|
const lodash_1 = __importDefault(require("lodash"));
|
|
43
43
|
const config_1 = require("./config");
|
|
44
44
|
const lang_1 = require("./lang");
|
|
45
|
+
const vfs_1 = require("./vfs");
|
|
45
46
|
const logGui = (0, config_1.defineConfig)('log_gui', false);
|
|
46
47
|
// in case of dev env we have our static files within the 'dist' folder'
|
|
47
48
|
const DEV_STATIC = process.env.DEV ? 'dist/' : '';
|
|
@@ -69,7 +70,7 @@ function serveStatic(uri) {
|
|
|
69
70
|
if (content === null)
|
|
70
71
|
return ctx.status = const_1.HTTP_NOT_FOUND;
|
|
71
72
|
if (!serveApp)
|
|
72
|
-
return (0, serveFile_1.serveFile)(ctx, fullPath,
|
|
73
|
+
return (0, serveFile_1.serveFile)(ctx, fullPath, vfs_1.MIME_AUTO, content);
|
|
73
74
|
// we don't cache the index as it's small and may prevent plugins change to apply
|
|
74
75
|
ctx.body = await treatIndex(ctx, uri, String(content));
|
|
75
76
|
};
|
package/src/update.js
CHANGED
|
@@ -63,15 +63,22 @@ function updateSupported() {
|
|
|
63
63
|
return const_1.IS_BINARY;
|
|
64
64
|
}
|
|
65
65
|
exports.updateSupported = updateSupported;
|
|
66
|
-
async function update(tag) {
|
|
66
|
+
async function update(tag = '') {
|
|
67
67
|
if (!updateSupported())
|
|
68
|
-
throw "only binary versions
|
|
68
|
+
throw "only binary versions supports automatic update for now";
|
|
69
69
|
let updateSource = await localUpdateAvailable() && (0, fs_1.createReadStream)(LOCAL_UPDATE);
|
|
70
70
|
if (!updateSource) {
|
|
71
|
+
if (/^\d/.test(tag)) // work even if the tag is passed without the initial 'v' (useful for console commands)
|
|
72
|
+
tag = 'v' + tag;
|
|
71
73
|
const update = !tag ? (await getUpdates())[0]
|
|
72
|
-
: await (0, github_1.getRepoInfo)(const_1.HFS_REPO + '/releases/tags/' + tag)
|
|
74
|
+
: await (0, github_1.getRepoInfo)(const_1.HFS_REPO + '/releases/tags/' + tag).catch(e => {
|
|
75
|
+
if (e.message === '404')
|
|
76
|
+
console.error("version not found");
|
|
77
|
+
else
|
|
78
|
+
throw e;
|
|
79
|
+
});
|
|
73
80
|
if (!update)
|
|
74
|
-
throw "
|
|
81
|
+
throw "update not found";
|
|
75
82
|
const assetSearch = { win32: 'windows', darwin: 'mac', linux: 'linux' }[process.platform];
|
|
76
83
|
if (!assetSearch)
|
|
77
84
|
throw "this feature doesn't support your platform: " + process.platform;
|
|
@@ -109,7 +116,8 @@ async function update(tag) {
|
|
|
109
116
|
console.log('quitting');
|
|
110
117
|
setTimeout(() => process.exit()); // give time to return (and caller to complete, eg: rest api to reply)
|
|
111
118
|
}
|
|
112
|
-
catch (
|
|
119
|
+
catch (e) {
|
|
120
|
+
console.error((e === null || e === void 0 ? void 0 : e.message) || String(e));
|
|
113
121
|
plugins_1.pluginsWatcher.unpause();
|
|
114
122
|
}
|
|
115
123
|
}
|
package/src/util-files.js
CHANGED
|
@@ -45,9 +45,7 @@ async function isDirectory(path) {
|
|
|
45
45
|
try {
|
|
46
46
|
return (await promises_1.default.stat(path)).isDirectory();
|
|
47
47
|
}
|
|
48
|
-
catch (_a) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
48
|
+
catch (_a) { }
|
|
51
49
|
}
|
|
52
50
|
exports.isDirectory = isDirectory;
|
|
53
51
|
async function readFileBusy(path) {
|
|
@@ -138,8 +136,9 @@ async function* dirStream(path, deep = 0) {
|
|
|
138
136
|
exports.dirStream = dirStream;
|
|
139
137
|
async function unzip(stream, cb) {
|
|
140
138
|
let pending = Promise.resolve();
|
|
141
|
-
return new Promise(resolve => stream.pipe(unzip_stream_1.default.Parse())
|
|
139
|
+
return new Promise((resolve, reject) => stream.pipe(unzip_stream_1.default.Parse())
|
|
142
140
|
.on('end', () => pending.then(resolve))
|
|
141
|
+
.on('error', reject)
|
|
143
142
|
.on('entry', (entry) => pending = pending.then(async () => {
|
|
144
143
|
const { path, type } = entry;
|
|
145
144
|
const dest = await (0, misc_1.try_)(() => cb(path), e => {
|
|
@@ -150,7 +149,7 @@ async function unzip(stream, cb) {
|
|
|
150
149
|
return entry.autodrain();
|
|
151
150
|
console.debug('unzip', dest);
|
|
152
151
|
await prepareFolder(dest);
|
|
153
|
-
const thisFile = entry.pipe((0, fs_1.createWriteStream)(dest));
|
|
152
|
+
const thisFile = entry.pipe((0, fs_1.createWriteStream)(dest).on('error', reject));
|
|
154
153
|
await (0, stream_1.once)(thisFile, 'finish');
|
|
155
154
|
})));
|
|
156
155
|
}
|
package/src/util-http.js
CHANGED
package/src/vfs.js
CHANGED
|
@@ -36,13 +36,14 @@ function permsFromParent(parent, child) {
|
|
|
36
36
|
}
|
|
37
37
|
exports.permsFromParent = permsFromParent;
|
|
38
38
|
function inheritFromParent(parent, child) {
|
|
39
|
-
var _a, _b;
|
|
39
|
+
var _a, _b, _c;
|
|
40
40
|
Object.assign(child, permsFromParent(parent, child));
|
|
41
41
|
if (typeof parent.mime === 'object' && typeof child.mime === 'object')
|
|
42
42
|
lodash_1.default.defaults(child.mime, parent.mime);
|
|
43
43
|
else
|
|
44
44
|
(_a = child.mime) !== null && _a !== void 0 ? _a : (child.mime = parent.mime);
|
|
45
45
|
(_b = child.accept) !== null && _b !== void 0 ? _b : (child.accept = parent.accept);
|
|
46
|
+
(_c = child.default) !== null && _c !== void 0 ? _c : (child.default = parent.default);
|
|
46
47
|
return child;
|
|
47
48
|
}
|
|
48
49
|
function isSameFilenameAs(name) {
|
|
@@ -167,8 +168,11 @@ function hasPermission(node, perm, ctx) {
|
|
|
167
168
|
exports.hasPermission = hasPermission;
|
|
168
169
|
function statusCodeForMissingPerm(node, perm, ctx, assign = true) {
|
|
169
170
|
const ret = getCode();
|
|
170
|
-
if (ret && assign)
|
|
171
|
+
if (ret && assign) {
|
|
171
172
|
ctx.status = ret;
|
|
173
|
+
if (ret === const_1.HTTP_UNAUTHORIZED) // this is necessary to support standard urls with credentials
|
|
174
|
+
ctx.set('WWW-Authenticate', 'Basic'); // we support basic authentication
|
|
175
|
+
}
|
|
172
176
|
return ret;
|
|
173
177
|
function getCode() {
|
|
174
178
|
if (!node.source && perm === 'can_upload') // Upload possible only if we know where to store. First check node.source because is supposedly faster.
|
package/src/watchLoad.js
CHANGED
|
@@ -15,8 +15,12 @@ function watchLoad(path, parser, { failedOnFirstAttempt, immediateFirst } = {})
|
|
|
15
15
|
let retry;
|
|
16
16
|
let last;
|
|
17
17
|
install(true);
|
|
18
|
-
const save = (0, misc_1.debounceAsync)((data
|
|
19
|
-
|
|
18
|
+
const save = (0, misc_1.debounceAsync)(async (data, { reparse = false } = {}) => {
|
|
19
|
+
await promises_1.default.writeFile(path, data, 'utf8');
|
|
20
|
+
if (reparse)
|
|
21
|
+
await parser(data);
|
|
22
|
+
});
|
|
23
|
+
return { unwatch, save, getText: () => last, getPath: () => path };
|
|
20
24
|
function install(first = false) {
|
|
21
25
|
try {
|
|
22
26
|
watcher = (0, fs_1.watch)(path, () => {
|