mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 20:42:43 +00:00
Add service account to file permissions
This commit is contained in:
@@ -6,6 +6,7 @@ import config from './config.js';
|
||||
|
||||
|
||||
let serviceAuth;
|
||||
let clientEmail;
|
||||
if(!config.get('service_account')){
|
||||
const reset = '\x1b[0m'; // Reset to default style
|
||||
const yellow = '\x1b[33m'; // yellow color
|
||||
@@ -15,6 +16,10 @@ if(!config.get('service_account')){
|
||||
JSON.parse(config.get('service_account')) :
|
||||
config.get('service_account');
|
||||
|
||||
if(keys?.client_email) {
|
||||
clientEmail = keys.client_email;
|
||||
}
|
||||
|
||||
try {
|
||||
serviceAuth = googleDrive.auth.fromJSON(keys);
|
||||
serviceAuth.scopes = ['https://www.googleapis.com/auth/drive'];
|
||||
@@ -227,9 +232,27 @@ const GoogleActions = {
|
||||
|
||||
if(!obj) return;
|
||||
|
||||
if(clientEmail) {
|
||||
await drive.permissions.create({
|
||||
resource : {
|
||||
type : 'user',
|
||||
emailAddress : clientEmail,
|
||||
role : 'writer'
|
||||
},
|
||||
fileId : obj.data.id,
|
||||
fields : 'id',
|
||||
})
|
||||
.catch((err)=>{
|
||||
console.log('Error updating permissions');
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
await drive.permissions.create({
|
||||
resource : { type : 'anyone',
|
||||
role : 'writer' },
|
||||
resource : {
|
||||
type : 'anyone',
|
||||
role : 'writer'
|
||||
},
|
||||
fileId : obj.data.id,
|
||||
fields : 'id',
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user