-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateUrl.js
More file actions
35 lines (26 loc) · 791 Bytes
/
Copy pathcreateUrl.js
File metadata and controls
35 lines (26 loc) · 791 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
/*
node-storage-wrapper
This module provides easy access to combine bucket + path to unique URIs
*/
module.exports = async function (uri, ttl) {
if (uri.substr(0, 5).toLowerCase() === 'gs://') {
// google cloud storage
const structure = uri.substr(5).split('/')
const bucket = structure.shift()
const path = structure.join('/')
// set config
const config = {
action: 'read',
expires: Date.now() + ttl,
}
// create link
const [url] = await this.sdk.gs.bucket(bucket).file(path).getSignedUrl(config)
// return link
return Promise.resolve(url)
}
if (uri.substr(0, 7).toLowerCase() === 'http://' || uri.substr(0, 8).toLowerCase() === 'https://') {
// return link
return Promise.resolve(uri)
}
return Promise.reject(new Error('not implemented'))
}