-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove.js
More file actions
42 lines (32 loc) · 949 Bytes
/
Copy pathmove.js
File metadata and controls
42 lines (32 loc) · 949 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
/*
node-storage-wrapper
*/
module.exports = async function (sourceUri, destinationUri, keepOriginal) {
if (sourceUri.substr(0, 5).toLowerCase() === 'gs://' && destinationUri.substr(0, 5).toLowerCase() === 'gs://') {
// google to google transfer
// parse source
const structure = sourceUri.substr(5).split('/')
const bucket = structure.shift()
const path = structure.join('/')
// move file within gcs
if (keepOriginal !== true) {
// move file
await this.sdk.gs.bucket(bucket).file(path).move(destinationUri)
} else {
// copy file
await this.sdk.gs.bucket(bucket).file(path).copy(destinationUri)
}
// return ok
return Promise.resolve()
}
// download file
const blob = await this.load(sourceUri)
// save file to destination
await this.save(destinationUri, blob)
// delete file if in production
if (keepOriginal !== true) {
await this.delete(sourceUri)
}
// return ok
return Promise.resolve()
}