Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
DownloadResult |
DownloaderConfig |
FindFileData |
RenewFileResult |
UploadFileResult |
UploadableFile |
UploaderConfig |
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
export interface DownloadResult {
data: number[];
mimeType: string | null;
}
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
export interface DownloaderConfig {
networkPreset: "mainnet" | "testnet" | "local";
}
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
export interface FindFileData {
name: string;
size: string;
mimeType: string;
expiryTime: number;
}
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
export interface RenewFileResult {
status: string;
prevExpiryTime?: number;
newExpiryTime?: number;
amount?: number;
}
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
export interface UploadFileResult {
published: boolean;
uhrpURL: string;
}
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
export interface UploadableFile {
data: number[];
type: string;
}
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
export interface UploaderConfig {
storageURL: string;
wallet: WalletInterface;
}
See also: WalletInterface
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
StorageDownloader |
StorageUploader |
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Locates HTTP URLs where content can be downloaded. It uses the passed or the default one.
export class StorageDownloader {
constructor(config?: DownloaderConfig)
public async resolve(uhrpUrl: string): Promise<string[]>
public async download(uhrpUrl: string): Promise<DownloadResult>
}
See also: DownloadResult, DownloaderConfig
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
The StorageUploader class provides client-side methods for:
export class StorageUploader {
constructor(config: UploaderConfig)
public async publishFile(params: {
file: UploadableFile;
retentionPeriod: number;
}): Promise<UploadFileResult>
public async findFile(uhrpUrl: string): Promise<FindFileData>
public async listUploads(): Promise<any>
public async renewFile(uhrpUrl: string, additionalMinutes: number): Promise<RenewFileResult>
}
See also: FindFileData, RenewFileResult, UploadFileResult, UploadableFile, UploaderConfig
Creates a new StorageUploader instance.
constructor(config: UploaderConfig)
See also: UploaderConfig
Argument Details
Retrieves metadata for a file matching the given UHRP URL from the /find
route.
public async findFile(uhrpUrl: string): Promise<FindFileData>
See also: FindFileData
Returns
An object with file name, size, MIME type, and expiry time
Argument Details
Throws
If the server or the route returns an error
Lists all advertisements belonging to the user from the /list
route.
public async listUploads(): Promise<any>
Returns
The array of uploads returned by the server
Throws
If the server or the route returns an error
Publishes a file to the storage server with the specified retention period.
This will:
public async publishFile(params: {
file: UploadableFile;
retentionPeriod: number;
}): Promise<UploadFileResult>
See also: UploadFileResult, UploadableFile
Returns
An object with the file’s UHRP URL
Throws
If the server or upload step returns a non-OK response
Renews the hosting time for an existing file advertisement identified by uhrpUrl.
Calls the /renew
route to add additionalMinutes
to the GCS customTime
and re-mint the advertisement token on-chain.
public async renewFile(uhrpUrl: string, additionalMinutes: number): Promise<RenewFileResult>
See also: RenewFileResult
Returns
An object with the new and previous expiry times, plus any cost
Argument Details
Throws
If the request fails or the server returns an error
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
getHashFromURL |
getURLForFile |
getURLForHash |
isValidURL |
normalizeURL |
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
getHashFromURL = (URL: string): number[] => {
URL = normalizeURL(URL);
const { data, prefix } = fromBase58Check(URL, undefined, 2);
if (data.length !== 32) {
throw new Error("Invalid length!");
}
if (toHex(prefix as number[]) !== "ce00") {
throw new Error("Bad prefix");
}
return data as number[];
}
See also: fromBase58Check, normalizeURL, toHex
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
getURLForFile = (file: number[]): string => {
const hash = sha256(file);
return getURLForHash(hash);
}
See also: getURLForHash, sha256
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
getURLForHash = (hash: number[]): string => {
if (hash.length !== 32) {
throw new Error("Hash length must be 32 bytes (sha256)");
}
return toBase58Check(hash, toArray("ce00", "hex"));
}
See also: toArray, toBase58Check
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
isValidURL = (URL: string): boolean => {
try {
getHashFromURL(URL);
return true;
}
catch (e) {
return false;
}
}
See also: getHashFromURL
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
normalizeURL = (URL: string): string => {
if (URL.toLowerCase().startsWith("uhrp:"))
URL = URL.slice(5);
if (URL.startsWith("//"))
URL = URL.slice(2);
return URL;
}
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables