Compare commits

..

No commits in common. "f77af25b844abb8124aabb1048fce37be8d4e8b3" and "afb3d7fa3d758c966d3dbdab59c3c63a5c426536" have entirely different histories.

3 changed files with 646 additions and 713 deletions

View File

@ -6,7 +6,7 @@ import {
MetadataResult, MetadataResult,
} from "./options/download.js"; } from "./options/download.js";
import {addUrlQuery, ensureUrl} from "./utils/url.js"; import { addUrlQuery, ensureUrl } from "./utils/url.js";
import { import {
CustomRegistryOptions, CustomRegistryOptions,
@ -14,16 +14,16 @@ import {
DEFAULT_PUBLISH_ENTRY_OPTIONS, DEFAULT_PUBLISH_ENTRY_OPTIONS,
DEFAULT_SUBSCRIBE_ENTRY_OPTIONS, DEFAULT_SUBSCRIBE_ENTRY_OPTIONS,
} from "./options/registry.js"; } from "./options/registry.js";
import {CustomClientOptions, optionsToConfig} from "./utils/options.js"; import { CustomClientOptions, optionsToConfig } from "./utils/options.js";
import {throwValidationError} from "./utils/validation.js"; import { throwValidationError } from "./utils/validation.js";
import { import {
AccountPinsResponse, AccountPinsResponse,
BasicUploadResponse, deleteS5DeleteCid, BasicUploadResponse,
getS5AccountPins, getS5AccountPins,
getS5BlobCid, getS5BlobCid,
getS5DownloadCid, getS5DownloadCid,
getS5MetadataCid, getS5PinCidStatus, getS5MetadataCid,
getS5Registry, postS5PinCid, getS5Registry,
postS5Registry, postS5Registry,
postS5Upload, postS5Upload,
postS5UploadDirectory, postS5UploadDirectory,
@ -31,11 +31,11 @@ import {
PostS5UploadResult, PostS5UploadResult,
} from "./generated/index.js"; } from "./generated/index.js";
import path from "path"; import path from "path";
import {customInstance} from "./axios.js"; import { customInstance } from "./axios.js";
import {ensureBytes, equalBytes} from "@noble/curves/abstract/utils"; import { ensureBytes, equalBytes } from "@noble/curves/abstract/utils";
import {concatBytes} from "@noble/hashes/utils"; import { concatBytes } from "@noble/hashes/utils";
import {CID_HASH_TYPES} from "@lumeweb/libs5"; import { CID_HASH_TYPES } from "@lumeweb/libs5";
import {buildRequestUrl} from "./request.js"; import { buildRequestUrl } from "./request.js";
import WS from "isomorphic-ws"; import WS from "isomorphic-ws";
import { import {
CID, CID,
@ -50,8 +50,8 @@ import {
signRegistryEntry, signRegistryEntry,
verifyRegistryEntry, verifyRegistryEntry,
} from "@lumeweb/libs5/lib/service/registry.js"; } from "@lumeweb/libs5/lib/service/registry.js";
import {Buffer} from "buffer"; import { Buffer } from "buffer";
import {AxiosError} from "axios"; import { AxiosError } from "axios";
import { import {
CustomUploadOptions, CustomUploadOptions,
DEFAULT_UPLOAD_OPTIONS, DEFAULT_UPLOAD_OPTIONS,
@ -64,12 +64,11 @@ import {
Upload, Upload,
UploadOptions, UploadOptions,
} from "tus-js-client"; } from "tus-js-client";
import {ensureFileObjectConsistency} from "./utils/file.js"; import { ensureFileObjectConsistency } from "./utils/file.js";
import defer from "p-defer"; 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;
@ -174,7 +173,7 @@ export class S5Client {
cid: string, cid: string,
customOptions: CustomDownloadOptions = {}, customOptions: CustomDownloadOptions = {},
): Promise<string> { ): Promise<string> {
const opt = {...this.clientOptions, customOptions}; const opt = { ...this.clientOptions, customOptions };
return addUrlQuery(path.join(this.portalUrl, cid), { return addUrlQuery(path.join(this.portalUrl, cid), {
auth_token: opt.apiKey, auth_token: opt.apiKey,
}); });
@ -201,7 +200,7 @@ export class S5Client {
const response = await getS5MetadataCid(cid, config); const response = await getS5MetadataCid(cid, config);
return {metadata: response}; return { metadata: response };
} }
/** /**
@ -492,7 +491,7 @@ export class S5Client {
): Promise<UploadResult> { ): Promise<UploadResult> {
const response = await this.uploadSmallFileRequest(file, customOptions); const response = await this.uploadSmallFileRequest(file, customOptions);
return {cid: CID.decode(<string>response.cid)}; return { cid: CID.decode(<string>response.cid) };
} }
/* istanbul ignore next */ /* istanbul ignore next */
@ -589,7 +588,7 @@ export class S5Client {
customOptions, customOptions,
); );
return {cid: CID.decode(<string>response.cid)}; return { cid: CID.decode(<string>response.cid) };
} }
/** /**
@ -640,7 +639,7 @@ export class S5Client {
): Promise<UploadResult> { ): Promise<UploadResult> {
const response = await this.uploadWebappRequest(directory, customOptions); const response = await this.uploadWebappRequest(directory, customOptions);
return {cid: CID.decode(<string>response.cid)}; return { cid: CID.decode(<string>response.cid) };
} }
/** /**
@ -705,7 +704,7 @@ export class S5Client {
return; return;
} }
p.resolve({cid}); p.resolve({ cid });
}, },
onError: (error: Error | DetailedError) => { onError: (error: Error | DetailedError) => {
// Return error body rather than entire error. // Return error body rather than entire error.
@ -728,34 +727,4 @@ 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);
}
public async pinStatus(cid: string, customOptions: CustomPinOptions = {}) {
const config = optionsToConfig(
this,
DEFAULT_PIN_OPTIONS,
customOptions,
);
return await getS5PinCidStatus(cid, config);
}
} }

View File

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

View File

@ -679,24 +679,6 @@ paths:
responses: responses:
'204': '204':
description: File pinned 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}: /s5/delete/{cid}:
delete: 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. summary: Delete a file. This will only unpin it from the account, and potentially delete it later if there are no more global pins.
@ -941,16 +923,6 @@ components:
type: string type: string
mime_type: mime_type:
type: string type: string
AccountPinStatusResponse:
type: object
required:
- status
- progress
properties:
status:
type: string
progress:
type: number
RegistryQueryResponse: RegistryQueryResponse:
type: object type: object
properties: properties: