koa-files 3.1.8 → 3.1.10
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.
- package/cjs/Service.cjs +7 -3
- package/cjs/index.cjs +1 -1
- package/cjs/utils/fs.cjs +1 -1
- package/cjs/utils/hash.cjs +2 -2
- package/cjs/utils/http.cjs +3 -3
- package/cjs/utils/path.cjs +1 -1
- package/cjs/utils/stream.cjs +1 -1
- package/esm/Service.js +7 -3
- package/esm/index.js +1 -1
- package/esm/utils/fs.js +1 -1
- package/esm/utils/hash.js +2 -2
- package/esm/utils/http.js +3 -3
- package/esm/utils/path.js +1 -1
- package/esm/utils/stream.js +1 -1
- package/package.json +1 -1
- package/types/Service.d.ts +2 -2
- package/types/utils/hash.d.ts +1 -1
- package/types/utils/stream.d.ts +3 -3
package/cjs/Service.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.1.
|
|
4
|
+
* @version 3.1.10
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -136,8 +136,12 @@ class Service {
|
|
|
136
136
|
if (this.isIgnore(path$2)) {
|
|
137
137
|
return false;
|
|
138
138
|
}
|
|
139
|
+
// Get options.
|
|
140
|
+
const { options } = this;
|
|
141
|
+
// Get file system.
|
|
142
|
+
const { fs } = options;
|
|
139
143
|
// File stats.
|
|
140
|
-
const stats = await fs$1.stat(
|
|
144
|
+
const stats = await fs$1.stat(fs, path$2);
|
|
141
145
|
// Check file stats.
|
|
142
146
|
if (
|
|
143
147
|
// File not exist (404 | 500).
|
|
@@ -190,7 +194,7 @@ class Service {
|
|
|
190
194
|
return context.throw(400);
|
|
191
195
|
}
|
|
192
196
|
// Get stream options.
|
|
193
|
-
const {
|
|
197
|
+
const { highWaterMark } = options;
|
|
194
198
|
// Set response body.
|
|
195
199
|
context.body = new stream.FileReadStream(path$2, ranges, { fs, highWaterMark });
|
|
196
200
|
// File found.
|
package/cjs/index.cjs
CHANGED
package/cjs/utils/fs.cjs
CHANGED
package/cjs/utils/hash.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.1.
|
|
4
|
+
* @version 3.1.10
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -32,7 +32,7 @@ const CHARS = [
|
|
|
32
32
|
* @description Generate a hash.
|
|
33
33
|
* @param length The length of hash.
|
|
34
34
|
*/
|
|
35
|
-
function generate(length
|
|
35
|
+
function generate(length) {
|
|
36
36
|
let hash = '';
|
|
37
37
|
const randomValues = crypto.getRandomValues(new Uint8Array(length));
|
|
38
38
|
// Create hash.
|
package/cjs/utils/http.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.1.
|
|
4
|
+
* @version 3.1.10
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -156,13 +156,13 @@ function parseRanges(context, stats) {
|
|
|
156
156
|
// Parsed entries.
|
|
157
157
|
const entries = parsed.entries();
|
|
158
158
|
// Range boundary.
|
|
159
|
-
const boundary =
|
|
159
|
+
const boundary = `${hash.generate(32)}`;
|
|
160
160
|
// Multipart Content-Type.
|
|
161
161
|
const contentType = `Content-Type: ${context.type}`;
|
|
162
162
|
// Range suffix.
|
|
163
163
|
const suffix = buffer.Buffer.from(`\r\n--${boundary}--\r\n`);
|
|
164
164
|
// Override Content-Type.
|
|
165
|
-
context.type = `multipart/byteranges; boundary
|
|
165
|
+
context.type = `multipart/byteranges; boundary="${boundary}"`;
|
|
166
166
|
// Map ranges.
|
|
167
167
|
for (const [index, { start, end }] of entries) {
|
|
168
168
|
const length = end - start + 1;
|
package/cjs/utils/path.cjs
CHANGED
package/cjs/utils/stream.cjs
CHANGED
package/esm/Service.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.1.
|
|
4
|
+
* @version 3.1.10
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -127,8 +127,12 @@ class Service {
|
|
|
127
127
|
if (this.isIgnore(path)) {
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
|
+
// Get options.
|
|
131
|
+
const { options } = this;
|
|
132
|
+
// Get file system.
|
|
133
|
+
const { fs } = options;
|
|
130
134
|
// File stats.
|
|
131
|
-
const stats = await stat(
|
|
135
|
+
const stats = await stat(fs, path);
|
|
132
136
|
// Check file stats.
|
|
133
137
|
if (
|
|
134
138
|
// File not exist (404 | 500).
|
|
@@ -181,7 +185,7 @@ class Service {
|
|
|
181
185
|
return context.throw(400);
|
|
182
186
|
}
|
|
183
187
|
// Get stream options.
|
|
184
|
-
const {
|
|
188
|
+
const { highWaterMark } = options;
|
|
185
189
|
// Set response body.
|
|
186
190
|
context.body = new FileReadStream(path, ranges, { fs, highWaterMark });
|
|
187
191
|
// File found.
|
package/esm/index.js
CHANGED
package/esm/utils/fs.js
CHANGED
package/esm/utils/hash.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.1.
|
|
4
|
+
* @version 3.1.10
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -30,7 +30,7 @@ const CHARS = [
|
|
|
30
30
|
* @description Generate a hash.
|
|
31
31
|
* @param length The length of hash.
|
|
32
32
|
*/
|
|
33
|
-
function generate(length
|
|
33
|
+
function generate(length) {
|
|
34
34
|
let hash = '';
|
|
35
35
|
const randomValues = getRandomValues(new Uint8Array(length));
|
|
36
36
|
// Create hash.
|
package/esm/utils/http.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.1.
|
|
4
|
+
* @version 3.1.10
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -148,13 +148,13 @@ function parseRanges(context, stats) {
|
|
|
148
148
|
// Parsed entries.
|
|
149
149
|
const entries = parsed.entries();
|
|
150
150
|
// Range boundary.
|
|
151
|
-
const boundary =
|
|
151
|
+
const boundary = `${generate(32)}`;
|
|
152
152
|
// Multipart Content-Type.
|
|
153
153
|
const contentType = `Content-Type: ${context.type}`;
|
|
154
154
|
// Range suffix.
|
|
155
155
|
const suffix = Buffer.from(`\r\n--${boundary}--\r\n`);
|
|
156
156
|
// Override Content-Type.
|
|
157
|
-
context.type = `multipart/byteranges; boundary
|
|
157
|
+
context.type = `multipart/byteranges; boundary="${boundary}"`;
|
|
158
158
|
// Map ranges.
|
|
159
159
|
for (const [index, { start, end }] of entries) {
|
|
160
160
|
const length = end - start + 1;
|
package/esm/utils/path.js
CHANGED
package/esm/utils/stream.js
CHANGED
package/package.json
CHANGED
package/types/Service.d.ts
CHANGED
package/types/utils/hash.d.ts
CHANGED
package/types/utils/stream.d.ts
CHANGED
|
@@ -18,9 +18,9 @@ interface Callback {
|
|
|
18
18
|
(error?: Error | null): void;
|
|
19
19
|
}
|
|
20
20
|
export declare class FileReadStream extends Readable {
|
|
21
|
-
private fs;
|
|
22
|
-
private path;
|
|
23
|
-
private ranges;
|
|
21
|
+
private readonly fs;
|
|
22
|
+
private readonly path;
|
|
23
|
+
private readonly ranges;
|
|
24
24
|
private bytesRead;
|
|
25
25
|
private fd;
|
|
26
26
|
private reading;
|