feat: add tus.io protocol support
This commit is contained in:
parent
9bcfa900f9
commit
52010e4907
12
cmd/root.go
12
cmd/root.go
@ -334,9 +334,15 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) {
|
||||
},
|
||||
AuthMethod: "",
|
||||
Branding: settings.Branding{},
|
||||
Commands: nil,
|
||||
Shell: nil,
|
||||
Rules: nil,
|
||||
Tus: settings.Tus{
|
||||
Enabled: true,
|
||||
ChunkSize: settings.DefaultTusChunkSize,
|
||||
ParallelUploads: settings.DefaultTusParallelUploads,
|
||||
RetryCount: settings.DefaultTusRetryCount,
|
||||
},
|
||||
Commands: nil,
|
||||
Shell: nil,
|
||||
Rules: nil,
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
247
frontend/package-lock.json
generated
247
frontend/package-lock.json
generated
@ -21,6 +21,7 @@
|
||||
"noty": "^3.2.0-beta",
|
||||
"pretty-bytes": "^6.0.0",
|
||||
"qrcode.vue": "^1.7.0",
|
||||
"tus-js-client": "^3.0.1",
|
||||
"utif": "^3.1.0",
|
||||
"vue": "^2.6.10",
|
||||
"vue-async-computed": "^3.9.0",
|
||||
@ -3315,10 +3316,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/buffer-from": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
||||
"dev": true
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="
|
||||
},
|
||||
"node_modules/buffer-indexof": {
|
||||
"version": "1.1.1",
|
||||
@ -4088,6 +4088,15 @@
|
||||
"integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/combine-errors": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/combine-errors/-/combine-errors-3.0.3.tgz",
|
||||
"integrity": "sha512-C8ikRNRMygCwaTx+Ek3Yr+OuZzgZjduCOfSQBjbM8V3MfgcjSTeto/GXP6PAwKvJz/v15b7GHZvx5rOlczFw/Q==",
|
||||
"dependencies": {
|
||||
"custom-error-instance": "2.1.1",
|
||||
"lodash.uniqby": "4.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
@ -5042,6 +5051,11 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/custom-error-instance": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/custom-error-instance/-/custom-error-instance-2.1.1.tgz",
|
||||
"integrity": "sha512-p6JFxJc3M4OTD2li2qaHkDCw9SfMw82Ldr6OC9Je1aXiGfhx2W8p3GaoeaGrPJTUN9NirTM/KTxHWMUdR1rsUg=="
|
||||
},
|
||||
"node_modules/cyclist": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz",
|
||||
@ -7065,8 +7079,7 @@
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.6",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
|
||||
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ=="
|
||||
},
|
||||
"node_modules/gzip-size": {
|
||||
"version": "5.1.1",
|
||||
@ -8847,6 +8860,46 @@
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/lodash._baseiteratee": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._baseiteratee/-/lodash._baseiteratee-4.7.0.tgz",
|
||||
"integrity": "sha512-nqB9M+wITz0BX/Q2xg6fQ8mLkyfF7MU7eE+MNBNjTHFKeKaZAPEzEg+E8LWxKWf1DQVflNEn9N49yAuqKh2mWQ==",
|
||||
"dependencies": {
|
||||
"lodash._stringtopath": "~4.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash._basetostring": {
|
||||
"version": "4.12.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._basetostring/-/lodash._basetostring-4.12.0.tgz",
|
||||
"integrity": "sha512-SwcRIbyxnN6CFEEK4K1y+zuApvWdpQdBHM/swxP962s8HIxPO3alBH5t3m/dl+f4CMUug6sJb7Pww8d13/9WSw=="
|
||||
},
|
||||
"node_modules/lodash._baseuniq": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz",
|
||||
"integrity": "sha512-Ja1YevpHZctlI5beLA7oc5KNDhGcPixFhcqSiORHNsp/1QTv7amAXzw+gu4YOvErqVlMVyIJGgtzeepCnnur0A==",
|
||||
"dependencies": {
|
||||
"lodash._createset": "~4.0.0",
|
||||
"lodash._root": "~3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash._createset": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash._createset/-/lodash._createset-4.0.3.tgz",
|
||||
"integrity": "sha512-GTkC6YMprrJZCYU3zcqZj+jkXkrXzq3IPBcF/fIPpNEAB4hZEtXU8zp/RwKOvZl43NUmwDbyRk3+ZTbeRdEBXA=="
|
||||
},
|
||||
"node_modules/lodash._root": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash._root/-/lodash._root-3.0.1.tgz",
|
||||
"integrity": "sha512-O0pWuFSK6x4EXhM1dhZ8gchNtG7JMqBtrHdoUFUWXD7dJnNSUze1GuyQr5sOs0aCvgGeI3o/OJW8f4ca7FDxmQ=="
|
||||
},
|
||||
"node_modules/lodash._stringtopath": {
|
||||
"version": "4.8.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._stringtopath/-/lodash._stringtopath-4.8.0.tgz",
|
||||
"integrity": "sha512-SXL66C731p0xPDC5LZg4wI5H+dJo/EO4KTqOMwLYCH3+FmmfAKJEZCm6ohGpI+T1xwsDsJCfL4OnhorllvlTPQ==",
|
||||
"dependencies": {
|
||||
"lodash._basetostring": "~4.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash.clonedeep": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
@ -8899,6 +8952,15 @@
|
||||
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/lodash.uniqby": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.uniqby/-/lodash.uniqby-4.5.0.tgz",
|
||||
"integrity": "sha512-IRt7cfTtHy6f1aRVA5n7kT8rgN3N1nH6MOWLcHfpWG2SH19E3JksLK38MktLxZDhlAjCP9jpIXkOnRXlu6oByQ==",
|
||||
"dependencies": {
|
||||
"lodash._baseiteratee": "~4.7.0",
|
||||
"lodash._baseuniq": "~4.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/log-symbols": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz",
|
||||
@ -11181,6 +11243,16 @@
|
||||
"integrity": "sha1-mEcocL8igTL8vdhoEputEsPAKeM=",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/proper-lockfile": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/proper-lockfile/-/proper-lockfile-4.1.2.tgz",
|
||||
"integrity": "sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA==",
|
||||
"dependencies": {
|
||||
"graceful-fs": "^4.2.4",
|
||||
"retry": "^0.12.0",
|
||||
"signal-exit": "^3.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-addr": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz",
|
||||
@ -11333,8 +11405,7 @@
|
||||
"node_modules/querystringify": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
|
||||
"integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ=="
|
||||
},
|
||||
"node_modules/randombytes": {
|
||||
"version": "2.1.0",
|
||||
@ -11681,8 +11752,7 @@
|
||||
"node_modules/requires-port": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
|
||||
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=",
|
||||
"dev": true
|
||||
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8="
|
||||
},
|
||||
"node_modules/resolve": {
|
||||
"version": "1.20.0",
|
||||
@ -11751,7 +11821,6 @@
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz",
|
||||
"integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
@ -12132,8 +12201,7 @@
|
||||
"node_modules/signal-exit": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",
|
||||
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="
|
||||
},
|
||||
"node_modules/simple-swizzle": {
|
||||
"version": "0.2.2",
|
||||
@ -13382,6 +13450,36 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/tus-js-client": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/tus-js-client/-/tus-js-client-3.1.0.tgz",
|
||||
"integrity": "sha512-Hfpc8ho4C9Lhs/OflPUA/nHUHZJUrKD5upoPBq7dYJJ9DQhWocsjJU2RZYfN16Y5n19j9dFDszwCvVZ5sfcogw==",
|
||||
"dependencies": {
|
||||
"buffer-from": "^1.1.2",
|
||||
"combine-errors": "^3.0.3",
|
||||
"is-stream": "^2.0.0",
|
||||
"js-base64": "^3.7.2",
|
||||
"lodash.throttle": "^4.1.1",
|
||||
"proper-lockfile": "^4.1.2",
|
||||
"url-parse": "^1.5.7"
|
||||
}
|
||||
},
|
||||
"node_modules/tus-js-client/node_modules/is-stream": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
|
||||
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/tus-js-client/node_modules/js-base64": {
|
||||
"version": "3.7.5",
|
||||
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.5.tgz",
|
||||
"integrity": "sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA=="
|
||||
},
|
||||
"node_modules/tweetnacl": {
|
||||
"version": "0.14.5",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
|
||||
@ -13709,7 +13807,6 @@
|
||||
"version": "1.5.10",
|
||||
"resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz",
|
||||
"integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"querystringify": "^2.1.1",
|
||||
"requires-port": "^1.0.0"
|
||||
@ -18142,10 +18239,9 @@
|
||||
}
|
||||
},
|
||||
"buffer-from": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
||||
"dev": true
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="
|
||||
},
|
||||
"buffer-indexof": {
|
||||
"version": "1.1.1",
|
||||
@ -18771,6 +18867,15 @@
|
||||
"integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==",
|
||||
"dev": true
|
||||
},
|
||||
"combine-errors": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/combine-errors/-/combine-errors-3.0.3.tgz",
|
||||
"integrity": "sha512-C8ikRNRMygCwaTx+Ek3Yr+OuZzgZjduCOfSQBjbM8V3MfgcjSTeto/GXP6PAwKvJz/v15b7GHZvx5rOlczFw/Q==",
|
||||
"requires": {
|
||||
"custom-error-instance": "2.1.1",
|
||||
"lodash.uniqby": "4.5.0"
|
||||
}
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
@ -19531,6 +19636,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"custom-error-instance": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/custom-error-instance/-/custom-error-instance-2.1.1.tgz",
|
||||
"integrity": "sha512-p6JFxJc3M4OTD2li2qaHkDCw9SfMw82Ldr6OC9Je1aXiGfhx2W8p3GaoeaGrPJTUN9NirTM/KTxHWMUdR1rsUg=="
|
||||
},
|
||||
"cyclist": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz",
|
||||
@ -21146,8 +21256,7 @@
|
||||
"graceful-fs": {
|
||||
"version": "4.2.6",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
|
||||
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ=="
|
||||
},
|
||||
"gzip-size": {
|
||||
"version": "5.1.1",
|
||||
@ -22521,6 +22630,46 @@
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||
"dev": true
|
||||
},
|
||||
"lodash._baseiteratee": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._baseiteratee/-/lodash._baseiteratee-4.7.0.tgz",
|
||||
"integrity": "sha512-nqB9M+wITz0BX/Q2xg6fQ8mLkyfF7MU7eE+MNBNjTHFKeKaZAPEzEg+E8LWxKWf1DQVflNEn9N49yAuqKh2mWQ==",
|
||||
"requires": {
|
||||
"lodash._stringtopath": "~4.8.0"
|
||||
}
|
||||
},
|
||||
"lodash._basetostring": {
|
||||
"version": "4.12.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._basetostring/-/lodash._basetostring-4.12.0.tgz",
|
||||
"integrity": "sha512-SwcRIbyxnN6CFEEK4K1y+zuApvWdpQdBHM/swxP962s8HIxPO3alBH5t3m/dl+f4CMUug6sJb7Pww8d13/9WSw=="
|
||||
},
|
||||
"lodash._baseuniq": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz",
|
||||
"integrity": "sha512-Ja1YevpHZctlI5beLA7oc5KNDhGcPixFhcqSiORHNsp/1QTv7amAXzw+gu4YOvErqVlMVyIJGgtzeepCnnur0A==",
|
||||
"requires": {
|
||||
"lodash._createset": "~4.0.0",
|
||||
"lodash._root": "~3.0.0"
|
||||
}
|
||||
},
|
||||
"lodash._createset": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash._createset/-/lodash._createset-4.0.3.tgz",
|
||||
"integrity": "sha512-GTkC6YMprrJZCYU3zcqZj+jkXkrXzq3IPBcF/fIPpNEAB4hZEtXU8zp/RwKOvZl43NUmwDbyRk3+ZTbeRdEBXA=="
|
||||
},
|
||||
"lodash._root": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash._root/-/lodash._root-3.0.1.tgz",
|
||||
"integrity": "sha512-O0pWuFSK6x4EXhM1dhZ8gchNtG7JMqBtrHdoUFUWXD7dJnNSUze1GuyQr5sOs0aCvgGeI3o/OJW8f4ca7FDxmQ=="
|
||||
},
|
||||
"lodash._stringtopath": {
|
||||
"version": "4.8.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._stringtopath/-/lodash._stringtopath-4.8.0.tgz",
|
||||
"integrity": "sha512-SXL66C731p0xPDC5LZg4wI5H+dJo/EO4KTqOMwLYCH3+FmmfAKJEZCm6ohGpI+T1xwsDsJCfL4OnhorllvlTPQ==",
|
||||
"requires": {
|
||||
"lodash._basetostring": "~4.12.0"
|
||||
}
|
||||
},
|
||||
"lodash.clonedeep": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
@ -22573,6 +22722,15 @@
|
||||
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.uniqby": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.uniqby/-/lodash.uniqby-4.5.0.tgz",
|
||||
"integrity": "sha512-IRt7cfTtHy6f1aRVA5n7kT8rgN3N1nH6MOWLcHfpWG2SH19E3JksLK38MktLxZDhlAjCP9jpIXkOnRXlu6oByQ==",
|
||||
"requires": {
|
||||
"lodash._baseiteratee": "~4.7.0",
|
||||
"lodash._baseuniq": "~4.6.0"
|
||||
}
|
||||
},
|
||||
"log-symbols": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz",
|
||||
@ -24460,6 +24618,16 @@
|
||||
"integrity": "sha1-mEcocL8igTL8vdhoEputEsPAKeM=",
|
||||
"dev": true
|
||||
},
|
||||
"proper-lockfile": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/proper-lockfile/-/proper-lockfile-4.1.2.tgz",
|
||||
"integrity": "sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA==",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.2.4",
|
||||
"retry": "^0.12.0",
|
||||
"signal-exit": "^3.0.2"
|
||||
}
|
||||
},
|
||||
"proxy-addr": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz",
|
||||
@ -24592,8 +24760,7 @@
|
||||
"querystringify": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
|
||||
"integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ=="
|
||||
},
|
||||
"randombytes": {
|
||||
"version": "2.1.0",
|
||||
@ -24879,8 +25046,7 @@
|
||||
"requires-port": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
|
||||
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=",
|
||||
"dev": true
|
||||
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8="
|
||||
},
|
||||
"resolve": {
|
||||
"version": "1.20.0",
|
||||
@ -24932,8 +25098,7 @@
|
||||
"retry": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz",
|
||||
"integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=",
|
||||
"dev": true
|
||||
"integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs="
|
||||
},
|
||||
"rgb-regex": {
|
||||
"version": "1.0.1",
|
||||
@ -25264,8 +25429,7 @@
|
||||
"signal-exit": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",
|
||||
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="
|
||||
},
|
||||
"simple-swizzle": {
|
||||
"version": "0.2.2",
|
||||
@ -26306,6 +26470,32 @@
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"tus-js-client": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/tus-js-client/-/tus-js-client-3.1.0.tgz",
|
||||
"integrity": "sha512-Hfpc8ho4C9Lhs/OflPUA/nHUHZJUrKD5upoPBq7dYJJ9DQhWocsjJU2RZYfN16Y5n19j9dFDszwCvVZ5sfcogw==",
|
||||
"requires": {
|
||||
"buffer-from": "^1.1.2",
|
||||
"combine-errors": "^3.0.3",
|
||||
"is-stream": "^2.0.0",
|
||||
"js-base64": "^3.7.2",
|
||||
"lodash.throttle": "^4.1.1",
|
||||
"proper-lockfile": "^4.1.2",
|
||||
"url-parse": "^1.5.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-stream": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
|
||||
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg=="
|
||||
},
|
||||
"js-base64": {
|
||||
"version": "3.7.5",
|
||||
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.5.tgz",
|
||||
"integrity": "sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"tweetnacl": {
|
||||
"version": "0.14.5",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
|
||||
@ -26575,7 +26765,6 @@
|
||||
"version": "1.5.10",
|
||||
"resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz",
|
||||
"integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"querystringify": "^2.1.1",
|
||||
"requires-port": "^1.0.0"
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
"noty": "^3.2.0-beta",
|
||||
"pretty-bytes": "^6.0.0",
|
||||
"qrcode.vue": "^1.7.0",
|
||||
"tus-js-client": "^3.0.1",
|
||||
"utif": "^3.1.0",
|
||||
"vue": "^2.6.10",
|
||||
"vue-async-computed": "^3.9.0",
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { createURL, fetchURL, removePrefix } from "./utils";
|
||||
import { baseURL } from "@/utils/constants";
|
||||
import store from "@/store";
|
||||
import { upload as postTus, useTus } from "./tus";
|
||||
|
||||
export async function fetch(url) {
|
||||
url = removePrefix(url);
|
||||
@ -78,6 +79,22 @@ export function download(format, ...files) {
|
||||
}
|
||||
|
||||
export async function post(url, content = "", overwrite = false, onupload) {
|
||||
// Use the pre-existing API if:
|
||||
const useResourcesApi =
|
||||
// a folder is being created
|
||||
url.endsWith("/") ||
|
||||
// We're not using http(s)
|
||||
(content instanceof Blob &&
|
||||
!["http:", "https:"].includes(window.location.protocol)) ||
|
||||
// Tus is disabled / not applicable
|
||||
!(await useTus(content));
|
||||
|
||||
return useResourcesApi
|
||||
? postResources(url, content, overwrite, onupload)
|
||||
: postTus(url, content, overwrite, onupload);
|
||||
}
|
||||
|
||||
async function postResources(url, content = "", overwrite = false, onupload) {
|
||||
url = removePrefix(url);
|
||||
|
||||
let bufferContent;
|
||||
|
||||
89
frontend/src/api/tus.js
Normal file
89
frontend/src/api/tus.js
Normal file
@ -0,0 +1,89 @@
|
||||
import * as tus from "tus-js-client";
|
||||
import { tusEndpoint, tusSettings } from "@/utils/constants";
|
||||
import store from "@/store";
|
||||
import { removePrefix } from "@/api/utils";
|
||||
|
||||
const RETRY_BASE_DELAY = 1000;
|
||||
const RETRY_MAX_DELAY = 20000;
|
||||
|
||||
export async function upload(url, content = "", overwrite = false, onupload) {
|
||||
if (!tusSettings) {
|
||||
// Shouldn't happen as we check for tus support before calling this function
|
||||
throw new Error("Tus.io settings are not defined");
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
var upload = new tus.Upload(content, {
|
||||
endpoint: tusEndpoint,
|
||||
chunkSize: tusSettings.chunkSize,
|
||||
retryDelays: computeRetryDelays(tusSettings),
|
||||
parallelUploads: tusSettings.parallelUploads || 1,
|
||||
metadata: {
|
||||
filename: content.name,
|
||||
filetype: content.type,
|
||||
overwrite: overwrite.toString(),
|
||||
// url is URI encoded and needs to be decoded for metadata first
|
||||
destination: decodeURIComponent(removePrefix(url)),
|
||||
},
|
||||
headers: {
|
||||
"X-Auth": store.state.jwt,
|
||||
},
|
||||
onError: function (error) {
|
||||
reject("Upload failed: " + error);
|
||||
},
|
||||
onProgress: function (bytesUploaded) {
|
||||
// Emulate ProgressEvent.loaded which is used by calling functions
|
||||
// loaded is specified in bytes (https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent/loaded)
|
||||
if (typeof onupload === "function") {
|
||||
onupload({ loaded: bytesUploaded });
|
||||
}
|
||||
},
|
||||
onSuccess: function () {
|
||||
resolve();
|
||||
},
|
||||
});
|
||||
|
||||
upload.findPreviousUploads().then(function (previousUploads) {
|
||||
if (previousUploads.length) {
|
||||
upload.resumeFromPreviousUpload(previousUploads[0]);
|
||||
}
|
||||
upload.start();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function computeRetryDelays(tusSettings) {
|
||||
if (!tusSettings.retryCount || tusSettings.retryCount < 1) {
|
||||
// Disable retries altogether
|
||||
return null;
|
||||
}
|
||||
// The tus client expects our retries as an array with computed backoffs
|
||||
// E.g.: [0, 3000, 5000, 10000, 20000]
|
||||
const retryDelays = [];
|
||||
let delay = 0;
|
||||
|
||||
for (let i = 0; i < tusSettings.retryCount; i++) {
|
||||
retryDelays.push(Math.min(delay, RETRY_MAX_DELAY));
|
||||
delay =
|
||||
delay === 0 ? RETRY_BASE_DELAY : Math.min(delay * 2, RETRY_MAX_DELAY);
|
||||
}
|
||||
|
||||
return retryDelays;
|
||||
}
|
||||
|
||||
export async function useTus(content) {
|
||||
if (!isTusSupported() || !(content instanceof Blob)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// use tus if tus uploads are enabled and the content's size is larger than chunkSize
|
||||
return (
|
||||
tusSettings &&
|
||||
tusSettings.enabled === true &&
|
||||
content.size > tusSettings.chunkSize
|
||||
);
|
||||
}
|
||||
|
||||
function isTusSupported() {
|
||||
return tus.isSupported === true;
|
||||
}
|
||||
@ -376,6 +376,16 @@ body.rtl .breadcrumbs .chevron {
|
||||
}
|
||||
}
|
||||
|
||||
/* * * * * * * * * * * * * * * *
|
||||
* SETTINGS TUS *
|
||||
* * * * * * * * * * * * * * * */
|
||||
|
||||
.tusConditionalSettings input:disabled {
|
||||
background-color: #ddd;
|
||||
color: #999;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* * * * * * * * * * * * * * * *
|
||||
* SETTINGS RULES *
|
||||
* * * * * * * * * * * * * * * */
|
||||
|
||||
@ -185,6 +185,12 @@
|
||||
"commandRunnerHelp": "Here you can set commands that are executed in the named events. You must write one per line. The environment variables {0} and {1} will be available, being {0} relative to {1}. For more information about this feature and the available environment variables, please read the {2}.",
|
||||
"commandsUpdated": "Commands updated!",
|
||||
"createUserDir": "Auto create user home dir while adding new user",
|
||||
"tusUploads": "Chunked Uploads",
|
||||
"tusUploadsHelp": "File Browser supports the tus.io protocol for resumable file uploads, allowing for the creation of efficient, reliable, resumable and chunked file uploads even on unreliable networks.",
|
||||
"tusUploadsEnabled": "Enable chunked file uploads",
|
||||
"tusUploadsParallelUploads": "Number of parallel uploads",
|
||||
"tusUploadsChunkSize": "Indicates to maximum size of a request (direct uploads will be used for smaller uploads). You may input a plain integer denoting a bytes input or a string like 10MB, 1.00Ti etc.",
|
||||
"tusUploadsRetryCount": "Number of times to retry a failed upload (set to 0 to disable retries)",
|
||||
"userHomeBasePath": "Base path for user home directories",
|
||||
"userScopeGenerationPlaceholder": "The scope will be auto generated",
|
||||
"createUserHomeDirectory": "Create user home directory",
|
||||
|
||||
@ -15,7 +15,9 @@ const theme = window.FileBrowser.Theme;
|
||||
const enableThumbs = window.FileBrowser.EnableThumbs;
|
||||
const resizePreview = window.FileBrowser.ResizePreview;
|
||||
const enableExec = window.FileBrowser.EnableExec;
|
||||
const tusSettings = window.FileBrowser.TusSettings;
|
||||
const origin = window.location.origin;
|
||||
const tusEndpoint = `${baseURL}/api/tus`;
|
||||
|
||||
export {
|
||||
name,
|
||||
@ -34,5 +36,7 @@ export {
|
||||
enableThumbs,
|
||||
resizePreview,
|
||||
enableExec,
|
||||
tusSettings,
|
||||
origin,
|
||||
tusEndpoint,
|
||||
};
|
||||
|
||||
@ -101,6 +101,56 @@
|
||||
id="branding-files"
|
||||
/>
|
||||
</p>
|
||||
|
||||
<h3>{{ $t("settings.tusUploads") }}</h3>
|
||||
|
||||
<p class="small">{{ $t("settings.tusUploadsHelp") }}</p>
|
||||
|
||||
<p>
|
||||
<input
|
||||
type="checkbox"
|
||||
v-model="settings.tus.enabled"
|
||||
id="tus-enabled"
|
||||
/>
|
||||
{{ $t("settings.tusUploadsEnabled") }}
|
||||
</p>
|
||||
|
||||
<div class="tusConditionalSettings">
|
||||
<label for="tus-parallelUploads">{{
|
||||
$t("settings.tusUploadsParallelUploads")
|
||||
}}</label>
|
||||
<input
|
||||
class="input input--block"
|
||||
type="number"
|
||||
v-model.number="settings.tus.parallelUploads"
|
||||
id="tus-parallelUploads"
|
||||
v-bind:disabled="!settings.tus.enabled"
|
||||
min="1"
|
||||
/>
|
||||
|
||||
<label for="tus-chunkSize">{{
|
||||
$t("settings.tusUploadsChunkSize")
|
||||
}}</label>
|
||||
<input
|
||||
class="input input--block"
|
||||
type="text"
|
||||
v-model="formattedChunkSize"
|
||||
id="tus-chunkSize"
|
||||
v-bind:disabled="!settings.tus.enabled"
|
||||
/>
|
||||
|
||||
<label for="tus-retryCount">{{
|
||||
$t("settings.tusUploadsRetryCount")
|
||||
}}</label>
|
||||
<input
|
||||
class="input input--block"
|
||||
type="number"
|
||||
v-model.number="settings.tus.retryCount"
|
||||
id="tus-retryCount"
|
||||
v-bind:disabled="!settings.tus.enabled"
|
||||
min="0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-action">
|
||||
@ -210,11 +260,30 @@ export default {
|
||||
error: null,
|
||||
originalSettings: null,
|
||||
settings: null,
|
||||
debounceTimeout: null,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapState(["user", "loading"]),
|
||||
isExecEnabled: () => enableExec,
|
||||
formattedChunkSize: {
|
||||
get() {
|
||||
return this.formatBytes(this.settings.tus.chunkSize);
|
||||
},
|
||||
set(value) {
|
||||
// Use debouncing to allow the user to type freely without
|
||||
// interruption by the formatter
|
||||
// Clear the previous timeout if it exists
|
||||
if (this.debounceTimeout) {
|
||||
clearTimeout(this.debounceTimeout);
|
||||
}
|
||||
|
||||
// Set a new timeout to apply the format after a short delay
|
||||
this.debounceTimeout = setTimeout(() => {
|
||||
this.settings.tus.chunkSize = this.parseBytes(value);
|
||||
}, 1500);
|
||||
},
|
||||
},
|
||||
},
|
||||
async created() {
|
||||
try {
|
||||
@ -275,6 +344,45 @@ export default {
|
||||
this.$showError(e);
|
||||
}
|
||||
},
|
||||
// Parse the user-friendly input (e.g., "20M" or "1T") to bytes
|
||||
parseBytes(input) {
|
||||
const regex = /^(\d+\.?\d*)([BKMGT]?[B|I]?)$/i;
|
||||
const matches = input.match(regex);
|
||||
if (matches) {
|
||||
const size = parseFloat(matches[1]);
|
||||
const unit = matches[2].toUpperCase();
|
||||
const units = {
|
||||
KB: 1e3,
|
||||
MB: 1e6,
|
||||
GB: 1e9,
|
||||
TB: 1e12,
|
||||
KI: 1024,
|
||||
MI: 1024 ** 2,
|
||||
GI: 1024 ** 3,
|
||||
TI: 1024 ** 4,
|
||||
};
|
||||
return size * (units[unit] || 1);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
// Format the chunk size in bytes to user-friendly format
|
||||
formatBytes(bytes) {
|
||||
const units = ["B", "Ki", "Mi", "Gi", "Ti"];
|
||||
let size = bytes;
|
||||
let unitIndex = 0;
|
||||
while (size >= 1024 && unitIndex < units.length - 1) {
|
||||
size /= 1024;
|
||||
unitIndex++;
|
||||
}
|
||||
return `${size.toFixed(2)}${units[unitIndex]}`;
|
||||
},
|
||||
// Clear the debounce timeout when the component is destroyed
|
||||
beforeDestroy() {
|
||||
if (this.debounceTimeout) {
|
||||
clearTimeout(this.debounceTimeout);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
18
go.mod
18
go.mod
@ -20,18 +20,19 @@ require (
|
||||
github.com/spf13/cobra v1.6.1
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/spf13/viper v1.15.0
|
||||
github.com/stretchr/testify v1.8.1
|
||||
github.com/stretchr/testify v1.8.2
|
||||
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce
|
||||
go.etcd.io/bbolt v1.3.7
|
||||
golang.org/x/crypto v0.6.0
|
||||
golang.org/x/image v0.5.0
|
||||
golang.org/x/text v0.7.0
|
||||
golang.org/x/text v0.8.0
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.1 // indirect
|
||||
github.com/andybalholm/brotli v1.0.4 // indirect
|
||||
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
|
||||
github.com/dsoprea/go-logging v0.0.0-20200517223158-a10564966e9d // indirect
|
||||
@ -40,25 +41,26 @@ require (
|
||||
github.com/go-errors/errors v1.1.1 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/golang/geo v0.0.0-20200319012246-673a6f80352d // indirect
|
||||
github.com/golang/snappy v0.0.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.1 // indirect
|
||||
github.com/klauspost/compress v1.11.4 // indirect
|
||||
github.com/klauspost/compress v1.15.9 // indirect
|
||||
github.com/klauspost/pgzip v1.2.5 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/nwaples/rardecode v1.1.0 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.2 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.15 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||
github.com/spf13/cast v1.5.0 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/subosito/gotenv v1.4.2 // indirect
|
||||
github.com/tus/tusd v1.11.0 // indirect
|
||||
github.com/ulikunitz/xz v0.5.9 // indirect
|
||||
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
golang.org/x/net v0.6.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
golang.org/x/net v0.8.0 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@ -65,6 +65,13 @@ func NewHandler(
|
||||
api.PathPrefix("/resources").Handler(monkey(resourcePutHandler, "/api/resources")).Methods("PUT")
|
||||
api.PathPrefix("/resources").Handler(monkey(resourcePatchHandler(fileCache), "/api/resources")).Methods("PATCH")
|
||||
|
||||
const tusPath = "/tus"
|
||||
tusHandler, err := NewTusHandler(store, server, "/api"+tusPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
api.PathPrefix(tusPath).Handler(tusHandler)
|
||||
|
||||
api.PathPrefix("/usage").Handler(monkey(diskUsage, "/api/usage")).Methods("GET")
|
||||
|
||||
api.Path("/shares").Handler(monkey(shareListHandler, "/api/shares")).Methods("GET")
|
||||
|
||||
@ -15,6 +15,7 @@ type settingsData struct {
|
||||
Defaults settings.UserDefaults `json:"defaults"`
|
||||
Rules []rules.Rule `json:"rules"`
|
||||
Branding settings.Branding `json:"branding"`
|
||||
Tus settings.Tus `json:"tus"`
|
||||
Shell []string `json:"shell"`
|
||||
Commands map[string][]string `json:"commands"`
|
||||
}
|
||||
@ -27,6 +28,7 @@ var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request,
|
||||
Defaults: d.settings.Defaults,
|
||||
Rules: d.settings.Rules,
|
||||
Branding: d.settings.Branding,
|
||||
Tus: d.settings.Tus,
|
||||
Shell: d.settings.Shell,
|
||||
Commands: d.settings.Commands,
|
||||
}
|
||||
@ -47,6 +49,7 @@ var settingsPutHandler = withAdmin(func(w http.ResponseWriter, r *http.Request,
|
||||
d.settings.Defaults = req.Defaults
|
||||
d.settings.Rules = req.Rules
|
||||
d.settings.Branding = req.Branding
|
||||
d.settings.Tus = req.Tus
|
||||
d.settings.Shell = req.Shell
|
||||
d.settings.Commands = req.Commands
|
||||
|
||||
|
||||
@ -44,6 +44,7 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys
|
||||
"EnableThumbs": d.server.EnableThumbnails,
|
||||
"ResizePreview": d.server.ResizePreview,
|
||||
"EnableExec": d.server.EnableExec,
|
||||
"TusSettings": d.settings.Tus,
|
||||
}
|
||||
|
||||
if d.settings.Branding.Files != "" {
|
||||
|
||||
271
http/tus.go
Normal file
271
http/tus.go
Normal file
@ -0,0 +1,271 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/tus/tusd/pkg/filestore"
|
||||
tusd "github.com/tus/tusd/pkg/handler"
|
||||
|
||||
"github.com/filebrowser/filebrowser/v2/settings"
|
||||
"github.com/filebrowser/filebrowser/v2/storage"
|
||||
"github.com/filebrowser/filebrowser/v2/users"
|
||||
)
|
||||
|
||||
const uploadDirName = ".tmp_upload"
|
||||
|
||||
type TusHandler struct {
|
||||
store *storage.Storage
|
||||
server *settings.Server
|
||||
settings *settings.Settings
|
||||
tusdHandlers map[uint]*tusd.UnroutedHandler
|
||||
notifyNewTusdHandler chan struct{}
|
||||
apiPath string
|
||||
mutex *sync.Mutex
|
||||
}
|
||||
|
||||
func NewTusHandler(store *storage.Storage, server *settings.Server, apiPath string) (TusHandler, error) {
|
||||
tusHandler := TusHandler{}
|
||||
tusHandler.store = store
|
||||
tusHandler.server = server
|
||||
tusHandler.tusdHandlers = make(map[uint]*tusd.UnroutedHandler)
|
||||
tusHandler.notifyNewTusdHandler = make(chan struct{})
|
||||
tusHandler.apiPath = apiPath
|
||||
tusHandler.mutex = &sync.Mutex{}
|
||||
|
||||
var err error
|
||||
if tusHandler.settings, err = store.Settings.Get(); err != nil {
|
||||
return tusHandler, fmt.Errorf("couldn't get settings: %w", err)
|
||||
}
|
||||
|
||||
// Create a goroutine that handles uploaded file events for all users
|
||||
go tusHandler.handleFileUploadedEvents()
|
||||
|
||||
return tusHandler, nil
|
||||
}
|
||||
|
||||
func (th TusHandler) getOrCreateTusdHandler(d *data, r *http.Request) (*tusd.UnroutedHandler, error) {
|
||||
// Use a mutex to make sure only one tus handler is created for each user
|
||||
th.mutex.Lock()
|
||||
defer th.mutex.Unlock()
|
||||
|
||||
tusdHandler, ok := th.tusdHandlers[d.user.ID]
|
||||
log.Printf("Getting tus handler for user %s with basePath %s\n", d.user.Username, d.user.FullPath("/"))
|
||||
if !ok {
|
||||
// If we don't define an absolute URL for tusd, it creates an absolute URL for us that the client will use.
|
||||
// See tusd/handler/unrouted_handler.go/absFileURL() for details.
|
||||
// This URL's scheme will be http in our case (as we don't use tusd's inbuilt TLS feature),
|
||||
// which is fine if we don't use both a browser and a reverse proxy that terminates SSL for us.
|
||||
// In case we do, we need to define an absolute URL with the correct scheme, or we'll get mixed content errors.
|
||||
// We can extract the correct scheme and host from the origin request header, if it exists (which always is the case for browsers).
|
||||
var origin string
|
||||
if originHeader, ok := r.Header["Origin"]; ok && len(originHeader) > 0 {
|
||||
origin = originHeader[0]
|
||||
}
|
||||
basePath, err := url.JoinPath(origin, th.server.BaseURL, th.apiPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Printf("Creating tus handler for user %s on path %s\n", d.user.Username, basePath)
|
||||
tusdHandler, err := th.createTusdHandler(d, basePath) //nolint:govet
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
th.tusdHandlers[d.user.ID] = tusdHandler
|
||||
th.notifyNewTusdHandler <- struct{}{}
|
||||
}
|
||||
|
||||
return tusdHandler, nil
|
||||
}
|
||||
|
||||
func (th TusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
code, err := withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||
// Create a new tus handler for current user if it doesn't exist yet
|
||||
tusdHandler, err := th.getOrCreateTusdHandler(d, r)
|
||||
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, err
|
||||
}
|
||||
|
||||
// Create upload directory for each request
|
||||
uploadDir := filepath.Join(d.user.FullPath("/"), uploadDirName)
|
||||
if err := os.MkdirAll(uploadDir, os.ModePerm); err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
switch r.Method {
|
||||
case "POST":
|
||||
tusdHandler.PostFile(w, r)
|
||||
case "HEAD":
|
||||
tusdHandler.HeadFile(w, r)
|
||||
case "PATCH":
|
||||
tusdHandler.PatchFile(w, r)
|
||||
default:
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
|
||||
// Isn't used
|
||||
return http.StatusNoContent, nil
|
||||
})(w, r, &data{
|
||||
store: th.store,
|
||||
settings: th.settings,
|
||||
server: th.server,
|
||||
})
|
||||
|
||||
switch {
|
||||
case err != nil:
|
||||
http.Error(w, err.Error(), code)
|
||||
case code >= http.StatusBadRequest:
|
||||
http.Error(w, "", code)
|
||||
}
|
||||
}
|
||||
|
||||
func (th TusHandler) createTusdHandler(d *data, basePath string) (*tusd.UnroutedHandler, error) {
|
||||
uploadDir := filepath.Join(d.user.FullPath("/"), uploadDirName)
|
||||
tusStore := filestore.FileStore{
|
||||
Path: uploadDir,
|
||||
}
|
||||
composer := tusd.NewStoreComposer()
|
||||
tusStore.UseIn(composer)
|
||||
|
||||
tusdHandler, err := tusd.NewUnroutedHandler(tusd.Config{
|
||||
BasePath: basePath,
|
||||
StoreComposer: composer,
|
||||
NotifyCompleteUploads: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to create tusdHandler: %w", err)
|
||||
}
|
||||
|
||||
return tusdHandler, nil
|
||||
}
|
||||
|
||||
func getMetadataField(metadata tusd.MetaData, field string) (string, error) {
|
||||
if value, ok := metadata[field]; ok {
|
||||
return value, nil
|
||||
} else {
|
||||
return "", fmt.Errorf("metadata field %s not found in upload request", field)
|
||||
}
|
||||
}
|
||||
|
||||
func (th TusHandler) handleFileUploadedEvents() {
|
||||
// Instead of running a goroutine for each user, we use a single goroutine that handles events for all users.
|
||||
// This works by using a reflect select statement that waits for events from all users.
|
||||
// On top of this, the reflect select statement also waits for a notification channel that is used to notify
|
||||
// the goroutine when a new user has been added to so that the reflect select statement can be updated.
|
||||
for {
|
||||
cases := make([]reflect.SelectCase, len(th.tusdHandlers)+1)
|
||||
// UserIDs != position in select statement, so store mapping
|
||||
caseIdsToUserIds := make(map[int]uint, len(th.tusdHandlers))
|
||||
cases[0] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(th.notifyNewTusdHandler)}
|
||||
i := 1
|
||||
for userID, tusdHandler := range th.tusdHandlers {
|
||||
cases[i] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(tusdHandler.CompleteUploads)}
|
||||
caseIdsToUserIds[i] = userID
|
||||
i++
|
||||
}
|
||||
|
||||
for {
|
||||
chosen, value, _ := reflect.Select(cases)
|
||||
if chosen == 0 {
|
||||
// Notification channel has been triggered,
|
||||
// so we need to update the reflect select statement
|
||||
break
|
||||
}
|
||||
|
||||
// Get user ID from reflect select statement
|
||||
userID := caseIdsToUserIds[chosen]
|
||||
user, err := th.store.Users.Get(th.server.Root, userID)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: couldn't get user with ID %d: %s\n", userID, err)
|
||||
continue
|
||||
}
|
||||
event := value.Interface().(tusd.HookEvent)
|
||||
if err := th.handleFileUploaded(user, &event); err != nil {
|
||||
log.Printf("ERROR: couldn't handle completed upload: %s\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (th TusHandler) handleFileUploaded(user *users.User, event *tusd.HookEvent) error {
|
||||
// Clean up only if an upload has been finalized
|
||||
if !event.Upload.IsFinal {
|
||||
return nil
|
||||
}
|
||||
|
||||
filename, err := getMetadataField(event.Upload.MetaData, "filename")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
destination, err := getMetadataField(event.Upload.MetaData, "destination")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
overwriteStr, err := getMetadataField(event.Upload.MetaData, "overwrite")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userPath := user.FullPath("/")
|
||||
uploadDir := filepath.Join(userPath, uploadDirName)
|
||||
uploadedFile := filepath.Join(uploadDir, event.Upload.ID)
|
||||
fullDestination := filepath.Join(userPath, destination)
|
||||
|
||||
log.Printf("Upload of %s (%s) is finished. Moving file to destination (%s) "+
|
||||
"and cleaning up temporary files.\n", filename, uploadedFile, fullDestination)
|
||||
|
||||
// Check if destination file already exists. If so, we require overwrite to be set
|
||||
if _, err := os.Stat(fullDestination); !errors.Is(err, os.ErrNotExist) {
|
||||
if overwrite, err := strconv.ParseBool(overwriteStr); err != nil {
|
||||
return err
|
||||
} else if !overwrite {
|
||||
return fmt.Errorf("overwrite is set to false while destination file %s exists", destination)
|
||||
}
|
||||
}
|
||||
|
||||
// Move uploaded file from tmp upload folder to user folder
|
||||
if err := os.Rename(uploadedFile, fullDestination); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return th.removeTemporaryFiles(uploadDir, &event.Upload)
|
||||
}
|
||||
|
||||
func (th TusHandler) removeTemporaryFiles(uploadDir string, upload *tusd.FileInfo) error {
|
||||
// Remove uploaded tmp files for finished upload (.info objects are created and need to be removed, too))
|
||||
for _, partialUpload := range append(upload.PartialUploads, upload.ID) {
|
||||
filesToDelete, err := filepath.Glob(filepath.Join(uploadDir, partialUpload+"*"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range filesToDelete {
|
||||
if err := os.Remove(f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete folder basePath if it is empty after the request
|
||||
dir, err := os.ReadDir(uploadDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(dir) == 0 {
|
||||
// os.Remove won't remove non-empty folders in case of race condition
|
||||
if err := os.Remove(uploadDir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -21,6 +21,7 @@ type Settings struct {
|
||||
Defaults UserDefaults `json:"defaults"`
|
||||
AuthMethod AuthMethod `json:"authMethod"`
|
||||
Branding Branding `json:"branding"`
|
||||
Tus Tus `json:"tus"`
|
||||
Commands map[string][]string `json:"commands"`
|
||||
Shell []string `json:"shell"`
|
||||
Rules []rules.Rule `json:"rules"`
|
||||
|
||||
@ -33,6 +33,14 @@ func (s *Storage) Get() (*Settings, error) {
|
||||
if set.UserHomeBasePath == "" {
|
||||
set.UserHomeBasePath = DefaultUsersHomeBasePath
|
||||
}
|
||||
if set.Tus == (Tus{}) {
|
||||
set.Tus = Tus{
|
||||
Enabled: false,
|
||||
ChunkSize: DefaultTusChunkSize,
|
||||
ParallelUploads: DefaultTusParallelUploads,
|
||||
RetryCount: DefaultTusRetryCount,
|
||||
}
|
||||
}
|
||||
return set, nil
|
||||
}
|
||||
|
||||
|
||||
13
settings/tus.go
Normal file
13
settings/tus.go
Normal file
@ -0,0 +1,13 @@
|
||||
package settings
|
||||
|
||||
const DefaultTusChunkSize = 20 * 1024 * 1024 // 20MB
|
||||
const DefaultTusParallelUploads = 3
|
||||
const DefaultTusRetryCount = 3
|
||||
|
||||
// Tus contains the tus.io settings of the app.
|
||||
type Tus struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
ChunkSize uint64 `json:"chunkSize"`
|
||||
ParallelUploads uint8 `json:"parallelUploads"`
|
||||
RetryCount uint16 `json:"retryCount"`
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user