-
Notifications
You must be signed in to change notification settings - Fork 415
Expand file tree
/
Copy pathutils.ts
More file actions
45 lines (43 loc) · 941 Bytes
/
utils.ts
File metadata and controls
45 lines (43 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { File } from '@google-cloud/storage';
export interface FirebaseMetadata {
name: string;
bucket: string;
generation: string;
metageneration: string;
contentType: string;
timeCreated: string;
updated: string;
storageClass: string;
size: string;
md5Hash: string;
contentEncoding: string;
contentDisposition: string;
crc32c: string;
etag: string;
downloadTokens?: string;
}
export function getFirebaseMetadata(
endpoint: string,
file: File,
headers?: { [key: string]: string }
): Promise<FirebaseMetadata> {
const uri = `${endpoint}/b/${file.bucket.name}/o/${encodeURIComponent(
file.name
)}`;
return new Promise((resolve, reject) => {
file.storage.makeAuthenticatedRequest(
{
method: 'GET',
uri,
headers,
},
(err, body) => {
if (err) {
reject(err);
} else {
resolve(body);
}
}
);
});
}