1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import * as ConfigStore from 'configstore';
|
10 | import { GaxiosOptions, GaxiosPromise, GaxiosResponse } from 'gaxios';
|
11 | import { GoogleAuthOptions } from 'google-auth-library';
|
12 | import * as Pumpify from 'pumpify';
|
13 | export declare const PROTOCOL_REGEX: RegExp;
|
14 | export interface ErrorWithCode extends Error {
|
15 | code: number;
|
16 | }
|
17 | export declare type CreateUriCallback = (err: Error | null, uri?: string) => void;
|
18 | export interface Encryption {
|
19 | key: {};
|
20 | hash: {};
|
21 | }
|
22 | export declare type PredefinedAcl = 'authenticatedRead' | 'bucketOwnerFullControl' | 'bucketOwnerRead' | 'private' | 'projectPrivate' | 'publicRead';
|
23 | export interface QueryParameters {
|
24 | contentEncoding?: string;
|
25 | ifGenerationMatch?: number;
|
26 | ifGenerationNotMatch?: number;
|
27 | ifMetagenerationMatch?: number;
|
28 | ifMetagenerationNotMatch?: number;
|
29 | kmsKeyName?: string;
|
30 | predefinedAcl?: PredefinedAcl;
|
31 | projection?: 'full' | 'noAcl';
|
32 | userProject?: string;
|
33 | }
|
34 | export interface UploadConfig {
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | apiEndpoint?: string;
|
43 | |
44 |
|
45 |
|
46 | bucket: string;
|
47 | |
48 |
|
49 |
|
50 | file: string;
|
51 | |
52 |
|
53 |
|
54 | authConfig?: GoogleAuthOptions;
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | authClient?: {
|
62 | request: <T = any>(opts: GaxiosOptions) => Promise<GaxiosResponse<T>> | GaxiosPromise<T>;
|
63 | };
|
64 | |
65 |
|
66 |
|
67 |
|
68 | configPath?: string;
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 | customRequestOptions?: GaxiosOptions;
|
75 | |
76 |
|
77 |
|
78 |
|
79 | generation?: number;
|
80 | |
81 |
|
82 |
|
83 |
|
84 | key?: string | Buffer;
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | kmsKeyName?: string;
|
92 | |
93 |
|
94 |
|
95 | metadata?: ConfigMetadata;
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 | offset?: number;
|
102 | |
103 |
|
104 |
|
105 | origin?: string;
|
106 | |
107 |
|
108 |
|
109 |
|
110 | params?: QueryParameters;
|
111 | |
112 |
|
113 |
|
114 | predefinedAcl?: PredefinedAcl;
|
115 | |
116 |
|
117 |
|
118 |
|
119 | private?: boolean;
|
120 | |
121 |
|
122 |
|
123 |
|
124 | public?: boolean;
|
125 | |
126 |
|
127 |
|
128 |
|
129 | uri?: string;
|
130 | |
131 |
|
132 |
|
133 |
|
134 | userProject?: string;
|
135 | |
136 |
|
137 |
|
138 | retryOptions?: RetryOptions;
|
139 | }
|
140 | export interface ConfigMetadata {
|
141 | [key: string]: any;
|
142 | |
143 |
|
144 |
|
145 | contentLength?: number;
|
146 | |
147 |
|
148 |
|
149 | contentType?: string;
|
150 | }
|
151 | export interface RetryOptions {
|
152 | retryDelayMultiplier?: number;
|
153 | totalTimeout?: number;
|
154 | maxRetryDelay?: number;
|
155 | autoRetry?: boolean;
|
156 | maxRetries?: number;
|
157 | retryableErrorFn?: (err: ApiError) => boolean;
|
158 | }
|
159 | export interface ApiError extends Error {
|
160 | code?: number;
|
161 | }
|
162 | export declare class Upload extends Pumpify {
|
163 | bucket: string;
|
164 | file: string;
|
165 | apiEndpoint: string;
|
166 | baseURI: string;
|
167 | authConfig?: {
|
168 | scopes?: string[];
|
169 | };
|
170 | authClient: {
|
171 | request: <T = any>(opts: GaxiosOptions) => Promise<GaxiosResponse<T>> | GaxiosPromise<T>;
|
172 | };
|
173 | cacheKey: string;
|
174 | customRequestOptions: GaxiosOptions;
|
175 | generation?: number;
|
176 | key?: string | Buffer;
|
177 | kmsKeyName?: string;
|
178 | metadata: ConfigMetadata;
|
179 | offset?: number;
|
180 | origin?: string;
|
181 | params: QueryParameters;
|
182 | predefinedAcl?: PredefinedAcl;
|
183 | private?: boolean;
|
184 | public?: boolean;
|
185 | uri?: string;
|
186 | userProject?: string;
|
187 | encryption?: Encryption;
|
188 | configStore: ConfigStore;
|
189 | uriProvidedManually: boolean;
|
190 | numBytesWritten: number;
|
191 | numRetries: number;
|
192 | contentLength: number | '*';
|
193 | retryLimit: number;
|
194 | maxRetryDelay: number;
|
195 | retryDelayMultiplier: number;
|
196 | maxRetryTotalTimeout: number;
|
197 | timeOfFirstRequest: number;
|
198 | retryableErrorFn?: (err: ApiError) => boolean;
|
199 | private bufferStream?;
|
200 | private offsetStream?;
|
201 | constructor(cfg: UploadConfig);
|
202 | createURI(): Promise<string>;
|
203 | createURI(callback: CreateUriCallback): void;
|
204 | protected createURIAsync(): Promise<string>;
|
205 | private continueUploading;
|
206 | private startUploading;
|
207 | private onChunk;
|
208 | private getAndSetOffset;
|
209 | private makeRequest;
|
210 | private makeRequestStream;
|
211 | private restart;
|
212 | private get;
|
213 | private set;
|
214 | deleteConfig(): void;
|
215 | /**
|
216 | * @return {bool} is the request good?
|
217 | */
|
218 | private onResponse;
|
219 | |
220 |
|
221 |
|
222 | private attemptDelayedRetry;
|
223 | |
224 |
|
225 |
|
226 | private getRetryDelay;
|
227 | private sanitizeEndpoint;
|
228 | }
|
229 | export declare function upload(cfg: UploadConfig): Upload;
|
230 | export declare function createURI(cfg: UploadConfig): Promise<string>;
|
231 | export declare function createURI(cfg: UploadConfig, callback: CreateUriCallback): void;
|