mirror of
https://github.com/logos-storage/logos-storage-js.git
synced 2026-01-02 13:33:07 +00:00
Add fetchManifest api
This commit is contained in:
parent
9decfba74d
commit
b059830cec
16
README.md
16
README.md
@ -264,7 +264,7 @@ const space = await data.space();
|
||||
|
||||
Upload a file in a streaming manner
|
||||
|
||||
- file (File, require)
|
||||
- file (File, required)
|
||||
- onProgress (onProgress: (loaded: number, total: number) => void, optional)
|
||||
- returns [UploadResponse](./src/data/types.ts#85)
|
||||
|
||||
@ -280,6 +280,20 @@ const upload = data.upload(file, (loaded: number, total: number) => {
|
||||
await upload.result();
|
||||
```
|
||||
|
||||
#### manifest
|
||||
|
||||
Download only the dataset manifest from the network to the local node if it's not available locally.
|
||||
|
||||
- cid (string, required)
|
||||
- returns [CodexManifest](./src/data/types.ts#3)
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
const cid = "QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N";
|
||||
const manifest = await data.fetchManifest(cid);
|
||||
```
|
||||
|
||||
### Debug
|
||||
|
||||
The following API assume that you have already a node module loaded, example:
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@codex-storage/sdk-js",
|
||||
"version": "0.0.8",
|
||||
"version": "0.0.9",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@codex-storage/sdk-js",
|
||||
"version": "0.0.8",
|
||||
"version": "0.0.9",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"valibot": "^0.32.0"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@codex-storage/sdk-js",
|
||||
"version": "0.0.8",
|
||||
"version": "0.0.9",
|
||||
"description": "Codex SDK to interact with the Codex decentralized storage network.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@ -4,6 +4,7 @@ import { Fetch } from "../fetch-safe/fetch-safe";
|
||||
import type { SafeValue } from "../values/values";
|
||||
import type {
|
||||
CodexDataResponse,
|
||||
CodexManifest,
|
||||
CodexNodeSpace,
|
||||
UploadResponse,
|
||||
} from "./types";
|
||||
@ -63,7 +64,7 @@ export class CodexData {
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
const promise = new Promise<SafeValue<string>>(async (resolve) => {
|
||||
const promise = new Promise<SafeValue<string>>((resolve) => {
|
||||
xhr.upload.onprogress = (evt) => {
|
||||
if (evt.lengthComputable) {
|
||||
onProgress?.(evt.loaded, evt.total);
|
||||
@ -71,7 +72,7 @@ export class CodexData {
|
||||
};
|
||||
|
||||
xhr.open("POST", url, true);
|
||||
|
||||
// xhr.setRequestHeader("Content-Disposition", "attachment; filename=\"" + file.name + "\"")
|
||||
xhr.send(file);
|
||||
|
||||
xhr.onload = function () {
|
||||
@ -145,4 +146,16 @@ export class CodexData {
|
||||
|
||||
return res.data.body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download only the dataset manifest from the network to the local node
|
||||
* if it's not available locally.
|
||||
*/
|
||||
async fetchManifest(cid: string) {
|
||||
const url = this.url + Api.config.prefix + `/data/${cid}/network/manifest`;
|
||||
|
||||
return Fetch.safeJson<CodexManifest>(url, {
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user