2023-12-10 20:03:56 +00:00
|
|
|
import {
|
|
|
|
uploadFile,
|
|
|
|
uploadLargeFile,
|
|
|
|
uploadDirectory,
|
|
|
|
uploadDirectoryRequest,
|
|
|
|
uploadSmallFile,
|
|
|
|
uploadSmallFileRequest,
|
|
|
|
uploadLargeFileRequest,
|
2023-12-12 02:53:10 +00:00
|
|
|
uploadWebapp,
|
|
|
|
uploadWebappRequest,
|
2024-03-17 18:06:10 +00:00
|
|
|
getTusOptions,
|
2023-12-11 01:05:57 +00:00
|
|
|
} from "./methods/upload.js";
|
2023-12-11 04:33:55 +00:00
|
|
|
import {
|
2024-02-13 05:30:13 +00:00
|
|
|
downloadBlob,
|
2023-12-11 04:33:55 +00:00
|
|
|
downloadData,
|
|
|
|
downloadFile,
|
2024-02-13 05:30:13 +00:00
|
|
|
downloadProof,
|
2023-12-11 04:33:55 +00:00
|
|
|
getCidUrl,
|
|
|
|
getMetadata,
|
|
|
|
} from "./methods/download.js";
|
2023-12-10 20:03:56 +00:00
|
|
|
|
2024-02-13 04:25:48 +00:00
|
|
|
import { ensureUrl } from "./utils/url.js";
|
2023-12-10 20:03:56 +00:00
|
|
|
|
2023-12-12 03:44:43 +00:00
|
|
|
import {
|
|
|
|
createEntry,
|
2023-12-12 20:48:13 +00:00
|
|
|
getEntry,
|
2023-12-12 03:44:43 +00:00
|
|
|
publishEntry,
|
|
|
|
subscribeToEntry,
|
|
|
|
} from "./methods/registry.js";
|
2024-03-18 13:21:05 +00:00
|
|
|
import { CustomClientOptions } from "./utils/options.js";
|
|
|
|
import { throwValidationError } from "./utils/validation.js";
|
2023-12-10 20:03:56 +00:00
|
|
|
|
2024-03-16 15:44:32 +00:00
|
|
|
import { accountPins } from "./methods/account.js";
|
|
|
|
|
2023-12-10 20:03:56 +00:00
|
|
|
/**
|
|
|
|
* The S5 Client which can be used to access S5-net.
|
|
|
|
*/
|
|
|
|
export class S5Client {
|
|
|
|
// Upload
|
|
|
|
uploadFile = uploadFile;
|
|
|
|
uploadDirectory = uploadDirectory;
|
2024-02-13 04:25:48 +00:00
|
|
|
// Set methods (defined in other files).
|
2023-12-12 02:53:10 +00:00
|
|
|
uploadWebapp = uploadWebapp;
|
2023-12-10 20:03:56 +00:00
|
|
|
downloadFile = downloadFile;
|
2023-12-11 04:33:55 +00:00
|
|
|
downloadData = downloadData;
|
2024-02-13 05:30:13 +00:00
|
|
|
downloadBlob = downloadBlob;
|
|
|
|
downloadProof = downloadProof;
|
2023-12-10 20:03:56 +00:00
|
|
|
getCidUrl = getCidUrl;
|
|
|
|
getMetadata = getMetadata;
|
2023-12-11 02:06:43 +00:00
|
|
|
// Registry
|
|
|
|
subscribeToEntry = subscribeToEntry;
|
2023-12-12 03:26:42 +00:00
|
|
|
publishEntry = publishEntry;
|
2023-12-12 03:44:43 +00:00
|
|
|
createEntry = createEntry;
|
2023-12-12 20:48:13 +00:00
|
|
|
getEntry = getEntry;
|
2024-03-16 15:44:32 +00:00
|
|
|
accountPins = accountPins;
|
2024-02-13 04:25:48 +00:00
|
|
|
// Download
|
2024-03-17 18:06:10 +00:00
|
|
|
getTusOptions = getTusOptions;
|
2024-02-13 04:25:48 +00:00
|
|
|
protected uploadSmallFile = uploadSmallFile;
|
|
|
|
protected uploadSmallFileRequest = uploadSmallFileRequest;
|
|
|
|
protected uploadLargeFile = uploadLargeFile;
|
|
|
|
protected uploadLargeFileRequest = uploadLargeFileRequest;
|
|
|
|
protected uploadDirectoryRequest = uploadDirectoryRequest;
|
|
|
|
protected uploadWebappRequest = uploadWebappRequest;
|
2023-12-11 02:06:43 +00:00
|
|
|
|
2023-12-10 20:03:56 +00:00
|
|
|
/**
|
|
|
|
* The S5 Client which can be used to access S5-net.
|
|
|
|
*
|
|
|
|
* @class
|
2024-02-13 04:25:48 +00:00
|
|
|
* @param [portalUrl] The initial portal URL to use to access S5, if specified. A request will be made to this URL to get the actual portal URL. To use the default portal while passing custom options, pass "".
|
2023-12-10 20:03:56 +00:00
|
|
|
* @param [customOptions] Configuration for the client.
|
|
|
|
*/
|
2024-02-13 04:25:48 +00:00
|
|
|
constructor(portalUrl: string, customOptions: CustomClientOptions = {}) {
|
|
|
|
if (!portalUrl) {
|
|
|
|
throwValidationError("portalUrl", portalUrl, "parameter", "string");
|
2023-12-10 20:03:56 +00:00
|
|
|
}
|
2024-02-13 04:25:48 +00:00
|
|
|
this._portalUrl = ensureUrl(portalUrl);
|
2024-03-18 13:14:34 +00:00
|
|
|
this._clientOptions = customOptions;
|
2023-12-10 20:03:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-18 13:14:34 +00:00
|
|
|
private _clientOptions: CustomClientOptions;
|
|
|
|
|
|
|
|
get clientOptions(): CustomClientOptions {
|
|
|
|
return this._clientOptions;
|
|
|
|
}
|
2023-12-10 20:03:56 +00:00
|
|
|
|
2024-03-18 13:14:44 +00:00
|
|
|
set clientOptions(value: CustomClientOptions) {
|
|
|
|
this._clientOptions = value;
|
2023-12-10 20:03:56 +00:00
|
|
|
}
|
|
|
|
|
2024-02-13 04:25:48 +00:00
|
|
|
private _portalUrl: string;
|
2023-12-10 20:03:56 +00:00
|
|
|
|
2024-02-13 04:25:48 +00:00
|
|
|
get portalUrl(): string {
|
|
|
|
return this._portalUrl;
|
2023-12-10 20:03:56 +00:00
|
|
|
}
|
|
|
|
|
2024-02-13 04:25:48 +00:00
|
|
|
public static create(
|
|
|
|
portalUrl: string,
|
|
|
|
customOptions: CustomClientOptions = {},
|
|
|
|
) {
|
|
|
|
return new S5Client(portalUrl, customOptions);
|
2023-12-10 20:03:56 +00:00
|
|
|
}
|
|
|
|
}
|