Compare commits

..

3 Commits

Author SHA1 Message Date
Derrick Hammer f77af25b84
feat: add pinStatus api 2024-03-22 18:12:07 -04:00
Derrick Hammer 645df0c8d0
feat: add pin and unpin api 2024-03-22 18:11:17 -04:00
Derrick Hammer fb8a1b3c7d
core: update swagger.yaml 2024-03-22 18:02:56 -04:00
3 changed files with 707 additions and 640 deletions

View File

@ -18,12 +18,12 @@ import { CustomClientOptions, optionsToConfig } from "./utils/options.js";
import {throwValidationError} from "./utils/validation.js";
import {
AccountPinsResponse,
BasicUploadResponse,
BasicUploadResponse, deleteS5DeleteCid,
getS5AccountPins,
getS5BlobCid,
getS5DownloadCid,
getS5MetadataCid,
getS5Registry,
getS5MetadataCid, getS5PinCidStatus,
getS5Registry, postS5PinCid,
postS5Registry,
postS5Upload,
postS5UploadDirectory,
@ -69,6 +69,7 @@ import defer from "p-defer";
import {Multihash} from "@lumeweb/libs5/lib/multihash.js";
import {blake3} from "@noble/hashes/blake3";
import {base64urlDecode, base64urlEncode} from "./utils/encoding.js";
import {CustomPinOptions, DEFAULT_PIN_OPTIONS} from "#options/pin.js";
export class S5Error extends Error {
public statusCode: number;
@ -727,4 +728,34 @@ export class S5Client {
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);
}
public async pinStatus(cid: string, customOptions: CustomPinOptions = {}) {
const config = optionsToConfig(
this,
DEFAULT_PIN_OPTIONS,
customOptions,
);
return await getS5PinCidStatus(cid, config);
}
}

8
src/options/pin.ts Normal file
View File

@ -0,0 +1,8 @@
import {CustomClientOptions} from "#utils/options.js";
import {ResponseType} from "axios";
export type CustomPinOptions = CustomClientOptions & {
};
export const DEFAULT_PIN_OPTIONS = {};

View File

@ -679,6 +679,24 @@ paths:
responses:
'204':
description: File pinned
/s5/pin/{cid}/status:
get:
summary: Retrieve pin status
tags:
- pin
parameters:
- name: cid
in: path
required: true
schema:
type: string
responses:
'200':
description: Pin status
content:
application/json:
schema:
$ref: '#/components/schemas/AccountPinStatusResponse'
/s5/delete/{cid}:
delete:
summary: Delete a file. This will only unpin it from the account, and potentially delete it later if there are no more global pins.
@ -923,6 +941,16 @@ components:
type: string
mime_type:
type: string
AccountPinStatusResponse:
type: object
required:
- status
- progress
properties:
status:
type: string
progress:
type: number
RegistryQueryResponse:
type: object
properties: