hfs 0.52.2 → 0.52.3

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.
@@ -1,4 +1,4 @@
1
- import{g as OF,c as UF}from"./index-f_a4EAov.js";function gF(sF,hF){for(var eF=0;eF<hF.length;eF++){const tF=hF[eF];if(typeof tF!="string"&&!Array.isArray(tF)){for(const w in tF)if(w!=="default"&&!(w in sF)){const lF=Object.getOwnPropertyDescriptor(tF,w);lF&&Object.defineProperty(sF,w,lF.get?lF:{enumerable:!0,get:()=>tF[w]})}}}return Object.freeze(Object.defineProperty(sF,Symbol.toStringTag,{value:"Module"}))}var dF={exports:{}};/*
1
+ import{g as OF,c as UF}from"./index-H_Hi8lRV.js";function gF(sF,hF){for(var eF=0;eF<hF.length;eF++){const tF=hF[eF];if(typeof tF!="string"&&!Array.isArray(tF)){for(const w in tF)if(w!=="default"&&!(w in sF)){const lF=Object.getOwnPropertyDescriptor(tF,w);lF&&Object.defineProperty(sF,w,lF.get?lF:{enumerable:!0,get:()=>tF[w]})}}}return Object.freeze(Object.defineProperty(sF,Symbol.toStringTag,{value:"Module"}))}var dF={exports:{}};/*
2
2
  * [js-sha512]{@link https://github.com/emn178/js-sha512}
3
3
  *
4
4
  * @version 0.8.0
@@ -4,11 +4,12 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0" />
6
6
  <link href="/fontello.css" rel="stylesheet" />
7
- <script type="module" crossorigin src="/assets/index-f_a4EAov.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-H_Hi8lRV.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-_JmRmWgy.css">
9
9
  </head>
10
10
  <body>
11
11
  <noscript>You need to enable JavaScript to run this app.</noscript>
12
12
  <div id="root"></div>
13
+ <script nomodule>document.getElementById('root').innerText = "Please use a newer browser"</script>
13
14
  </body>
14
15
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hfs",
3
- "version": "0.52.2",
3
+ "version": "0.52.3",
4
4
  "description": "HTTP File Server",
5
5
  "keywords": [
6
6
  "file server",
@@ -53,8 +53,8 @@ exports.default = {
53
53
  await (0, perm_1.updateAccount)(existing, rest);
54
54
  return lodash_1.default.pick(existing, 'username');
55
55
  }
56
- const acc = (0, perm_1.addAccount)(username, rest);
57
- return acc ? lodash_1.default.pick(acc, 'username') : new apiMiddleware_1.ApiError(const_1.HTTP_BAD_REQUEST);
56
+ const acc = await (0, perm_1.addAccount)(username, rest);
57
+ return acc ? lodash_1.default.pick(acc, 'username') : new apiMiddleware_1.ApiError(const_1.HTTP_BAD_REQUEST); // return username because it is normalized
58
58
  },
59
59
  del_account({ username }) {
60
60
  (0, misc_1.apiAssertTypes)({ string: { username } });
package/src/api.vfs.js CHANGED
@@ -224,9 +224,14 @@ const apis = {
224
224
  for (const k of ['*', 'Directory']) {
225
225
  await reg('add', WINDOWS_REG_KEY.replace('*', k), '/ve', '/f', '/d', 'Add to HFS (new)');
226
226
  await reg('add', WINDOWS_REG_KEY.replace('*', k) + '\\command', '/ve', '/f', '/d', `powershell -Command "
227
- $j = '{ \\"parent\\": \\"${parent}\\", \\"source\\": "' + ('%1'|convertTo-json) + '" }'; $j = [System.Text.Encoding]::UTF8.GetBytes($j); $wsh = New-Object -ComObject Wscript.Shell;
228
- try { $res = Invoke-WebRequest -Uri '${url}/~/api/add_vfs' -Method POST -Headers @{ 'x-hfs-anti-csrf' = '1' } -ContentType 'application/json' -TimeoutSec 1 -Body $j;
229
- $json = $res.Content | ConvertFrom-Json; $link = $json.link; $link | Set-Clipboard; } catch { $wsh.Popup('Server is down', 0, 'Error', 16); }"`);
227
+ $wsh = New-Object -ComObject Wscript.Shell;
228
+ $j = @{parent=@'\n${parent}\n'@; source=@'\n%1\n'@} | ConvertTo-Json -Compress
229
+ $j = [System.Text.Encoding]::UTF8.GetBytes($j);
230
+ try {
231
+ $res = Invoke-WebRequest -Uri '${url}/~/api/add_vfs' -Method POST -Headers @{ 'x-hfs-anti-csrf' = '1' } -ContentType 'application/json' -TimeoutSec 1 -Body $j;
232
+ $json = $res.Content | ConvertFrom-Json; $link = $json.link; $link | Set-Clipboard;
233
+ $wsh.Popup('The link is ready to be pasted');
234
+ } catch { $wsh.Popup('Server is down', 0, 'Error', 16); }"`);
230
235
  }
231
236
  return {};
232
237
  },
package/src/const.js CHANGED
@@ -45,7 +45,7 @@ exports.DEV = process.env.DEV || exports.argv.dev ? 'DEV' : '';
45
45
  exports.ORIGINAL_CWD = process.cwd();
46
46
  exports.HFS_STARTED = new Date();
47
47
  const PKG_PATH = (0, path_1.join)(__dirname, '..', 'package.json');
48
- exports.BUILD_TIMESTAMP = "2024-04-20T19:09:36.991Z";
48
+ exports.BUILD_TIMESTAMP = "2024-04-25T15:53:22.338Z";
49
49
  const pkg = JSON.parse(fs.readFileSync(PKG_PATH, 'utf8'));
50
50
  exports.VERSION = pkg.version;
51
51
  exports.RUNNING_BETA = exports.VERSION.includes('-');
package/src/perm.js CHANGED
@@ -44,11 +44,10 @@ createAdminConfig.sub(v => {
44
44
  createAdmin(v);
45
45
  createAdminConfig.set('');
46
46
  });
47
- function createAdmin(password, username = 'admin') {
48
- const acc = addAccount(username, { admin: true });
47
+ async function createAdmin(password, username = 'admin') {
48
+ const acc = await addAccount(username, { admin: true, password });
49
49
  if (!acc)
50
50
  return console.log("cannot create, already exists");
51
- updateAccount(acc, { password });
52
51
  console.log("account admin created");
53
52
  }
54
53
  exports.createAdmin = createAdmin;
@@ -79,7 +78,7 @@ async function updateAccount(account, change) {
79
78
  account.expire && (account.expire = new Date(account.expire));
80
79
  if (username !== usernameWas)
81
80
  renameAccount(usernameWas, username);
82
- if (jsonWas !== JSON.stringify(account))
81
+ if (jsonWas !== JSON.stringify(account)) // this test will miss the 'username' field, because hidden, but renameAccount is already calling saveAccountsASAP
83
82
  saveAccountsAsap();
84
83
  }
85
84
  exports.updateAccount = updateAccount;
@@ -126,13 +125,13 @@ function renameAccount(from, to) {
126
125
  }
127
126
  }
128
127
  exports.renameAccount = renameAccount;
129
- function addAccount(username, props) {
128
+ async function addAccount(username, props) {
130
129
  username = normalizeUsername(username);
131
130
  if (!username || getAccount(username, false))
132
131
  return;
133
132
  const copy = (0, misc_1.setHidden)(lodash_1.default.pickBy(props, Boolean), { username }); // have the field in the object but hidden so that stringification won't include it
134
133
  exports.accountsConfig.set(accounts => Object.assign(accounts, { [username]: copy }));
135
- saveAccountsAsap();
134
+ await updateAccount(copy, copy);
136
135
  return copy;
137
136
  }
138
137
  exports.addAccount = addAccount;
package/src/serveFile.js CHANGED
@@ -70,6 +70,8 @@ async function serveFile(ctx, source, mime, content) {
70
70
  return ctx.status = const_1.HTTP_METHOD_NOT_ALLOWED;
71
71
  try {
72
72
  const stats = await (0, util_1.promisify)(fs_1.stat)(source); // using fs's function instead of fs/promises, because only the former is supported by pkg
73
+ if (!stats.isFile())
74
+ return ctx.status = const_1.HTTP_METHOD_NOT_ALLOWED;
73
75
  ctx.set('Last-Modified', stats.mtime.toUTCString());
74
76
  ctx.fileSource = // legacy pre-0.51
75
77
  ctx.state.fileSource = source;