utils.d.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Progress, LocalInfo } from './upload';
  2. export declare const MB: number;
  3. export declare function getChunks(file: File, blockSize: number): Blob[];
  4. export declare function isMetaDataValid(params: {
  5. [key: string]: string;
  6. }): boolean;
  7. export declare function isCustomVarsValid(params: {
  8. [key: string]: string;
  9. }): boolean;
  10. export declare function sum(list: number[]): number;
  11. export declare function setLocalFileInfo(localKey: string, info: LocalInfo): void;
  12. export declare function createLocalKey(name: string, key: string | null | undefined, size: number): string;
  13. export declare function removeLocalFileInfo(localKey: string): void;
  14. export declare function getLocalFileInfo(localKey: string): LocalInfo | null;
  15. export declare function getAuthHeaders(token: string): {
  16. Authorization: string;
  17. };
  18. export declare function getHeadersForChunkUpload(token: string): {
  19. Authorization: string;
  20. 'content-type': string;
  21. };
  22. export declare function getHeadersForMkFile(token: string): {
  23. Authorization: string;
  24. 'content-type': string;
  25. };
  26. export declare function createXHR(): XMLHttpRequest;
  27. export declare function computeMd5(data: Blob): Promise<string>;
  28. export declare function readAsArrayBuffer(data: Blob): Promise<ArrayBuffer>;
  29. export interface ResponseSuccess<T> {
  30. data: T;
  31. reqId: string;
  32. }
  33. export interface ResponseError {
  34. code: number; /** 请求错误状态码,只有在 err.isRequestError 为 true 的时候才有效。可查阅码值对应说明。*/
  35. message: string; /** 错误信息,包含错误码,当后端返回提示信息时也会有相应的错误信息。 */
  36. isRequestError: true | undefined; /** 用于区分是否 xhr 请求错误当 xhr 请求出现错误并且后端通过 HTTP 状态码返回了错误信息时,该参数为 true否则为 undefined 。 */
  37. reqId: string; /** xhr请求错误的 X-Reqid。 */
  38. }
  39. export declare type CustomError = ResponseError | Error | any;
  40. export declare type XHRHandler = (xhr: XMLHttpRequest) => void;
  41. export interface RequestOptions {
  42. method: string;
  43. onProgress?: (data: Progress) => void;
  44. onCreate?: XHRHandler;
  45. body?: BodyInit | null;
  46. headers?: {
  47. [key: string]: string;
  48. };
  49. }
  50. export declare type Response<T> = Promise<ResponseSuccess<T>>;
  51. export declare function request<T>(url: string, options: RequestOptions): Response<T>;
  52. export declare function getPortFromUrl(url: string): string;
  53. export declare function getDomainFromUrl(url: string): string;
  54. export declare function getPutPolicy(token: string): {
  55. ak: string;
  56. bucket: string;
  57. };
  58. export declare function createObjectURL(file: File): string;
  59. export interface TransformValue {
  60. width: number;
  61. height: number;
  62. matrix: [number, number, number, number, number, number];
  63. }
  64. export declare function getTransform(image: HTMLImageElement, orientation: number): TransformValue;