@open-webapp/drive-sync 0.7.0 → 0.7.1
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/files.js +11 -5
- package/dist/testing/driveFake.js +3 -1
- package/package.json +1 -1
package/dist/files.js
CHANGED
|
@@ -221,13 +221,19 @@ export async function write(opts) {
|
|
|
221
221
|
// and inserts a correct multipart boundary (never hand-rolled by us) and
|
|
222
222
|
// exposes the resulting `Content-Type: multipart/form-data; boundary=...`
|
|
223
223
|
// header, which we then forward explicitly alongside the serialized body.
|
|
224
|
-
// This also makes the request body a
|
|
225
|
-
// driveFetch, so environments (e.g. test fakes) that read the body
|
|
226
|
-
//
|
|
227
|
-
//
|
|
224
|
+
// This also makes the request body a concrete buffer by the time it reaches
|
|
225
|
+
// driveFetch, so environments (e.g. test fakes) that read the body without
|
|
226
|
+
// re-driving a real network stack see the fully encoded multipart payload
|
|
227
|
+
// rather than an opaque FormData object.
|
|
228
|
+
//
|
|
229
|
+
// The body is forwarded as an ArrayBuffer, never a string: a multipart body
|
|
230
|
+
// that carries a binary media part (a pasted PNG/JPEG) is not valid UTF-8,
|
|
231
|
+
// so `serialized.text()` would replace every non-UTF-8 byte with U+FFFD and
|
|
232
|
+
// fetch would then re-encode that lossy string, storing a corrupted blob on
|
|
233
|
+
// Drive. `arrayBuffer()` preserves the bytes exactly.
|
|
228
234
|
const serialized = new Request('https://example.invalid/', { method: 'POST', body: form });
|
|
229
235
|
const multipartContentType = serialized.headers.get('content-type') ?? undefined;
|
|
230
|
-
const multipartBody = await serialized.
|
|
236
|
+
const multipartBody = await serialized.arrayBuffer();
|
|
231
237
|
const res = await driveFetch({
|
|
232
238
|
appId: opts.appId,
|
|
233
239
|
projectId: opts.projectId,
|
|
@@ -105,7 +105,9 @@ async function readBodyText(init) {
|
|
|
105
105
|
return '';
|
|
106
106
|
if (typeof body === 'string')
|
|
107
107
|
return body;
|
|
108
|
-
if (body instanceof
|
|
108
|
+
if (body instanceof ArrayBuffer)
|
|
109
|
+
return new TextDecoder().decode(body);
|
|
110
|
+
if (ArrayBuffer.isView(body))
|
|
109
111
|
return new TextDecoder().decode(body);
|
|
110
112
|
if (typeof body.text === 'function')
|
|
111
113
|
return await body.text();
|