@uppy/companion
Version:
OAuth helper and remote fetcher for Uppy's (https://uppy.io) extensible file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Dropbox and Google Drive, S3 and more :dog:
154 lines (153 loc) • 4.73 kB
TypeScript
export class ValidationError extends Error {
}
declare class Uploader {
/**
* returns a substring of the token. Used as traceId for logging
* we avoid using the entire token because this is meant to be a short term
* access token between uppy client and companion websocket
*
* @param {string} token the token to Shorten
* @returns {string}
*/
static shortenToken(token: string): string;
static reqToOptions(req: any, size: any): {
headers: any;
httpMethod: any;
protocol: any;
endpoint: any;
uploadUrl: any;
metadata: any;
fieldname: any;
useFormData: any;
providerName: any;
size: any;
companionOptions: any;
pathPrefix: string;
storage: import("ioredis").default;
s3: {
client: any;
options: any;
};
chunkSize: any;
};
/**
* Uploads file to destination based on the supplied protocol (tus, s3-multipart, multipart)
* For tus uploads, the deferredLength option is enabled, because file size value can be unreliable
* for some providers (Instagram particularly)
*
* @typedef {object} UploaderOptions
* @property {string} endpoint
* @property {string} [uploadUrl]
* @property {string} protocol
* @property {number} [size]
* @property {string} [fieldname]
* @property {string} pathPrefix
* @property {any} [s3]
* @property {any} metadata
* @property {any} companionOptions
* @property {any} [storage]
* @property {any} [headers]
* @property {string} [httpMethod]
* @property {boolean} [useFormData]
* @property {number} [chunkSize]
* @property {string} [providerName]
*
* @param {UploaderOptions} optionsIn
*/
constructor(optionsIn: {
endpoint: string;
uploadUrl?: string;
protocol: string;
size?: number;
fieldname?: string;
pathPrefix: string;
s3?: any;
metadata: any;
companionOptions: any;
storage?: any;
headers?: any;
httpMethod?: string;
useFormData?: boolean;
chunkSize?: number;
providerName?: string;
});
/** @type {import('ioredis').Redis} */
storage: import("ioredis").Redis;
providerName: string;
options: {
headers: any;
endpoint: string;
uploadUrl?: string;
protocol: string;
size?: number;
fieldname?: string;
pathPrefix: string;
s3?: any;
metadata: any;
companionOptions: any;
storage?: any;
httpMethod?: string;
useFormData?: boolean;
chunkSize?: number;
providerName?: string;
};
token: `${string}-${string}-${string}-${string}-${string}`;
fileName: string;
size: number;
uploadFileName: string;
downloadedBytes: number;
readStream: import("stream").Readable | ReadStream;
abortReadStream(err: any): void;
_getUploadProtocol(): string;
_uploadByProtocol(req: any): Promise<any>;
_downloadStreamAsFile(stream: any): Promise<void>;
tmpPath: string;
_canStream(): any;
/**
*
* @param {import('stream').Readable} stream
* @param {import('express').Request} req
*/
uploadStream(stream: import("stream").Readable, req: import("express").Request): Promise<{
url: any;
extraData: any;
}>;
tryDeleteTmpPath(): void;
/**
*
* @param {import('stream').Readable} stream
* @param {import('express').Request} req
*/
tryUploadStream(stream: import("stream").Readable, req: import("express").Request): Promise<void>;
/**
* returns a substring of the token. Used as traceId for logging
* we avoid using the entire token because this is meant to be a short term
* access token between uppy client and companion websocket
*/
get shortToken(): string;
awaitReady(timeout: any): Promise<void>;
/**
* @typedef {{action: string, payload: object}} State
* @param {State} state
*/
saveState(state: {
action: string;
payload: object;
}): void;
throttledEmitProgress: import("lodash").DebouncedFunc<(dataToEmit: any) => void>;
/**
*
* @param {number} [bytesUploaded]
* @param {number | null} [bytesTotalIn]
*/
onProgress(bytesUploaded?: number, bytesTotalIn?: number | null): void;
tus: tus.Upload;
#private;
}
declare namespace Uploader {
let FILE_NAME_PREFIX: string;
let STORAGE_PREFIX: string;
}
export default Uploader;
import { ReadStream } from 'node:fs';
import tus from 'tus-js-client';