@c8y/ngx-components
Version:
Angular modules for Cumulocity IoT applications
180 lines • 7.17 kB
TypeScript
import { IManagedObjectBinary, InventoryBinaryService, SystemOptionsService } from '@c8y/client';
import { Observable } from 'rxjs';
import { Stream } from 'stream';
import * as i0 from "@angular/core";
export interface IFetchWithProgress {
totalBytes: number;
bufferedBytes: number;
percentage: number;
bytesPerSecond: number;
blob?: Blob;
}
export declare enum GENERIC_FILE_TYPE {
ARCHIVE = "archive",
AUDIO = "audio",
CODE = "code",
EXCEL = "excel",
IMAGE = "image",
PDF = "pdf",
POWERPOINT = "powerpoint",
TEXT = "text",
VIDEO = "video",
WORD = "word",
EPL = "epl"
}
export declare class FilesService {
private systemOptionsService;
private inventoryBinaryService;
readonly DEFAULT_BYTES_LIMIT = 52428800;
readonly FILENAME_MAX_LENGTH = 128;
fileTypeExtensionsMap: {
readonly archive: {
readonly exts: readonly ["7z", "apk", "cab", "gz", "iso", "jar", "rar", "tar", "zip"];
};
readonly audio: {
readonly exts: readonly ["3gp", "aiff", "aac", "amr", "m4a", "m4p", "mp3", "oga", "ogg", "raw", "wav", "wma"];
};
readonly code: {
readonly exts: readonly ["aspx", "exe", "htm", "html", "jad", "js", "json", "jsp", "php", "xml"];
};
readonly excel: {
readonly exts: readonly ["xls", "xlsx"];
};
readonly image: {
readonly exts: readonly ["bmp", "gif", "jpeg", "jpg", "png", "tiff", "svg", "ico", "apng", "webp"];
};
readonly pdf: {
readonly exts: readonly ["pdf"];
};
readonly powerpoint: {
readonly exts: readonly ["ppt", "pptx"];
};
readonly text: {
readonly exts: readonly ["txt"];
};
readonly video: {
readonly exts: readonly ["asf", "avi", "flv", "mov", "mp4", "ogv", "qt", "rm", "rmvb", "wmv", "3gp"];
};
readonly word: {
readonly exts: readonly ["doc", "docx"];
};
readonly epl: {
readonly exts: readonly ["mon"];
};
};
private fileSizeLimitCfg;
constructor(systemOptionsService: SystemOptionsService, inventoryBinaryService: InventoryBinaryService);
/**
* Checks if files have valid size.
* @param files Files to check.
* @returns Returns true if each file has the correct size.
*/
haveValidSizes(files: FileList, maxFileSizeInBytes?: number): Promise<boolean>;
/**
* Checks the system file size limit, if not available returns the default value.
* Default limit: [DEFAULT_BYTES_LIMIT]{@link DEFAULT_BYTES_LIMIT}
* @returns Returns promise with the limit value.
*/
loadBytesSizeLimit(): Promise<number>;
/**
* Checks the size of the file
* @param file File to check.
* @returns Returns size of the file in bytes.
*/
size(file: File | IManagedObjectBinary): number;
/**
* Checks whether files have allowed extensions.
* If the accept parameter is not specified, all extensions are accepted.
* @param files Files to check.
* @param accept String of comma separated file extensions and generic types ([GENERIC_FILE_TYPE]{@link GENERIC_FILE_TYPE}), e.g. .zip,.7z,excel.
* @returns Returns true if each file has allowed extension.
*/
haveValidExtensions(files: FileList | File | File[], accept: string): boolean;
/**
* Checks if file names have allowed extension.
* If the accept parameter is not specified, all extensions are accepted.
* @param fileNames The file names to check.
* @param accept String of comma separated file extensions and generic types ([GENERIC_FILE_TYPE]{@link GENERIC_FILE_TYPE}), e.g. .zip,.7z,excel.
* @returns Returns true if each file has allowed extension.
*/
fileNamesHaveValidExtension(fileNames: string | string[], accept: string): boolean;
/**
* Checks if each file has a valid filename length.
* @param files Files to check.
* @returns Returns true if each file has a valid filename length.
*/
checkMaxLength(files: FileList): boolean;
/**
* Extracts the file extension.
* @param fileOrFileName File or name of file from which the extension should be extracted.
* @returns Returns the file extension or undefined if the file has no extension.
*/
getFileExtension(fileOrFileName: File | string): string | undefined;
/**
* List of file extensions.
* @returns Returns list of file extensions.
*/
getFileExtensions(): string[];
/**
* The list of generic file types.
* @returns Returns the list of generic file types.
*/
getGenericFileTypes(): GENERIC_FILE_TYPE[];
/**
* @ignore
*/
mapGenericFileTypesToExtensions(genericFileTypes?: GENERIC_FILE_TYPE[]): string[];
/**
* Extracts a list of file extensions from a string.
* Can accept generic file types check: [GENERIC_FILE_TYPE]{@link GENERIC_FILE_TYPE}.
*
* @param str String from which the file extensions are extracted (comma separated values).
* Accepted string format:
* * ".zip,.iso",
* * "zip,ISO",
* * "archive".
* Important: generic types cannot contain a dot. All values with a dot are treated as a normal extension.
* @returns Returns a list of the file extensions.
*/
extractFileExtensions(str: string): string[];
/**
* Converts a file to a base64 image string.
*
* @param file The file to convert to base 64.
* @returns The image string in base64 format.
*/
toBase64(file: File): Promise<string>;
/**
* Allows to get a File representation of an managed object binary. Can be used
* to convert this file toBase64 to show it to the end-user.
* @param binary The binary managed object
* @returns The file representation.
*/
getFile(binary: IManagedObjectBinary): Promise<File>;
/**
* Allows to calculate the hash sum of the provided file.
* @param file The file to hash.
* @returns The SHA-256 hash of the file.
*/
getHashSumOfFile(file: File | Blob): Promise<string>;
/**
* Allows to download a file (opens the browser download prompt).
* @param binary The binary managed object.
*/
download(binary: IManagedObjectBinary): Promise<void>;
/**
* Loads the file to JavaScript memory.
* Returns an observable that emits progression status object,
* and after download is completed, blob property is populated with Blob result object.
* Unsubscribing from the returned observable aborts the file fetch request.
*
* @param binary The binary managed object.
*/
fetchFileWithProgress$(binary: IManagedObjectBinary): Observable<IFetchWithProgress>;
uploadFileWithProgress$(file: Stream | Buffer | File | Blob): Observable<IFetchWithProgress>;
private processResponse$;
private isGenericType;
static ɵfac: i0.ɵɵFactoryDeclaration<FilesService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<FilesService>;
}
//# sourceMappingURL=files.service.d.ts.map