MCPcopy
hub / github.com/remotely-save/remotely-save / _putUint8ArrayByRange

Method _putUint8ArrayByRange

src/fsOnedrive.ts:730–774  ·  view source on GitHub ↗

* A specialized function to upload large files by parts * @param pathFragOrig * @param payload * @param rangeMin * @param rangeEnd the end, exclusive * @param size

(
    pathFragOrig: string,
    payload: Uint8Array,
    rangeStart: number,
    rangeEnd: number,
    size: number
  )

Source from the content-addressed store, hash-verified

728 * @param size
729 */
730 async _putUint8ArrayByRange(
731 pathFragOrig: string,
732 payload: Uint8Array,
733 rangeStart: number,
734 rangeEnd: number,
735 size: number
736 ) {
737 const theUrl = this._buildUrl(pathFragOrig);
738 console.debug(
739 `putUint8ArrayByRange, theUrl=${theUrl}, range=${rangeStart}-${
740 rangeEnd - 1
741 }, len=${rangeEnd - rangeStart}, size=${size}`
742 );
743 // NO AUTH HEADER here!
744 // TODO:
745 // 20220401: On Android, requestUrl has issue that text becomes base64.
746 // Use fetch everywhere instead!
747 // biome-ignore lint/correctness/noConstantCondition: hard code
748 if (false /*VALID_REQURL*/) {
749 const res = await requestUrl({
750 url: theUrl,
751 method: "PUT",
752 body: bufferToArrayBuffer(payload.subarray(rangeStart, rangeEnd)),
753 contentType: DEFAULT_CONTENT_TYPE,
754 headers: {
755 // no "Content-Length" allowed here
756 "Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`,
757 /* "Cache-Control": "no-cache", not allowed here!!! */
758 },
759 });
760 return res.json as DriveItem | UploadSession;
761 } else {
762 const res = await fetch(theUrl, {
763 method: "PUT",
764 body: payload.subarray(rangeStart, rangeEnd),
765 headers: {
766 "Content-Length": `${rangeEnd - rangeStart}`,
767 "Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`,
768 "Content-Type": DEFAULT_CONTENT_TYPE,
769 /* "Cache-Control": "no-cache", not allowed here!!! */
770 },
771 });
772 return (await res.json()) as DriveItem | UploadSession;
773 }
774 }
775
776 /**
777 * Use delta api to list all files and folders

Callers 1

_writeFileFromRootMethod · 0.95

Calls 2

_buildUrlMethod · 0.95
bufferToArrayBufferFunction · 0.90

Tested by

no test coverage detected