-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.js
More file actions
39 lines (30 loc) · 806 Bytes
/
Copy pathdelete.js
File metadata and controls
39 lines (30 loc) · 806 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
/*
node-storage-wrapper
*/
const deleteLocalFile = (that, filePath) =>
new Promise((resolve, reject) => {
that.sdk.fs.unlink(filePath, (err) => {
if (err) reject(err)
else resolve()
})
})
module.exports = async function (uri) {
if (uri.substr(0, 5).toLowerCase() === 'gs://') {
// google cloud storage
const structure = uri.substr(5).split('/')
const bucket = structure.shift()
const path = structure.join('/')
// delete from gcp
await this.sdk.gs.bucket(bucket).file(path).delete(path)
// return ok
return Promise.resolve()
}
if (uri.substr(0, 7).toLowerCase() === 'http://' || uri.substr(0, 8).toLowerCase() === 'https://') {
// return ok
return Promise.resolve()
}
// delete file
await deleteLocalFile(this, uri)
// return ok
return Promise.resolve()
}