feat: add pin and unpin api
This commit is contained in:
parent
fb8a1b3c7d
commit
645df0c8d0
|
@ -18,12 +18,12 @@ import { CustomClientOptions, optionsToConfig } from "./utils/options.js";
|
||||||
import {throwValidationError} from "./utils/validation.js";
|
import {throwValidationError} from "./utils/validation.js";
|
||||||
import {
|
import {
|
||||||
AccountPinsResponse,
|
AccountPinsResponse,
|
||||||
BasicUploadResponse,
|
BasicUploadResponse, deleteS5DeleteCid,
|
||||||
getS5AccountPins,
|
getS5AccountPins,
|
||||||
getS5BlobCid,
|
getS5BlobCid,
|
||||||
getS5DownloadCid,
|
getS5DownloadCid,
|
||||||
getS5MetadataCid,
|
getS5MetadataCid,
|
||||||
getS5Registry,
|
getS5Registry, postS5PinCid,
|
||||||
postS5Registry,
|
postS5Registry,
|
||||||
postS5Upload,
|
postS5Upload,
|
||||||
postS5UploadDirectory,
|
postS5UploadDirectory,
|
||||||
|
@ -69,6 +69,7 @@ import defer from "p-defer";
|
||||||
import {Multihash} from "@lumeweb/libs5/lib/multihash.js";
|
import {Multihash} from "@lumeweb/libs5/lib/multihash.js";
|
||||||
import {blake3} from "@noble/hashes/blake3";
|
import {blake3} from "@noble/hashes/blake3";
|
||||||
import {base64urlDecode, base64urlEncode} from "./utils/encoding.js";
|
import {base64urlDecode, base64urlEncode} from "./utils/encoding.js";
|
||||||
|
import {CustomPinOptions, DEFAULT_PIN_OPTIONS} from "#options/pin.js";
|
||||||
|
|
||||||
export class S5Error extends Error {
|
export class S5Error extends Error {
|
||||||
public statusCode: number;
|
public statusCode: number;
|
||||||
|
@ -727,4 +728,24 @@ export class S5Client {
|
||||||
|
|
||||||
return p.promise;
|
return p.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async pin(cid: string, customOptions: CustomPinOptions = {}) {
|
||||||
|
const config = optionsToConfig(
|
||||||
|
this,
|
||||||
|
DEFAULT_PIN_OPTIONS,
|
||||||
|
customOptions,
|
||||||
|
);
|
||||||
|
|
||||||
|
await postS5PinCid(cid, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async unpin(cid: string, customOptions: CustomPinOptions = {}) {
|
||||||
|
const config = optionsToConfig(
|
||||||
|
this,
|
||||||
|
DEFAULT_PIN_OPTIONS,
|
||||||
|
customOptions,
|
||||||
|
);
|
||||||
|
|
||||||
|
await deleteS5DeleteCid(cid, config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
import {CustomClientOptions} from "#utils/options.js";
|
||||||
|
import {ResponseType} from "axios";
|
||||||
|
|
||||||
|
export type CustomPinOptions = CustomClientOptions & {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DEFAULT_PIN_OPTIONS = {};
|
Loading…
Reference in New Issue