-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
node-storage-wrapper | ||
This module provides easy access to combine bucket + path to unique URIs | ||
*/ | ||
|
||
module.exports = async function (uri, ttl) { | ||
try { | ||
if (uri.substr(0, 5).toLowerCase() == 's3://') { | ||
// log progress | ||
this.sdk.log(this, 'log', ['storage.createUrl.aws >', uri]); | ||
|
||
return Promise.reject('not implemented'); | ||
} else if (uri.substr(0, 5).toLowerCase() == 'gs://') { | ||
// google cloud storage | ||
let structure = uri.substr(5).split('/'); | ||
let bucket = structure.shift(); | ||
let path = structure.join('/'); | ||
|
||
// log progress | ||
this.sdk.log(this, 'log', ['storage.createUrl.gcp >', uri]); | ||
|
||
// set config | ||
const config = { | ||
action: 'read', | ||
expires: Date.now() + ttl, | ||
}; | ||
|
||
// create link | ||
var [url] = await this.sdk.gs.bucket(bucket).file(path).getSignedUrl(config); | ||
|
||
// return link | ||
return Promise.resolve(url); | ||
} else if ( | ||
uri.substr(0, 7).toLowerCase() == 'http://' || | ||
uri.substr(0, 8).toLowerCase() == 'https://' | ||
) { | ||
// log progress | ||
this.sdk.log(this, 'log', ['storage.createUrl.https >', uri]); | ||
|
||
// return link | ||
return Promise.resolve(uri); | ||
} else { | ||
// log progress | ||
this.sdk.log(this, 'log', ['storage.createUrl.local >', uri]); | ||
|
||
return Promise.reject('not implemented'); | ||
} | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters