hfs 0.35.0 → 0.36.0

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-0859bb0d.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-44854bd0.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
@@ -7,8 +7,8 @@
7
7
  <link rel="icon"/>
8
8
  <script>SESSION = _HFS_SESSION_</script>
9
9
  <title>File Server</title>
10
- <script type="module" crossorigin src="/assets/index-21e40dc5.js"></script>
11
- <link rel="stylesheet" href="/assets/index-c4c325e9.css">
10
+ <script type="module" crossorigin src="/assets/index-44854bd0.js"></script>
11
+ <link rel="stylesheet" href="/assets/index-216f7ea9.css">
12
12
  </head>
13
13
  <body>
14
14
  <noscript>You need to enable JavaScript to run this app.</noscript>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hfs",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "description": "HTTP File Server",
5
5
  "keywords": [
6
6
  "file server",
@@ -77,6 +77,7 @@ const apis = {
77
77
  function fromCtx(ctx) {
78
78
  return ctx && {
79
79
  user: (0, perm_1.getCurrentUsername)(ctx),
80
+ agent: getBrowser(ctx.get('user-agent')),
80
81
  archive: ctx.state.archive,
81
82
  path: (ctx.fileSource || ctx.state.archive) && ctx.path // only for downloading files
82
83
  };
@@ -102,3 +103,36 @@ function getConnAddress(conn) {
102
103
  port: conn.socket.remotePort,
103
104
  };
104
105
  }
106
+ function getBrowser(agent) {
107
+ for (const [name, re] of Object.entries(BROWSERS))
108
+ if (re.test(agent))
109
+ return name;
110
+ return '';
111
+ }
112
+ const BROWSERS = {
113
+ YaBrowser: /yabrowser/i,
114
+ AlamoFire: /alamofire/i,
115
+ Edge: /edge|edga|edgios|edg/i,
116
+ PhantomJS: /phantomjs/i,
117
+ Konqueror: /konqueror/i,
118
+ Amaya: /amaya/i,
119
+ Epiphany: /epiphany/i,
120
+ SeaMonkey: /seamonkey/i,
121
+ Flock: /flock/i,
122
+ OmniWeb: /omniweb/i,
123
+ Opera: /opera|OPR\//i,
124
+ Chromium: /chromium/i,
125
+ Facebook: /FBA[NV]/,
126
+ Chrome: /chrome|crios/i,
127
+ WinJs: /msapphost/i,
128
+ IE: /msie|trident/i,
129
+ Firefox: /firefox|fxios/i,
130
+ Safari: /safari/i,
131
+ PS5: /playstation 5/i,
132
+ PS4: /playstation 4/i,
133
+ PS3: /playstation 3/i,
134
+ PSP: /playstation portable/i,
135
+ PS: /playstation/i,
136
+ Xbox: /xbox/i,
137
+ UC: /UCBrowser/i,
138
+ };
package/src/api.vfs.js CHANGED
@@ -63,10 +63,14 @@ const apis = {
63
63
  return {};
64
64
  },
65
65
  async set_vfs({ uri, props }) {
66
+ var _a;
66
67
  const n = await urlToNodeOriginal(uri);
67
68
  if (!n)
68
69
  return new apiMiddleware_1.ApiError(const_1.HTTP_NOT_FOUND, 'path not found');
69
70
  props = pickProps(props, ['name', 'source', 'masks', 'default', ...Object.keys(vfs_1.defaultPerms)]);
71
+ const parent = await urlToNodeOriginal((0, path_1.dirname)(uri));
72
+ if ((_a = parent === null || parent === void 0 ? void 0 : parent.children) === null || _a === void 0 ? void 0 : _a.find(x => (0, vfs_1.getNodeName)(x) === props.name))
73
+ return new apiMiddleware_1.ApiError(const_1.HTTP_CONFLICT, 'name already present');
70
74
  props = (0, misc_1.objSameKeys)(props, v => v === null ? undefined : v); // null is a way to serialize undefined, that will restore default values
71
75
  if (props.masks && typeof props.masks !== 'object')
72
76
  delete props.masks;
@@ -84,10 +88,10 @@ const apis = {
84
88
  return new apiMiddleware_1.ApiError(const_1.HTTP_NOT_ACCEPTABLE, 'invalid parent');
85
89
  if ((0, misc_1.isWindowsDrive)(source))
86
90
  source += '\\'; // slash must be included, otherwise it will refer to the cwd of that drive
87
- const a = n.children || (n.children = []);
88
- if (source && a.find(x => x.source === source))
91
+ n.children || (n.children = []);
92
+ if (n.children.find(x => x.source === source || (0, vfs_1.getNodeName)(x) === name))
89
93
  return new apiMiddleware_1.ApiError(const_1.HTTP_CONFLICT, 'already present');
90
- a.unshift({ source, name });
94
+ n.children.unshift({ source, name });
91
95
  await (0, vfs_1.saveVfs)();
92
96
  return {};
93
97
  },
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-02-20T11:41:13.654Z";
41
+ exports.BUILD_TIMESTAMP = "2023-02-22T06:32:57.270Z";
42
42
  const pkg = JSON.parse(fs.readFileSync(PKG_PATH, 'utf8'));
43
43
  exports.VERSION = pkg.version;
44
44
  exports.DAY = 86400000;
@@ -115,7 +115,7 @@ const serveGuiAndSharedFiles = async (ctx, next) => {
115
115
  const canRead = (0, vfs_1.hasPermission)(node, 'can_read', ctx);
116
116
  const isFolder = await (0, vfs_1.nodeIsDirectory)(node);
117
117
  if (isFolder && !path.endsWith('/'))
118
- return ctx.redirect(path + '/');
118
+ return ctx.redirect(ctx.originalUrl + '/');
119
119
  if (canRead && !isFolder)
120
120
  return node.source ? (0, serveFile_1.serveFileNode)(node)(ctx, next)
121
121
  : next();
package/src/upload.js CHANGED
@@ -14,6 +14,7 @@ const config_1 = require("./config");
14
14
  const util_os_1 = require("./util-os");
15
15
  exports.deleteUnfinishedUploadsAfter = (0, config_1.defineConfig)('delete_unfinished_uploads_after');
16
16
  exports.minAvailableMb = (0, config_1.defineConfig)('min_available_mb', 100);
17
+ const dontOverwriteUploading = (0, config_1.defineConfig)('dont_overwrite_uploading', false);
17
18
  const waitingToBeDeleted = {};
18
19
  function uploadWriter(base, path, ctx) {
19
20
  if (!base.source || !(0, vfs_1.hasPermission)(base, 'can_upload', ctx))
@@ -59,12 +60,22 @@ function uploadWriter(base, path, ctx) {
59
60
  }
60
61
  cancelDeletion(tempName);
61
62
  ret.on('close', () => {
62
- if (!ctx.req.aborted)
63
- return fs_1.default.rename(tempName, fullPath, err => {
64
- err && console.error("couldn't rename temp to", fullPath, String(err));
63
+ if (!ctx.req.aborted) {
64
+ let dest = fullPath;
65
+ if (dontOverwriteUploading.get() && fs_1.default.existsSync(dest)) {
66
+ const ext = (0, path_1.extname)(dest);
67
+ const base = dest.slice(0, -ext.length);
68
+ let i = 1;
69
+ do
70
+ dest = `${base} (${i++})${ext}`;
71
+ while (fs_1.default.existsSync(dest));
72
+ }
73
+ return fs_1.default.rename(tempName, dest, err => {
74
+ err && console.error("couldn't rename temp to", dest, String(err));
65
75
  if (resumable)
66
76
  delayedDelete(resumable, 0);
67
77
  });
78
+ }
68
79
  if (resumable) // we don't want to be left with 2 temp files
69
80
  return delayedDelete(tempName, 0);
70
81
  const sec = exports.deleteUnfinishedUploadsAfter.get();
package/src/vfs.js CHANGED
@@ -62,9 +62,9 @@ async function urlToNode(url, ctx, parent = exports.vfs, getRest) {
62
62
  original: child,
63
63
  isTemp: true,
64
64
  };
65
- inheritFromParent(parent, ret);
66
65
  inheritMasks(ret, parent, name);
67
66
  applyMasks(ret, parent, name);
67
+ inheritFromParent(parent, ret);
68
68
  if (child) // yes
69
69
  return urlToNode(rest, ctx, ret, getRest);
70
70
  // not in the tree, we can see consider continuing on the disk
@@ -165,8 +165,8 @@ async function* walkNode(parent, ctx, depth = 0, prefixPath = '') {
165
165
  // we basename for depth>0 where we already have the rest of the path in the parent's url, and would be duplicated
166
166
  const virtualBasename = (0, path_1.basename)(name);
167
167
  item.isTemp = true;
168
- inheritFromParent(parent, item);
169
168
  applyMasks(item, parent, virtualBasename);
169
+ inheritFromParent(parent, item);
170
170
  if (ctx && !hasPermission(item, 'can_see', ctx))
171
171
  return;
172
172
  yield item;
@@ -181,10 +181,10 @@ function applyMasks(item, parent, virtualBasename) {
181
181
  const { masks } = parent;
182
182
  if (!masks)
183
183
  return;
184
- for (const k in masks)
184
+ for (const [k, v] of Object.entries(masks))
185
185
  if (k.startsWith('**/') && (0, micromatch_1.isMatch)(virtualBasename, k.slice(3))
186
186
  || !k.includes('/') && (0, micromatch_1.isMatch)(virtualBasename, k))
187
- Object.assign(item, masks[k]);
187
+ lodash_1.default.defaults(item, v);
188
188
  }
189
189
  function inheritMasks(item, parent, virtualBasename) {
190
190
  const { masks } = parent;
@@ -197,7 +197,7 @@ function inheritMasks(item, parent, virtualBasename) {
197
197
  else if (k.startsWith(virtualBasename + '/'))
198
198
  o[k.slice(virtualBasename.length + 1)] = v;
199
199
  if (Object.keys(o).length)
200
- item.masks = o;
200
+ item.masks = lodash_1.default.defaults(item.masks, o);
201
201
  }
202
202
  function renameUnderPath(rename, path) {
203
203
  if (!rename)