@swell/cli 1.0.1-alpha → 1.0.2
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/dist/bin/{multipart-parser-97941dba.js → multipart-parser-85ef9626.js} +1 -1
- package/dist/bin/{swell-96dae89a.js → swell-0f71f07d.js} +47 -15
- package/dist/bin/swell.js +1 -1
- package/dist/man/swell.1 +1 -1
- package/package.json +1 -1
- package/dist/bin/multipart-parser-fc2dc43e.js +0 -456
- package/dist/bin/swell-cfd63c19.js +0 -30637
|
@@ -15385,7 +15385,7 @@ class Body {
|
|
|
15385
15385
|
return formData;
|
|
15386
15386
|
}
|
|
15387
15387
|
|
|
15388
|
-
const {toFormData} = await import('./multipart-parser-
|
|
15388
|
+
const {toFormData} = await import('./multipart-parser-85ef9626.js');
|
|
15389
15389
|
return toFormData(this.body, ct);
|
|
15390
15390
|
}
|
|
15391
15391
|
|
|
@@ -30257,19 +30257,26 @@ async function storefrontsPush(params, config = {}) {
|
|
|
30257
30257
|
|
|
30258
30258
|
const storefrontsToggleEditorParams = {
|
|
30259
30259
|
'--id': String,
|
|
30260
|
+
'--enable': Boolean,
|
|
30261
|
+
'--theme-id': String,
|
|
30260
30262
|
};
|
|
30261
30263
|
|
|
30262
30264
|
/**
|
|
30263
|
-
* Enable or disable the editor for a storefront
|
|
30265
|
+
* Enable or disable the editor for a storefront and set the source theme id
|
|
30266
|
+
* if not already set.
|
|
30264
30267
|
*
|
|
30265
30268
|
* @param {string} params.id - id of the storefront to push data to
|
|
30269
|
+
* @param {boolean} params.enable - whether to enable or disable the editor.
|
|
30270
|
+
* If not specified, the existing value will be negated.
|
|
30271
|
+
* @param {string} params.themeId - id of the theme to use as the source
|
|
30266
30272
|
*/
|
|
30267
30273
|
async function storefrontsToggleEditor(params, config = {}) {
|
|
30268
30274
|
const { storeId, status, api } = config;
|
|
30269
|
-
const { '--id': id } = params;
|
|
30275
|
+
const { '--id': id, '--enable': enable, '--theme-id': themeId } = params;
|
|
30270
30276
|
|
|
30271
30277
|
if (!id) {
|
|
30272
30278
|
status.fail('You need to specify a storefront id for this command');
|
|
30279
|
+
return;
|
|
30273
30280
|
}
|
|
30274
30281
|
|
|
30275
30282
|
const apiPathOpts = {
|
|
@@ -30277,22 +30284,47 @@ async function storefrontsToggleEditor(params, config = {}) {
|
|
|
30277
30284
|
backendPath: `:storefronts/${id}`,
|
|
30278
30285
|
};
|
|
30279
30286
|
|
|
30280
|
-
const
|
|
30281
|
-
|
|
30287
|
+
const valuesToUpdate = {
|
|
30288
|
+
editor: enable,
|
|
30289
|
+
};
|
|
30290
|
+
|
|
30291
|
+
const outputMessage = [
|
|
30292
|
+
`Successfully set editor values for ${chalk.magenta.bold(
|
|
30293
|
+
storeId,
|
|
30294
|
+
)} storefront ${chalk.magenta.bold(id)}.`,
|
|
30295
|
+
];
|
|
30296
|
+
|
|
30297
|
+
if (enable === undefined) {
|
|
30298
|
+
const currentData = await api.get(apiPathOpts);
|
|
30299
|
+
valuesToUpdate.editor = !Boolean(currentData['editor']);
|
|
30300
|
+
}
|
|
30301
|
+
|
|
30302
|
+
outputMessage.push(
|
|
30303
|
+
`Enabled editor: ${chalk.magenta.bold(valuesToUpdate.editor)}`,
|
|
30304
|
+
);
|
|
30305
|
+
|
|
30306
|
+
if (themeId) {
|
|
30307
|
+
valuesToUpdate.source_model = 'themes';
|
|
30308
|
+
valuesToUpdate.source_id = themeId;
|
|
30309
|
+
outputMessage.push(`Source theme id: ${chalk.magenta.bold(themeId)}`);
|
|
30310
|
+
}
|
|
30282
30311
|
|
|
30283
30312
|
status.text = `Pushing storefront ${chalk.bold(id)} data`;
|
|
30284
30313
|
|
|
30285
|
-
await api.put(apiPathOpts, {
|
|
30286
|
-
body: JSON.stringify(
|
|
30314
|
+
const response = await api.put(apiPathOpts, {
|
|
30315
|
+
body: JSON.stringify(valuesToUpdate),
|
|
30287
30316
|
});
|
|
30288
30317
|
|
|
30289
|
-
|
|
30290
|
-
|
|
30291
|
-
|
|
30292
|
-
|
|
30293
|
-
|
|
30294
|
-
)
|
|
30295
|
-
|
|
30318
|
+
if (response?.errors?.source_id?.code === 'IMMUTABLE') {
|
|
30319
|
+
status.fail(
|
|
30320
|
+
`Failed to update storefront ${chalk.magenta.bold(
|
|
30321
|
+
id,
|
|
30322
|
+
)}: theme already set`,
|
|
30323
|
+
);
|
|
30324
|
+
return;
|
|
30325
|
+
}
|
|
30326
|
+
|
|
30327
|
+
status.succeed(outputMessage.join('\n'));
|
|
30296
30328
|
}
|
|
30297
30329
|
|
|
30298
30330
|
const loginParams = {
|
|
@@ -30416,7 +30448,7 @@ const versionParams = {
|
|
|
30416
30448
|
|
|
30417
30449
|
function version(_params, config = {}) {
|
|
30418
30450
|
const { status } = config;
|
|
30419
|
-
status.succeed('1.0.
|
|
30451
|
+
status.succeed('1.0.2');
|
|
30420
30452
|
}
|
|
30421
30453
|
|
|
30422
30454
|
const API_BASE_URL = process.env.API_BASE_URL || 'https://api.swell.store';
|
package/dist/bin/swell.js
CHANGED
package/dist/man/swell.1
CHANGED
package/package.json
CHANGED
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { F as FormData, a as File } from './swell-96dae89a.js';
|
|
4
|
-
import 'node:assert';
|
|
5
|
-
import 'node:child_process';
|
|
6
|
-
import 'node:async_hooks';
|
|
7
|
-
import 'node:util';
|
|
8
|
-
import 'node:process';
|
|
9
|
-
import 'node:os';
|
|
10
|
-
import 'node:tty';
|
|
11
|
-
import 'node:fs';
|
|
12
|
-
import 'node:path';
|
|
13
|
-
import 'node:stream';
|
|
14
|
-
import 'node:string_decoder';
|
|
15
|
-
import 'node:buffer';
|
|
16
|
-
import 'node:events';
|
|
17
|
-
import 'node:url';
|
|
18
|
-
import 'node:http';
|
|
19
|
-
import 'node:https';
|
|
20
|
-
import 'node:zlib';
|
|
21
|
-
import 'node:net';
|
|
22
|
-
import 'node:readline';
|
|
23
|
-
import 'node:constants';
|
|
24
|
-
import 'node:crypto';
|
|
25
|
-
|
|
26
|
-
let s = 0;
|
|
27
|
-
const S = {
|
|
28
|
-
START_BOUNDARY: s++,
|
|
29
|
-
HEADER_FIELD_START: s++,
|
|
30
|
-
HEADER_FIELD: s++,
|
|
31
|
-
HEADER_VALUE_START: s++,
|
|
32
|
-
HEADER_VALUE: s++,
|
|
33
|
-
HEADER_VALUE_ALMOST_DONE: s++,
|
|
34
|
-
HEADERS_ALMOST_DONE: s++,
|
|
35
|
-
PART_DATA_START: s++,
|
|
36
|
-
PART_DATA: s++,
|
|
37
|
-
END: s++
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
let f = 1;
|
|
41
|
-
const F = {
|
|
42
|
-
PART_BOUNDARY: f,
|
|
43
|
-
LAST_BOUNDARY: f *= 2
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const LF = 10;
|
|
47
|
-
const CR = 13;
|
|
48
|
-
const SPACE = 32;
|
|
49
|
-
const HYPHEN = 45;
|
|
50
|
-
const COLON = 58;
|
|
51
|
-
const A = 97;
|
|
52
|
-
const Z = 122;
|
|
53
|
-
|
|
54
|
-
const lower = c => c | 0x20;
|
|
55
|
-
|
|
56
|
-
const noop = () => {};
|
|
57
|
-
|
|
58
|
-
class MultipartParser {
|
|
59
|
-
/**
|
|
60
|
-
* @param {string} boundary
|
|
61
|
-
*/
|
|
62
|
-
constructor(boundary) {
|
|
63
|
-
this.index = 0;
|
|
64
|
-
this.flags = 0;
|
|
65
|
-
|
|
66
|
-
this.onHeaderEnd = noop;
|
|
67
|
-
this.onHeaderField = noop;
|
|
68
|
-
this.onHeadersEnd = noop;
|
|
69
|
-
this.onHeaderValue = noop;
|
|
70
|
-
this.onPartBegin = noop;
|
|
71
|
-
this.onPartData = noop;
|
|
72
|
-
this.onPartEnd = noop;
|
|
73
|
-
|
|
74
|
-
this.boundaryChars = {};
|
|
75
|
-
|
|
76
|
-
boundary = '\r\n--' + boundary;
|
|
77
|
-
const ui8a = new Uint8Array(boundary.length);
|
|
78
|
-
for (let i = 0; i < boundary.length; i++) {
|
|
79
|
-
ui8a[i] = boundary.charCodeAt(i);
|
|
80
|
-
this.boundaryChars[ui8a[i]] = true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
this.boundary = ui8a;
|
|
84
|
-
this.lookbehind = new Uint8Array(this.boundary.length + 8);
|
|
85
|
-
this.state = S.START_BOUNDARY;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @param {Uint8Array} data
|
|
90
|
-
*/
|
|
91
|
-
write(data) {
|
|
92
|
-
let i = 0;
|
|
93
|
-
const length_ = data.length;
|
|
94
|
-
let previousIndex = this.index;
|
|
95
|
-
let {lookbehind, boundary, boundaryChars, index, state, flags} = this;
|
|
96
|
-
const boundaryLength = this.boundary.length;
|
|
97
|
-
const boundaryEnd = boundaryLength - 1;
|
|
98
|
-
const bufferLength = data.length;
|
|
99
|
-
let c;
|
|
100
|
-
let cl;
|
|
101
|
-
|
|
102
|
-
const mark = name => {
|
|
103
|
-
this[name + 'Mark'] = i;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const clear = name => {
|
|
107
|
-
delete this[name + 'Mark'];
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const callback = (callbackSymbol, start, end, ui8a) => {
|
|
111
|
-
if (start === undefined || start !== end) {
|
|
112
|
-
this[callbackSymbol](ui8a && ui8a.subarray(start, end));
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const dataCallback = (name, clear) => {
|
|
117
|
-
const markSymbol = name + 'Mark';
|
|
118
|
-
if (!(markSymbol in this)) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (clear) {
|
|
123
|
-
callback(name, this[markSymbol], i, data);
|
|
124
|
-
delete this[markSymbol];
|
|
125
|
-
} else {
|
|
126
|
-
callback(name, this[markSymbol], data.length, data);
|
|
127
|
-
this[markSymbol] = 0;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
for (i = 0; i < length_; i++) {
|
|
132
|
-
c = data[i];
|
|
133
|
-
|
|
134
|
-
switch (state) {
|
|
135
|
-
case S.START_BOUNDARY:
|
|
136
|
-
if (index === boundary.length - 2) {
|
|
137
|
-
if (c === HYPHEN) {
|
|
138
|
-
flags |= F.LAST_BOUNDARY;
|
|
139
|
-
} else if (c !== CR) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
index++;
|
|
144
|
-
break;
|
|
145
|
-
} else if (index - 1 === boundary.length - 2) {
|
|
146
|
-
if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
|
|
147
|
-
state = S.END;
|
|
148
|
-
flags = 0;
|
|
149
|
-
} else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
|
|
150
|
-
index = 0;
|
|
151
|
-
callback('onPartBegin');
|
|
152
|
-
state = S.HEADER_FIELD_START;
|
|
153
|
-
} else {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (c !== boundary[index + 2]) {
|
|
161
|
-
index = -2;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (c === boundary[index + 2]) {
|
|
165
|
-
index++;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
break;
|
|
169
|
-
case S.HEADER_FIELD_START:
|
|
170
|
-
state = S.HEADER_FIELD;
|
|
171
|
-
mark('onHeaderField');
|
|
172
|
-
index = 0;
|
|
173
|
-
// falls through
|
|
174
|
-
case S.HEADER_FIELD:
|
|
175
|
-
if (c === CR) {
|
|
176
|
-
clear('onHeaderField');
|
|
177
|
-
state = S.HEADERS_ALMOST_DONE;
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
index++;
|
|
182
|
-
if (c === HYPHEN) {
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (c === COLON) {
|
|
187
|
-
if (index === 1) {
|
|
188
|
-
// empty header field
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
dataCallback('onHeaderField', true);
|
|
193
|
-
state = S.HEADER_VALUE_START;
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
cl = lower(c);
|
|
198
|
-
if (cl < A || cl > Z) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
break;
|
|
203
|
-
case S.HEADER_VALUE_START:
|
|
204
|
-
if (c === SPACE) {
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
mark('onHeaderValue');
|
|
209
|
-
state = S.HEADER_VALUE;
|
|
210
|
-
// falls through
|
|
211
|
-
case S.HEADER_VALUE:
|
|
212
|
-
if (c === CR) {
|
|
213
|
-
dataCallback('onHeaderValue', true);
|
|
214
|
-
callback('onHeaderEnd');
|
|
215
|
-
state = S.HEADER_VALUE_ALMOST_DONE;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
break;
|
|
219
|
-
case S.HEADER_VALUE_ALMOST_DONE:
|
|
220
|
-
if (c !== LF) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
state = S.HEADER_FIELD_START;
|
|
225
|
-
break;
|
|
226
|
-
case S.HEADERS_ALMOST_DONE:
|
|
227
|
-
if (c !== LF) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
callback('onHeadersEnd');
|
|
232
|
-
state = S.PART_DATA_START;
|
|
233
|
-
break;
|
|
234
|
-
case S.PART_DATA_START:
|
|
235
|
-
state = S.PART_DATA;
|
|
236
|
-
mark('onPartData');
|
|
237
|
-
// falls through
|
|
238
|
-
case S.PART_DATA:
|
|
239
|
-
previousIndex = index;
|
|
240
|
-
|
|
241
|
-
if (index === 0) {
|
|
242
|
-
// boyer-moore derrived algorithm to safely skip non-boundary data
|
|
243
|
-
i += boundaryEnd;
|
|
244
|
-
while (i < bufferLength && !(data[i] in boundaryChars)) {
|
|
245
|
-
i += boundaryLength;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
i -= boundaryEnd;
|
|
249
|
-
c = data[i];
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (index < boundary.length) {
|
|
253
|
-
if (boundary[index] === c) {
|
|
254
|
-
if (index === 0) {
|
|
255
|
-
dataCallback('onPartData', true);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
index++;
|
|
259
|
-
} else {
|
|
260
|
-
index = 0;
|
|
261
|
-
}
|
|
262
|
-
} else if (index === boundary.length) {
|
|
263
|
-
index++;
|
|
264
|
-
if (c === CR) {
|
|
265
|
-
// CR = part boundary
|
|
266
|
-
flags |= F.PART_BOUNDARY;
|
|
267
|
-
} else if (c === HYPHEN) {
|
|
268
|
-
// HYPHEN = end boundary
|
|
269
|
-
flags |= F.LAST_BOUNDARY;
|
|
270
|
-
} else {
|
|
271
|
-
index = 0;
|
|
272
|
-
}
|
|
273
|
-
} else if (index - 1 === boundary.length) {
|
|
274
|
-
if (flags & F.PART_BOUNDARY) {
|
|
275
|
-
index = 0;
|
|
276
|
-
if (c === LF) {
|
|
277
|
-
// unset the PART_BOUNDARY flag
|
|
278
|
-
flags &= ~F.PART_BOUNDARY;
|
|
279
|
-
callback('onPartEnd');
|
|
280
|
-
callback('onPartBegin');
|
|
281
|
-
state = S.HEADER_FIELD_START;
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
} else if (flags & F.LAST_BOUNDARY) {
|
|
285
|
-
if (c === HYPHEN) {
|
|
286
|
-
callback('onPartEnd');
|
|
287
|
-
state = S.END;
|
|
288
|
-
flags = 0;
|
|
289
|
-
} else {
|
|
290
|
-
index = 0;
|
|
291
|
-
}
|
|
292
|
-
} else {
|
|
293
|
-
index = 0;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (index > 0) {
|
|
298
|
-
// when matching a possible boundary, keep a lookbehind reference
|
|
299
|
-
// in case it turns out to be a false lead
|
|
300
|
-
lookbehind[index - 1] = c;
|
|
301
|
-
} else if (previousIndex > 0) {
|
|
302
|
-
// if our boundary turned out to be rubbish, the captured lookbehind
|
|
303
|
-
// belongs to partData
|
|
304
|
-
const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
|
|
305
|
-
callback('onPartData', 0, previousIndex, _lookbehind);
|
|
306
|
-
previousIndex = 0;
|
|
307
|
-
mark('onPartData');
|
|
308
|
-
|
|
309
|
-
// reconsider the current character even so it interrupted the sequence
|
|
310
|
-
// it could be the beginning of a new sequence
|
|
311
|
-
i--;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
break;
|
|
315
|
-
case S.END:
|
|
316
|
-
break;
|
|
317
|
-
default:
|
|
318
|
-
throw new Error(`Unexpected state entered: ${state}`);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
dataCallback('onHeaderField');
|
|
323
|
-
dataCallback('onHeaderValue');
|
|
324
|
-
dataCallback('onPartData');
|
|
325
|
-
|
|
326
|
-
// Update properties for the next call
|
|
327
|
-
this.index = index;
|
|
328
|
-
this.state = state;
|
|
329
|
-
this.flags = flags;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
end() {
|
|
333
|
-
if ((this.state === S.HEADER_FIELD_START && this.index === 0) ||
|
|
334
|
-
(this.state === S.PART_DATA && this.index === this.boundary.length)) {
|
|
335
|
-
this.onPartEnd();
|
|
336
|
-
} else if (this.state !== S.END) {
|
|
337
|
-
throw new Error('MultipartParser.end(): stream ended unexpectedly');
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function _fileName(headerValue) {
|
|
343
|
-
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
|
|
344
|
-
const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
|
|
345
|
-
if (!m) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const match = m[2] || m[3] || '';
|
|
350
|
-
let filename = match.slice(match.lastIndexOf('\\') + 1);
|
|
351
|
-
filename = filename.replace(/%22/g, '"');
|
|
352
|
-
filename = filename.replace(/&#(\d{4});/g, (m, code) => {
|
|
353
|
-
return String.fromCharCode(code);
|
|
354
|
-
});
|
|
355
|
-
return filename;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
async function toFormData(Body, ct) {
|
|
359
|
-
if (!/multipart/i.test(ct)) {
|
|
360
|
-
throw new TypeError('Failed to fetch');
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
|
|
364
|
-
|
|
365
|
-
if (!m) {
|
|
366
|
-
throw new TypeError('no or bad content-type header, no multipart boundary');
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const parser = new MultipartParser(m[1] || m[2]);
|
|
370
|
-
|
|
371
|
-
let headerField;
|
|
372
|
-
let headerValue;
|
|
373
|
-
let entryValue;
|
|
374
|
-
let entryName;
|
|
375
|
-
let contentType;
|
|
376
|
-
let filename;
|
|
377
|
-
const entryChunks = [];
|
|
378
|
-
const formData = new FormData();
|
|
379
|
-
|
|
380
|
-
const onPartData = ui8a => {
|
|
381
|
-
entryValue += decoder.decode(ui8a, {stream: true});
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
const appendToFile = ui8a => {
|
|
385
|
-
entryChunks.push(ui8a);
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
const appendFileToFormData = () => {
|
|
389
|
-
const file = new File(entryChunks, filename, {type: contentType});
|
|
390
|
-
formData.append(entryName, file);
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
const appendEntryToFormData = () => {
|
|
394
|
-
formData.append(entryName, entryValue);
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
const decoder = new TextDecoder('utf-8');
|
|
398
|
-
decoder.decode();
|
|
399
|
-
|
|
400
|
-
parser.onPartBegin = function () {
|
|
401
|
-
parser.onPartData = onPartData;
|
|
402
|
-
parser.onPartEnd = appendEntryToFormData;
|
|
403
|
-
|
|
404
|
-
headerField = '';
|
|
405
|
-
headerValue = '';
|
|
406
|
-
entryValue = '';
|
|
407
|
-
entryName = '';
|
|
408
|
-
contentType = '';
|
|
409
|
-
filename = null;
|
|
410
|
-
entryChunks.length = 0;
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
parser.onHeaderField = function (ui8a) {
|
|
414
|
-
headerField += decoder.decode(ui8a, {stream: true});
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
parser.onHeaderValue = function (ui8a) {
|
|
418
|
-
headerValue += decoder.decode(ui8a, {stream: true});
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
parser.onHeaderEnd = function () {
|
|
422
|
-
headerValue += decoder.decode();
|
|
423
|
-
headerField = headerField.toLowerCase();
|
|
424
|
-
|
|
425
|
-
if (headerField === 'content-disposition') {
|
|
426
|
-
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
|
|
427
|
-
const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
|
|
428
|
-
|
|
429
|
-
if (m) {
|
|
430
|
-
entryName = m[2] || m[3] || '';
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
filename = _fileName(headerValue);
|
|
434
|
-
|
|
435
|
-
if (filename) {
|
|
436
|
-
parser.onPartData = appendToFile;
|
|
437
|
-
parser.onPartEnd = appendFileToFormData;
|
|
438
|
-
}
|
|
439
|
-
} else if (headerField === 'content-type') {
|
|
440
|
-
contentType = headerValue;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
headerValue = '';
|
|
444
|
-
headerField = '';
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
for await (const chunk of Body) {
|
|
448
|
-
parser.write(chunk);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
parser.end();
|
|
452
|
-
|
|
453
|
-
return formData;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
export { toFormData };
|