hfs 0.42.2 → 0.42.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{c as SF}from"./index-297a3f3d.js";function OF(iF,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 iF)){const lF=Object.getOwnPropertyDescriptor(tF,w);lF&&Object.defineProperty(iF,w,lF.get?lF:{enumerable:!0,get:()=>tF[w]})}}}return Object.freeze(Object.defineProperty(iF,Symbol.toStringTag,{value:"Module"}))}var EF={},UF={get exports(){return EF},set exports(iF){EF=iF}};/*
1
+ import{c as SF}from"./index-5f125477.js";function OF(iF,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 iF)){const lF=Object.getOwnPropertyDescriptor(tF,w);lF&&Object.defineProperty(iF,w,lF.get?lF:{enumerable:!0,get:()=>tF[w]})}}}return Object.freeze(Object.defineProperty(iF,Symbol.toStringTag,{value:"Module"}))}var EF={},UF={get exports(){return EF},set exports(iF){EF=iF}};/*
2
2
  * [js-sha512]{@link https://github.com/emn178/js-sha512}
3
3
  *
4
4
  * @version 0.8.0
@@ -5,7 +5,7 @@
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
7
 
8
- <script type="module" crossorigin src="/assets/index-297a3f3d.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-5f125477.js"></script>
9
9
  <link rel="stylesheet" href="/assets/index-a09cacfd.css">
10
10
  </head>
11
11
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hfs",
3
- "version": "0.42.2",
3
+ "version": "0.42.3",
4
4
  "description": "HTTP File Server",
5
5
  "keywords": [
6
6
  "file server",
@@ -19,7 +19,7 @@
19
19
  "build-server": "rm -rf dist/src dist/plugins && tsc --target es2018 && touch package.json && cp -v -r package.json README* LICENSE* plugins dist && find dist -name .DS_Store -delete && node afterbuild.js",
20
20
  "build-frontend": "npm run build --workspace=frontend",
21
21
  "build-admin": "npm run build --workspace=admin",
22
- "server-for-test": "node dist/src --cwd . --config tests",
22
+ "server-for-test": "node dist/src --cwd . --config tests && rm custom.html",
23
23
  "server-for-test-dev": "cross-env DEV=1 nodemon --ignore tests/ --watch src -e ts,tsx --exec ts-node src -- --cwd . --config tests",
24
24
  "test": "mocha -r ts-node/register 'tests/**/*.ts'",
25
25
  "pub": "cd dist && npm publish",
@@ -32,6 +32,7 @@ const apis = {
32
32
  return { list: lodash_1.default.filter(perm_1.accountsConfig.get(), perm_1.accountCanLoginAdmin).map(ac => ac.username) };
33
33
  },
34
34
  set_account({ username, changes }, ctx) {
35
+ var _a;
35
36
  const { admin } = changes;
36
37
  if (admin === null)
37
38
  changes.admin = undefined;
@@ -41,7 +42,7 @@ const apis = {
41
42
  if (!acc)
42
43
  return new apiMiddleware_1.ApiError(const_1.HTTP_BAD_REQUEST);
43
44
  (0, perm_1.setAccount)(acc, changes);
44
- if (changes.username && ctx.session)
45
+ if (changes.username && ((_a = ctx.session) === null || _a === void 0 ? void 0 : _a.username) === username)
45
46
  ctx.session.username = changes.username;
46
47
  return lodash_1.default.pick(acc, 'username');
47
48
  },
package/src/api.vfs.js CHANGED
@@ -86,6 +86,7 @@ const apis = {
86
86
  return n;
87
87
  },
88
88
  async add_vfs({ parent, source, name }) {
89
+ var _a;
89
90
  const n = parent ? await urlToNodeOriginal(parent) : vfs_1.vfs;
90
91
  if (!n)
91
92
  return new apiMiddleware_1.ApiError(const_1.HTTP_NOT_FOUND, 'invalid parent');
@@ -93,13 +94,17 @@ const apis = {
93
94
  return new apiMiddleware_1.ApiError(const_1.HTTP_NOT_ACCEPTABLE, 'invalid parent');
94
95
  if ((0, misc_1.isWindowsDrive)(source))
95
96
  source += '\\'; // slash must be included, otherwise it will refer to the cwd of that drive
97
+ let tryName = (0, vfs_1.getNodeName)({ name, source });
98
+ const ext = (0, path_1.extname)(tryName);
99
+ const noExt = ext ? tryName.slice(0, -ext.length) : tryName;
100
+ let idx = 2;
101
+ while ((_a = n.children) === null || _a === void 0 ? void 0 : _a.find((0, vfs_1.isSameFilenameAs)(tryName)))
102
+ tryName = `${noExt} ${idx++}${ext}`;
103
+ name = tryName;
96
104
  n.children || (n.children = []);
97
- const sameName = name && (0, vfs_1.isSameFilenameAs)(name);
98
- if (n.children.find(x => source && source === x.source || (sameName === null || sameName === void 0 ? void 0 : sameName(x))))
99
- return new apiMiddleware_1.ApiError(const_1.HTTP_CONFLICT, 'already present');
100
105
  n.children.unshift({ source, name });
101
106
  await (0, vfs_1.saveVfs)();
102
- return {};
107
+ return { name };
103
108
  },
104
109
  async del_vfs({ uris }) {
105
110
  if (!uris || !Array.isArray(uris))
package/src/const.js CHANGED
@@ -38,7 +38,7 @@ exports.DEV = process.env.DEV || exports.argv.dev ? 'DEV' : '';
38
38
  exports.ORIGINAL_CWD = process.cwd();
39
39
  exports.HFS_STARTED = new Date();
40
40
  const PKG_PATH = (0, path_1.join)(__dirname, '..', 'package.json');
41
- exports.BUILD_TIMESTAMP = "2023-03-28T13:25:45.798Z";
41
+ exports.BUILD_TIMESTAMP = "2023-03-29T21:48:40.615Z";
42
42
  const pkg = JSON.parse(fs.readFileSync(PKG_PATH, 'utf8'));
43
43
  exports.VERSION = pkg.version;
44
44
  exports.DAY = 86400000;
package/src/vfs.js CHANGED
@@ -104,16 +104,18 @@ function saveVfs() {
104
104
  }
105
105
  exports.saveVfs = saveVfs;
106
106
  function getNodeName(node) {
107
- const { name, source: s } = node;
107
+ const { name, source } = node;
108
108
  if (name)
109
109
  return name;
110
- if (!s)
110
+ if (!source)
111
111
  return ''; // should happen only for root
112
- if (/^[a-zA-Z]:\\?$/.test(s))
113
- return s.slice(0, 2); // exclude trailing slash
114
- const base = (0, path_1.basename)(s);
112
+ if (source === '/')
113
+ return 'root';
114
+ if (/^[a-zA-Z]:\\?$/.test(source))
115
+ return source.slice(0, 2); // exclude trailing slash
116
+ const base = (0, path_1.basename)(source);
115
117
  if (/^[./\\]*$/.test(base)) // if empty or special-chars-only
116
- return (0, path_1.basename)((0, path_1.resolve)(s)); // resolve to try to get more
118
+ return (0, path_1.basename)((0, path_1.resolve)(source)); // resolve to try to get more
117
119
  return base;
118
120
  }
119
121
  exports.getNodeName = getNodeName;