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/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', { '*': 'auto' });
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;
@@ -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, 'auto', content);
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 are supported for now";
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 "no update found";
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 (_a) {
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
@@ -36,9 +36,7 @@ function httpStream(url, { body, ...options } = {}) {
36
36
  }).on('error', e => {
37
37
  reject(req.res || e);
38
38
  });
39
- if (body)
40
- req.write(body);
41
- req.end();
39
+ req.end(body);
42
40
  });
43
41
  }
44
42
  exports.httpStream = httpStream;
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) => promises_1.default.writeFile(path, data, 'utf8'));
19
- return { unwatch, save };
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, () => {