UNPKG

@webda/core

Version:

Expose API with Lambda

134 lines (133 loc) 3.53 kB
import { Readable } from "stream"; import { CloudBinary, CloudBinaryParameters, CoreModel } from "../index.js"; import { WebContext } from "../utils/context.js"; import { BinaryFile, BinaryMap, BinaryService } from "./binary.js"; import CryptoService from "./cryptoservice.js"; export declare class FileBinaryParameters extends CloudBinaryParameters { /** * Define the folder to store objects in */ folder: string; /** * Maximum size to handle * @default 10Mb */ maxSize?: number; constructor(params: any, service: BinaryService); } /** * FileBinary handles the storage of binary on a hard drive * * The structure used for now is * /folder/{hash}/data * /folder/{hash}/{targetStore}_{uuid} * /folder/{hash}/challenge * * It takes one parameter * folder: "path" * * See Binary the general interface * @category CoreServices * @WebdaModda */ export declare class FileBinary<T extends FileBinaryParameters = FileBinaryParameters> extends CloudBinary<T> { /** * Used for hmac */ cryptoService: CryptoService; /** * Load parameters * * @param params */ loadParameters(params: any): CloudBinaryParameters; /** * Create the storage folder if needed */ computeParameters(): void; initRoutes(): void; /** * Download a binary with a challenge */ downloadBinaryLink(ctx: WebContext): Promise<void>; /** * @inheritdoc */ _get(info: BinaryMap): Promise<Readable>; /** * Get signed url to download an element */ getSignedUrlFromMap(map: BinaryMap, expires: number, context: WebContext): Promise<string>; /** * Get storage path for a hash * @param hash * @param postfix * @returns */ _getPath(hash: string, postfix?: string): string; _touch(filePath: any, mode?: number): void; /** * Get token for action * * @param ctx * @param expiresIn */ getToken(hash: string, method: "PUT" | "GET", expiresIn?: number): Promise<string>; /** * Get put URL * @param ctx * @returns */ getPutUrl(ctx: WebContext<BinaryFile>): Promise<string>; /** * Will give you the redirect url * * @ignore */ putRedirectUrl(ctx: WebContext<BinaryFile>): Promise<{ url: string; method: string; }>; /** * Store the binary sent * * Check the hashs match and that a storage folder exists * The storage folder should have been created by the putRedirectUrl * * @ignore */ storeBinary(ctx: WebContext): Promise<void>; /** * @inheritdoc */ getUsageCount(hash: string): Promise<number>; /** * Delete any usage marker and hash * * @param hash to remove * @returns */ _cleanHash(hash: string): Promise<void>; /** * @override */ _cleanUsage(hash: string, uuid: string, attribute?: string): Promise<void>; /** * @inheritdoc */ delete(object: CoreModel, property: string, index?: number): Promise<void>; challenge(hash: any, challenge: any): boolean; /** * @inheritdoc */ cascadeDelete(info: BinaryMap, uuid: string): Promise<void>; _store(file: BinaryFile, object: CoreModel, attribute: string): Promise<void>; /** * @inheritdoc */ store(object: CoreModel, property: string, file: BinaryFile): Promise<any>; /** * Clean all data */ ___cleanData(): Promise<void>; }