mirror of
https://github.com/logos-storage/logos-storage-js.git
synced 2026-01-07 16:03:06 +00:00
Return the Response object for download
This commit is contained in:
parent
c477f793cb
commit
d219976412
@ -300,7 +300,7 @@ Download a file from the network in a streaming manner.
|
|||||||
If the file is not available locally, it will be retrieved from other nodes in the network if able.
|
If the file is not available locally, it will be retrieved from other nodes in the network if able.
|
||||||
|
|
||||||
- cid (string, required)
|
- cid (string, required)
|
||||||
- returns ReadableStream<Uint8Array> | null
|
- returns Response
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,7 @@ export class CodexData {
|
|||||||
* A callback onProgress can be passed to receive upload progress data information.
|
* A callback onProgress can be passed to receive upload progress data information.
|
||||||
*/
|
*/
|
||||||
upload(
|
upload(
|
||||||
file: File,
|
file: Document | XMLHttpRequestBodyInit,
|
||||||
onProgress?: (loaded: number, total: number) => void
|
onProgress?: (loaded: number, total: number) => void
|
||||||
): UploadResponse {
|
): UploadResponse {
|
||||||
const url = this.url + Api.config.prefix + "/data";
|
const url = this.url + Api.config.prefix + "/data";
|
||||||
@ -109,21 +109,12 @@ export class CodexData {
|
|||||||
* Download a file from the local node in a streaming manner.
|
* Download a file from the local node in a streaming manner.
|
||||||
* If the file is not available locally, a 404 is returned.
|
* If the file is not available locally, a 404 is returned.
|
||||||
*/
|
*/
|
||||||
async localDownload(cid: string): Promise<SafeValue<ReadableStream<Uint8Array> | null>> {
|
async localDownload(cid: string): Promise<SafeValue<Response>> {
|
||||||
const url = this.url + Api.config.prefix + "/data/" + cid;
|
const url = this.url + Api.config.prefix + "/data/" + cid;
|
||||||
|
|
||||||
const res = await Fetch.safe(url, {
|
return Fetch.safe(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
|
||||||
"content-type": "application/octet-stream",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.error) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { error: false, data: res.data.body };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,10 +125,7 @@ export class CodexData {
|
|||||||
const url = this.url + Api.config.prefix + `/data/${cid}/network`;
|
const url = this.url + Api.config.prefix + `/data/${cid}/network`;
|
||||||
|
|
||||||
return Fetch.safeJson(url, {
|
return Fetch.safeJson(url, {
|
||||||
method: "POST",
|
method: "POST"
|
||||||
headers: {
|
|
||||||
"content-type": "application/octet-stream",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,18 +133,12 @@ export class CodexData {
|
|||||||
* Download a file from the network in a streaming manner.
|
* Download a file from the network in a streaming manner.
|
||||||
* If the file is not available locally, it will be retrieved from other nodes in the network if able.
|
* If the file is not available locally, it will be retrieved from other nodes in the network if able.
|
||||||
*/
|
*/
|
||||||
async networkDownloadStream(cid: string): Promise<SafeValue<ReadableStream<Uint8Array> | null>> {
|
async networkDownloadStream(cid: string): Promise<SafeValue<Response>> {
|
||||||
const url = this.url + Api.config.prefix + `/data/${cid}/network/stream`;
|
const url = this.url + Api.config.prefix + `/data/${cid}/network/stream`;
|
||||||
|
|
||||||
const res = await Fetch.safe(url, {
|
return Fetch.safe(url, {
|
||||||
method: "GET"
|
method: "GET"
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.error) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { error: false, data: res.data.body };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user