Files
healer-man/src/content/nativeContentStorage.ts
T
2026-09-11 14:26:15 -04:00

43 lines
1.3 KiB
TypeScript

import { registerPlugin, type PluginListenerHandle } from "@capacitor/core";
export interface ContentDownloadProgress {
readonly logicalPath: string;
readonly downloadedBytes: number;
readonly totalBytes: number;
}
export interface NativeContentFileResult {
readonly fileUri: string;
readonly bytes: number;
readonly reused: boolean;
}
interface DownloadOptions {
readonly url: string;
readonly logicalPath: string;
readonly sha256: string;
readonly extension: string;
readonly bytes: number;
readonly encoding?: "gzip";
readonly downloadSha256?: string;
readonly downloadBytes?: number;
}
interface ObjectOptions {
readonly sha256: string;
readonly extension: string;
}
interface NativeContentStoragePlugin {
download(options: DownloadOptions): Promise<NativeContentFileResult>;
remove(options: ObjectOptions): Promise<void>;
has(options: ObjectOptions & { readonly bytes: number }): Promise<{ readonly exists: boolean; readonly fileUri?: string }>;
getFreeBytes(): Promise<{ readonly freeBytes: number }>;
addListener(
eventName: "downloadProgress",
listener: (event: ContentDownloadProgress) => void,
): Promise<PluginListenerHandle>;
}
export const NativeContentStorage = registerPlugin<NativeContentStoragePlugin>("ContentStorage");