API
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Interfaces
DownloadResult |
DownloaderConfig |
FindFileData |
RenewFileResult |
UploadFileResult |
UploadableFile |
UploaderConfig |
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Interface: DownloadResult
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Interface: DownloaderConfig
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Interface: FindFileData
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Interface: RenewFileResult
export interface RenewFileResult {
status: string;
prevExpiryTime?: number;
newExpiryTime?: number;
amount?: number;
}
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Interface: UploadFileResult
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Interface: UploadableFile
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Interface: UploaderConfig
See also: WalletInterface
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Classes
StorageDownloader |
StorageUploader |
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Class: StorageDownloader
export class StorageDownloader {
constructor(config?: DownloaderConfig)
public async resolve(uhrpUrl: string): Promise<string[]>
public async download(uhrpUrl: string): Promise<DownloadResult>
}
See also: DownloadResult, DownloaderConfig
Method download
Downloads the content from the UHRP URL after validating the hash for integrity.
See also: DownloadResultReturns
A promise that resolves to the downloaded content.
Argument Details
- uhrpUrl
- The UHRP URL to download.
Method resolve
Resolves the UHRP URL to a list of HTTP URLs where content can be downloaded.
Returns
A promise that resolves to an array of HTTP URLs.
Argument Details
- uhrpUrl
- The UHRP URL to resolve.
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Class: StorageUploader
The StorageUploader class provides client-side methods for: - Uploading files with a specified retention period - Finding file metadata by UHRP URL - Listing all user uploads - Renewing an existing advertisement's expiry time
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
Constructor
Creates a new StorageUploader instance.
See also: UploaderConfigArgument Details
- config
- An object containing the storage server's URL and a wallet interface
Method findFile
Retrieves metadata for a file matching the given UHRP URL from the /find
route.
Returns
An object with file name, size, MIME type, and expiry time
Argument Details
- uhrpUrl
- The UHRP URL, e.g. "uhrp://abcd..."
Throws
If the server or the route returns an error
Method listUploads
Lists all advertisements belonging to the user from the /list
route.
Returns
The array of uploads returned by the server
Throws
If the server or the route returns an error
Method publishFile
Publishes a file to the storage server with the specified retention period.
This will: 1. Request an upload URL from the server. 2. Perform an HTTP PUT to upload the file’s raw bytes. 3. Return a UHRP URL referencing the file once published.
public async publishFile(params: {
file: UploadableFile;
retentionPeriod: number;
}): Promise<UploadFileResult>
Returns
An object with the file's UHRP URL
Throws
If the server or upload step returns a non-OK response
Method renewFile
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.
Returns
An object with the new and previous expiry times, plus any cost
Argument Details
- uhrpUrl
- The UHRP URL of the file (e.g., "uhrp://abcd1234...")
- additionalMinutes
- The number of minutes to extend
Throws
If the request fails or the server returns an error
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Functions
Types
Enums
Variables
getHashFromURL |
getURLForFile |
getURLForHash |
isValidURL |
normalizeURL |
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Variable: getHashFromURL
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
Variable: getURLForFile
getURLForFile = (file: number[]): string => {
const hash = sha256(file);
return getURLForHash(hash);
}
See also: getURLForHash, sha256
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Variable: getURLForHash
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
Variable: isValidURL
isValidURL = (URL: string): boolean => {
try {
getHashFromURL(URL);
return true;
}
catch (e) {
return false;
}
}
See also: getHashFromURL
Links: API, Interfaces, Classes, Functions, Types, Enums, Variables
Variable: normalizeURL
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