support gzip for api requests
Massimo Melina committed
Dec 21, 2021 at 12:48 UTC
c5a259897be41105c8d503668dbe0fe0729d8f96
5 files changed
+123
-6
README.md
+15
-3
@@ -1,11 +1,22 @@
1
# HFS: HTTP File Server
2
3
-This project is currently at a very early stage, only basic features are available.
4
-
3
HFS is a file server offering a virtual file system (vfs).
4
You can easily share a single file instead of the whole folder,
5
or you can rename it, but without touching the real file, just virtually.
6
7
+This project is in an early stage and distribution will be made easier.
8
+
9
+This is a full rewrite of [the Delphi version](https://github.com/rejetto/hfs2).
10
+You won't find all previous features here (yet), but still we got:
11
+
12
+# Features
13
+- unicode
14
+- virtual file system
15
+- mobile friendly front-end
16
+- search
17
+- accounts
18
+- resumable downloads
19
+
20
# Configuration
21
22
At the moment there's no administration UI. You must edit configuration files.
@@ -45,10 +56,11 @@ accounts:
56
password: guest
57
```
58
48
-As soon as possible HFS will encrypt passwords in a non-reversible way.
59
+As soon as the file is read HFS will encrypt passwords in a non-reversible way.
60
61
# Building instructions
62
63
+0. Install [Node.js](https://nodejs.org/) 16+
64
1. Launch `npm run build` in the root
65
2. Launch `npm run build` inside `frontend` folder
66
package-lock.json
+93
@@ -14,6 +14,7 @@
14
"koa": "^2.13.4",
15
"koa-better-http-proxy": "^0.2.9",
16
"koa-bodyparser": "^4.3.0",
17
+ "koa-compress": "^5.1.0",
18
"koa-mount": "^4.0.0",
19
"koa-static": "^5.0.0",
20
"lodash": "^4.17.21",
@@ -26,6 +27,7 @@
27
"@types/koa": "^2.13.4",
28
"@types/koa__router": "^8.0.11",
29
"@types/koa-bodyparser": "^4.3.4",
30
+ "@types/koa-compress": "^4.0.3",
31
"@types/koa-mount": "^4.0.1",
32
"@types/koa-static": "^4.0.2",
33
"@types/lodash": "^4.14.178",
@@ -300,6 +302,16 @@
302
"@types/koa": "*"
303
}
304
},
305
+ "node_modules/@types/koa-compress": {
306
+ "version": "4.0.3",
307
+ "resolved": "https://registry.npmjs.org/@types/koa-compress/-/koa-compress-4.0.3.tgz",
308
+ "integrity": "sha512-nJSII/tOSvYCwk3yDEBJLHd8ctkt5CQFZ0j8ZBnHZ2x0hg24z9H1i38lWXA/5z0Ix0uitMW1jov+kVbQI1aNPQ==",
309
+ "dev": true,
310
+ "dependencies": {
311
+ "@types/koa": "*",
312
+ "@types/node": "*"
313
+ }
314
+ },
315
"node_modules/@types/koa-mount": {
316
"version": "4.0.1",
317
"resolved": "https://registry.npmjs.org/@types/koa-mount/-/koa-mount-4.0.1.tgz",
@@ -807,6 +819,17 @@
819
"node": ">=0.1.90"
820
}
821
},
822
+ "node_modules/compressible": {
823
+ "version": "2.0.18",
824
+ "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
825
+ "integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
826
+ "dependencies": {
827
+ "mime-db": ">= 1.43.0 < 2"
828
+ },
829
+ "engines": {
830
+ "node": ">= 0.6"
831
+ }
832
+ },
833
"node_modules/concat-map": {
834
"version": "0.0.1",
835
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -1675,6 +1698,29 @@
1698
"resolved": "https://registry.npmjs.org/koa-compose/-/koa-compose-4.1.0.tgz",
1699
"integrity": "sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw=="
1700
},
1701
+ "node_modules/koa-compress": {
1702
+ "version": "5.1.0",
1703
+ "resolved": "https://registry.npmjs.org/koa-compress/-/koa-compress-5.1.0.tgz",
1704
+ "integrity": "sha512-G3Ppo9jrUwlchp6qdoRgQNMiGZtM0TAHkxRZQ7EoVvIG8E47J4nAsMJxXHAUQ+0oc7t0MDxSdONWTFcbzX7/Bg==",
1705
+ "dependencies": {
1706
+ "bytes": "^3.0.0",
1707
+ "compressible": "^2.0.0",
1708
+ "http-errors": "^1.8.0",
1709
+ "koa-is-json": "^1.0.0",
1710
+ "statuses": "^2.0.1"
1711
+ },
1712
+ "engines": {
1713
+ "node": ">= 8.0.0"
1714
+ }
1715
+ },
1716
+ "node_modules/koa-compress/node_modules/statuses": {
1717
+ "version": "2.0.1",
1718
+ "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
1719
+ "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
1720
+ "engines": {
1721
+ "node": ">= 0.8"
1722
+ }
1723
+ },
1724
"node_modules/koa-convert": {
1725
"version": "2.0.0",
1726
"resolved": "https://registry.npmjs.org/koa-convert/-/koa-convert-2.0.0.tgz",
@@ -1687,6 +1733,11 @@
1733
"node": ">= 10"
1734
}
1735
},
1736
+ "node_modules/koa-is-json": {
1737
+ "version": "1.0.0",
1738
+ "resolved": "https://registry.npmjs.org/koa-is-json/-/koa-is-json-1.0.0.tgz",
1739
+ "integrity": "sha1-JzwH7c3Ljfaiwat9We52SRRR7BQ="
1740
+ },
1741
"node_modules/koa-mount": {
1742
"version": "4.0.0",
1743
"resolved": "https://registry.npmjs.org/koa-mount/-/koa-mount-4.0.0.tgz",
@@ -3363,6 +3414,16 @@
3414
"@types/koa": "*"
3415
}
3416
},
3417
+ "@types/koa-compress": {
3418
+ "version": "4.0.3",
3419
+ "resolved": "https://registry.npmjs.org/@types/koa-compress/-/koa-compress-4.0.3.tgz",
3420
+ "integrity": "sha512-nJSII/tOSvYCwk3yDEBJLHd8ctkt5CQFZ0j8ZBnHZ2x0hg24z9H1i38lWXA/5z0Ix0uitMW1jov+kVbQI1aNPQ==",
3421
+ "dev": true,
3422
+ "requires": {
3423
+ "@types/koa": "*",
3424
+ "@types/node": "*"
3425
+ }
3426
+ },
3427
"@types/koa-mount": {
3428
"version": "4.0.1",
3429
"resolved": "https://registry.npmjs.org/@types/koa-mount/-/koa-mount-4.0.1.tgz",
@@ -3775,6 +3836,14 @@
3836
"resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
3837
"integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs="
3838
},
3839
+ "compressible": {
3840
+ "version": "2.0.18",
3841
+ "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
3842
+ "integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
3843
+ "requires": {
3844
+ "mime-db": ">= 1.43.0 < 2"
3845
+ }
3846
+ },
3847
"concat-map": {
3848
"version": "0.0.1",
3849
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -4418,6 +4487,25 @@
4487
"resolved": "https://registry.npmjs.org/koa-compose/-/koa-compose-4.1.0.tgz",
4488
"integrity": "sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw=="
4489
},
4490
+ "koa-compress": {
4491
+ "version": "5.1.0",
4492
+ "resolved": "https://registry.npmjs.org/koa-compress/-/koa-compress-5.1.0.tgz",
4493
+ "integrity": "sha512-G3Ppo9jrUwlchp6qdoRgQNMiGZtM0TAHkxRZQ7EoVvIG8E47J4nAsMJxXHAUQ+0oc7t0MDxSdONWTFcbzX7/Bg==",
4494
+ "requires": {
4495
+ "bytes": "^3.0.0",
4496
+ "compressible": "^2.0.0",
4497
+ "http-errors": "^1.8.0",
4498
+ "koa-is-json": "^1.0.0",
4499
+ "statuses": "^2.0.1"
4500
+ },
4501
+ "dependencies": {
4502
+ "statuses": {
4503
+ "version": "2.0.1",
4504
+ "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
4505
+ "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ=="
4506
+ }
4507
+ }
4508
+ },
4509
"koa-convert": {
4510
"version": "2.0.0",
4511
"resolved": "https://registry.npmjs.org/koa-convert/-/koa-convert-2.0.0.tgz",
@@ -4427,6 +4515,11 @@
4515
"koa-compose": "^4.1.0"
4516
}
4517
},
4518
+ "koa-is-json": {
4519
+ "version": "1.0.0",
4520
+ "resolved": "https://registry.npmjs.org/koa-is-json/-/koa-is-json-1.0.0.tgz",
4521
+ "integrity": "sha1-JzwH7c3Ljfaiwat9We52SRRR7BQ="
4522
+ },
4523
"koa-mount": {
4524
"version": "4.0.0",
4525
"resolved": "https://registry.npmjs.org/koa-mount/-/koa-mount-4.0.0.tgz",
package.json
+2
@@ -21,6 +21,7 @@
21
"koa": "^2.13.4",
22
"koa-better-http-proxy": "^0.2.9",
23
"koa-bodyparser": "^4.3.0",
24
+ "koa-compress": "^5.1.0",
25
"koa-mount": "^4.0.0",
26
"koa-static": "^5.0.0",
27
"lodash": "^4.17.21",
@@ -33,6 +34,7 @@
34
"@types/koa": "^2.13.4",
35
"@types/koa__router": "^8.0.11",
36
"@types/koa-bodyparser": "^4.3.4",
37
+ "@types/koa-compress": "^4.0.3",
38
"@types/koa-mount": "^4.0.1",
39
"@types/koa-static": "^4.0.2",
40
"@types/lodash": "^4.14.178",
src/index.ts
+11
-1
@@ -8,6 +8,7 @@ import { serveFile } from './serveFile'
8
import { vfs } from './vfs'
9
import { isDirectory } from './misc'
10
import proxy from 'koa-better-http-proxy'
11
+import compress from 'koa-compress'
12
13
const PORT = argv.port || 80
14
@@ -19,7 +20,16 @@ srv.use(async (ctx, next) => {
20
})
21
22
// serve apis
22
-srv.use(mount(API_URI, new Koa().use(bodyParser()).use(apiMw(frontEndApis))))
23
+srv.use(mount(API_URI, new Koa()
24
+ .use(bodyParser())
25
+ .use(apiMw(frontEndApis))
26
+ .use(compress({
27
+ threshold: 2048,
28
+ gzip: { flush: require('zlib').constants.Z_SYNC_FLUSH },
29
+ deflate: { flush: require('zlib').constants.Z_SYNC_FLUSH },
30
+ br: false // disable brotli
31
+ }))
32
+))
33
34
// serve shared files and front-end files
35
const serveFrontendPrefixed = mount(FRONTEND_URI.slice(0,-1), serveFrontend)
todo.md
+2
-2
@@ -2,12 +2,12 @@
2
- search: try to use server-sent events for the reply
3
https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
4
- node.link
5
-- api: gzip for >5kb
6
-- frontend: dialogs
5
- vfs: serve an html for a folder?
6
- "default" property for vfsNode?
7
- interruption of long requests if client aborted (searching/listing)
8
+- log file
9
- throttle speed
10
+- frontend: dialogs
11
- frontend
12
- don't depend on cdn
13
- webdav?