@remix-run/node 1.7.6 → 1.8.0-pre.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.
- package/CHANGELOG.md +17 -0
- package/dist/base64.js +1 -1
- package/dist/crypto.js +1 -1
- package/dist/fetch.js +1 -7
- package/dist/globals.js +1 -1
- package/dist/implementations.js +1 -1
- package/dist/index.js +1 -1
- package/dist/magicExports/esm/remix.js +33 -2
- package/dist/magicExports/remix.d.ts +33 -3
- package/dist/magicExports/remix.js +39 -33
- package/dist/sessions/fileStorage.js +5 -15
- package/dist/stream.js +3 -26
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/upload/fileUploadHandler.js +1 -32
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/node v1.
|
|
2
|
+
* @remix-run/node v1.8.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -49,18 +49,14 @@ let defaultFilePathResolver = ({
|
|
|
49
49
|
let ext = filename ? path.extname(filename) : "";
|
|
50
50
|
return "upload_" + crypto.randomBytes(4).readUInt32LE(0) + ext;
|
|
51
51
|
};
|
|
52
|
-
|
|
53
52
|
async function uniqueFile(filepath) {
|
|
54
53
|
let ext = path.extname(filepath);
|
|
55
54
|
let uniqueFilepath = filepath;
|
|
56
|
-
|
|
57
55
|
for (let i = 1; await promises.stat(uniqueFilepath).then(() => true).catch(() => false); i++) {
|
|
58
56
|
uniqueFilepath = (ext ? filepath.slice(0, -ext.length) : filepath) + `-${new Date().getTime()}${ext}`;
|
|
59
57
|
}
|
|
60
|
-
|
|
61
58
|
return uniqueFilepath;
|
|
62
59
|
}
|
|
63
|
-
|
|
64
60
|
function createFileUploadHandler({
|
|
65
61
|
directory = os.tmpdir(),
|
|
66
62
|
avoidFileConflicts = true,
|
|
@@ -81,89 +77,71 @@ function createFileUploadHandler({
|
|
|
81
77
|
}))) {
|
|
82
78
|
return undefined;
|
|
83
79
|
}
|
|
84
|
-
|
|
85
80
|
let dir = typeof directory === "string" ? directory : directory({
|
|
86
81
|
name,
|
|
87
82
|
filename,
|
|
88
83
|
contentType
|
|
89
84
|
});
|
|
90
|
-
|
|
91
85
|
if (!dir) {
|
|
92
86
|
return undefined;
|
|
93
87
|
}
|
|
94
|
-
|
|
95
88
|
let filedir = path.resolve(dir);
|
|
96
89
|
let path$1 = typeof file === "string" ? file : file({
|
|
97
90
|
name,
|
|
98
91
|
filename,
|
|
99
92
|
contentType
|
|
100
93
|
});
|
|
101
|
-
|
|
102
94
|
if (!path$1) {
|
|
103
95
|
return undefined;
|
|
104
96
|
}
|
|
105
|
-
|
|
106
97
|
let filepath = path.resolve(filedir, path$1);
|
|
107
|
-
|
|
108
98
|
if (avoidFileConflicts) {
|
|
109
99
|
filepath = await uniqueFile(filepath);
|
|
110
100
|
}
|
|
111
|
-
|
|
112
101
|
await promises.mkdir(path.dirname(filepath), {
|
|
113
102
|
recursive: true
|
|
114
103
|
}).catch(() => {});
|
|
115
104
|
let writeFileStream = fs.createWriteStream(filepath);
|
|
116
105
|
let size = 0;
|
|
117
106
|
let deleteFile = false;
|
|
118
|
-
|
|
119
107
|
try {
|
|
120
108
|
for await (let chunk of data) {
|
|
121
109
|
size += chunk.byteLength;
|
|
122
|
-
|
|
123
110
|
if (size > maxPartSize) {
|
|
124
111
|
deleteFile = true;
|
|
125
112
|
throw new serverRuntime.MaxPartSizeExceededError(name, maxPartSize);
|
|
126
113
|
}
|
|
127
|
-
|
|
128
114
|
writeFileStream.write(chunk);
|
|
129
115
|
}
|
|
130
116
|
} finally {
|
|
131
117
|
writeFileStream.end();
|
|
132
118
|
await util.promisify(stream.finished)(writeFileStream);
|
|
133
|
-
|
|
134
119
|
if (deleteFile) {
|
|
135
120
|
await promises.rm(filepath).catch(() => {});
|
|
136
121
|
}
|
|
137
122
|
}
|
|
138
|
-
|
|
139
123
|
return new NodeOnDiskFile(filepath, contentType);
|
|
140
124
|
};
|
|
141
125
|
}
|
|
142
126
|
class NodeOnDiskFile {
|
|
143
127
|
lastModified = 0;
|
|
144
128
|
webkitRelativePath = "";
|
|
145
|
-
|
|
146
129
|
constructor(filepath, type, slicer) {
|
|
147
130
|
this.filepath = filepath;
|
|
148
131
|
this.type = type;
|
|
149
132
|
this.slicer = slicer;
|
|
150
133
|
this.name = path.basename(filepath);
|
|
151
134
|
}
|
|
152
|
-
|
|
153
135
|
get size() {
|
|
154
136
|
let stats = fs.statSync(this.filepath);
|
|
155
|
-
|
|
156
137
|
if (this.slicer) {
|
|
157
138
|
let slice = this.slicer.end - this.slicer.start;
|
|
158
139
|
return slice < 0 ? 0 : slice > stats.size ? stats.size : slice;
|
|
159
140
|
}
|
|
160
|
-
|
|
161
141
|
return stats.size;
|
|
162
142
|
}
|
|
163
|
-
|
|
164
143
|
slice(start, end, type) {
|
|
165
144
|
var _this$slicer;
|
|
166
|
-
|
|
167
145
|
if (typeof start === "number" && start < 0) start = this.size + start;
|
|
168
146
|
if (typeof end === "number" && end < 0) end = this.size + end;
|
|
169
147
|
let startOffset = ((_this$slicer = this.slicer) === null || _this$slicer === void 0 ? void 0 : _this$slicer.start) || 0;
|
|
@@ -174,14 +152,11 @@ class NodeOnDiskFile {
|
|
|
174
152
|
end
|
|
175
153
|
});
|
|
176
154
|
}
|
|
177
|
-
|
|
178
155
|
async arrayBuffer() {
|
|
179
156
|
let stream = fs.createReadStream(this.filepath);
|
|
180
|
-
|
|
181
157
|
if (this.slicer) {
|
|
182
158
|
stream = stream.pipe(streamSlice__namespace.slice(this.slicer.start, this.slicer.end));
|
|
183
159
|
}
|
|
184
|
-
|
|
185
160
|
return new Promise((resolve, reject) => {
|
|
186
161
|
let buf = [];
|
|
187
162
|
stream.on("data", chunk => buf.push(chunk));
|
|
@@ -189,25 +164,19 @@ class NodeOnDiskFile {
|
|
|
189
164
|
stream.on("error", err => reject(err));
|
|
190
165
|
});
|
|
191
166
|
}
|
|
192
|
-
|
|
193
167
|
stream() {
|
|
194
168
|
let stream = fs.createReadStream(this.filepath);
|
|
195
|
-
|
|
196
169
|
if (this.slicer) {
|
|
197
170
|
stream = stream.pipe(streamSlice__namespace.slice(this.slicer.start, this.slicer.end));
|
|
198
171
|
}
|
|
199
|
-
|
|
200
172
|
return stream$1.createReadableStreamFromReadable(stream);
|
|
201
173
|
}
|
|
202
|
-
|
|
203
174
|
async text() {
|
|
204
175
|
return stream$1.readableStreamToString(this.stream());
|
|
205
176
|
}
|
|
206
|
-
|
|
207
177
|
get [Symbol.toStringTag]() {
|
|
208
178
|
return "File";
|
|
209
179
|
}
|
|
210
|
-
|
|
211
180
|
}
|
|
212
181
|
|
|
213
182
|
exports.NodeOnDiskFile = NodeOnDiskFile;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix-run/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0-pre.0",
|
|
4
4
|
"description": "Node.js platform abstractions for Remix",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/remix-run/remix/issues"
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"typings": "dist/index.d.ts",
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@remix-run/server-runtime": "1.
|
|
19
|
-
"@remix-run/web-fetch": "^4.3.
|
|
18
|
+
"@remix-run/server-runtime": "1.8.0-pre.0",
|
|
19
|
+
"@remix-run/web-fetch": "^4.3.2",
|
|
20
20
|
"@remix-run/web-file": "^3.0.2",
|
|
21
21
|
"@remix-run/web-stream": "^1.0.3",
|
|
22
22
|
"@web3-storage/multipart-parser": "^1.0.0",
|