Created
November 30, 2016 17:00
-
-
Save YacheLee/6f4aaaab4bf3a25e3661385eae23ea3c to your computer and use it in GitHub Desktop.
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
var gcloud = require('google-cloud'); | |
var storage = gcloud.storage; | |
var fs = require('fs'); | |
module.exports = ()=> { | |
return new Promise((resolve, reject)=> { | |
var gcs = storage({ | |
projectId: 'PROJECT_ID', | |
keyFilename: __dirname+'/keys.json' | |
}); | |
var bucket = gcs.bucket('dentaltw'); | |
findAllFiles(bucket) | |
.then((files)=> { | |
const promises = []; | |
files.forEach((file, i)=> { | |
promises.push(file.makePublic()); | |
}); | |
Promise.all(promises).then(()=>{ | |
console.log("ok"); | |
resolve(); | |
}); | |
}) | |
.catch((err)=> { | |
reject(err); | |
}); | |
}); | |
function findAllFiles(bucket){ | |
return new Promise((resolve, reject)=> { | |
bucket.getFiles((err, files)=> { | |
if(err){reject(err);} | |
resolve(files); | |
}); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment