-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemporaryUrl.ts
37 lines (34 loc) · 1.05 KB
/
temporaryUrl.ts
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
import { storage } from './lib/gcp';
// export const getTemporaryUrlImage = async (type: string, userId: string, fileName: string) => {
// try {
// const options = {
// version: 'v2', // defaults to 'v2' if missing.
// action: 'read',
// expires: Date.now() + 10000 * 60 * 60,
// };
// // const [img] = await storage
// // .bucket(`${process.env.GCP_BUCKET}`)
// // .file(type === "profiles" ? `${type}/${id}/${image}` : `${type}/${image}`)
// // .getSignedUrl(options);
// const [img] = await storage
// .bucket(`${process.env.GCP_BUCKET}`)
// .file(`${type}/${userId}/${fileName} `)
// .getSignedUrl(options);
// return img;
// } catch (error) {
// return null;
// }
// };
export const getTemporaryUrl = async (url: string) => {
try {
const options = {
version: 'v2', // defaults to 'v2' if missing.
action: 'read',
expires: Date.now() + 10000 * 60 * 60,
};
const [img] = await storage.bucket(`${process.env.GCP_BUCKET}`).file(url).getSignedUrl(options);
return img;
} catch (error) {
return null;
}
};