0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00

update API and frontend for google drive document stubs

This commit is contained in:
Charlie Humphreys
2022-03-30 23:23:45 -05:00
parent 562ba42b1b
commit fa8d47400f
7 changed files with 266 additions and 266 deletions

View File

@@ -141,13 +141,7 @@ const GoogleActions = {
name : `${brew.title}.txt`,
description : `${brew.description}`,
properties : {
title : brew.title,
published : brew.published,
version : brew.version,
renderer : brew.renderer,
tags : brew.tags,
pageCount : brew.pageCount,
systems : brew.systems.join()
title : brew.title
}
},
media : {
@@ -159,10 +153,9 @@ const GoogleActions = {
console.log('Error saving to google');
console.error(err);
throw (err);
//return res.status(500).send('Error while saving');
});
return (brew);
return true;
},
newGoogleBrew : async (auth, brew)=>{
@@ -180,12 +173,9 @@ const GoogleActions = {
'description' : `${brew.description}`,
'parents' : [folderId],
'properties' : { //AppProperties is not accessible
'shareId' : brew.shareId || nanoid(12),
'editId' : brew.editId || nanoid(12),
'title' : brew.title,
'views' : '0',
'pageCount' : brew.pageCount,
'renderer' : brew.renderer || 'legacy'
'shareId' : brew.shareId || nanoid(12),
'editId' : brew.editId || nanoid(12),
'title' : brew.title
}
};
@@ -212,26 +202,7 @@ const GoogleActions = {
console.error(err);
});
const newHomebrew = {
text : brew.text,
shareId : fileMetadata.properties.shareId,
editId : fileMetadata.properties.editId,
createdAt : new Date(),
updatedAt : new Date(),
gDrive : true,
googleId : obj.data.id,
pageCount : fileMetadata.properties.pageCount,
title : brew.title,
description : brew.description,
tags : '',
published : brew.published,
renderer : brew.renderer,
authors : [],
systems : []
};
return newHomebrew;
return obj.data.id;
},
getGoogleBrew : async (id, accessId, accessType)=>{
@@ -244,7 +215,6 @@ const GoogleActions = {
.catch((err)=>{
console.log('Error loading from Google');
throw (err);
return;
});
if(obj) {
@@ -254,9 +224,7 @@ const GoogleActions = {
throw ('Share ID does not match');
}
const serviceDrive = google.drive({ version: 'v3' });
const file = await serviceDrive.files.get({
const file = await drive.files.get({
fileId : id,
fields : 'description, properties',
alt : 'media'
@@ -273,7 +241,7 @@ const GoogleActions = {
text : file.data,
description : obj.data.description,
tags : obj.data.properties.tags ? obj.data.properties.tags : '',
tags : obj.data.properties.tags ? obj.data.properties.tags : '',
systems : obj.data.properties.systems ? obj.data.properties.systems.split(',') : [],
authors : [],
published : obj.data.properties.published ? obj.data.properties.published == 'true' : false,
@@ -287,7 +255,6 @@ const GoogleActions = {
version : parseInt(obj.data.properties.version) || 0,
renderer : obj.data.properties.renderer ? obj.data.properties.renderer : 'legacy',
gDrive : true,
googleId : id
};
@@ -295,14 +262,11 @@ const GoogleActions = {
}
},
deleteGoogleBrew : async (auth, id)=>{
deleteGoogleBrew : async (auth, id, accessId)=>{
const drive = google.drive({ version: 'v3', auth });
const googleId = id.slice(0, -12);
const accessId = id.slice(-12);
const obj = await drive.files.get({
fileId : googleId,
fileId : id,
fields : 'properties'
})
.catch((err)=>{
@@ -311,11 +275,11 @@ const GoogleActions = {
});
if(obj && obj.data.properties.editId != accessId) {
throw ('Not authorized to delete this Google brew');
throw { status: 403, message: 'Not authorized to delete this Google brew' };
}
await drive.files.update({
fileId : googleId,
fileId : id,
resource : { trashed: true }
})
.catch((err)=>{