mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 20:23:39 +00:00
Merge pull request #1118 from naturalcrit/fixGoogleMetadata
Fix metadata in Google docs
This commit is contained in:
10
changelog.md
10
changelog.md
@@ -1,5 +1,9 @@
|
|||||||
# changelog
|
# changelog
|
||||||
|
|
||||||
|
### Wednesday, 25/11/2020 - v2.10.4
|
||||||
|
- Fixed Google Drive brews not saving metadata (view count, description, etc.) Note that we are still working on making published Google brews visible to the public when viewing your profile page.
|
||||||
|
- Fixed inconsistent font size for bullet lists inside notes (thanks /u/garumoo! re:1085)
|
||||||
|
|
||||||
### Thursday, 22/10/2020 - v2.10.3
|
### Thursday, 22/10/2020 - v2.10.3
|
||||||
- Fixed brews with broken code crashing the edit page when loaded (the "blue screen of death" bug).
|
- Fixed brews with broken code crashing the edit page when loaded (the "blue screen of death" bug).
|
||||||
|
|
||||||
@@ -33,15 +37,15 @@
|
|||||||
- Fixed issue of being unable to change brew metadata
|
- Fixed issue of being unable to change brew metadata
|
||||||
- Sanitized script tags-javascript typed into the editor was crashing brews
|
- Sanitized script tags-javascript typed into the editor was crashing brews
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
|
||||||
### Sunday, 08/04/2018 - v2.8.0
|
### Sunday, 08/04/2018 - v2.8.0
|
||||||
- Re-enabled box shadows for PDF output
|
- Re-enabled box shadows for PDF output
|
||||||
- Added a "contributing guide" for the GitHub
|
- Added a "contributing guide" for the GitHub
|
||||||
- "Report Issue" navbar button now links to the subreddit
|
- "Report Issue" navbar button now links to the subreddit
|
||||||
- Refactored background code
|
- Refactored background code
|
||||||
|
|
||||||
```
|
|
||||||
```
|
|
||||||
|
|
||||||
### Sunday, 04/06/2017 - v2.7.5
|
### Sunday, 04/06/2017 - v2.7.5
|
||||||
- Fixed the class feature snippet duplicating the entire brew
|
- Fixed the class feature snippet duplicating the entire brew
|
||||||
- Fixed headers in tables being duplicated
|
- Fixed headers in tables being duplicated
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
font-family : ScalySans;
|
font-family : ScalySans;
|
||||||
font-size : 1.2em;
|
font-size : 1.2em;
|
||||||
&>span{
|
&>span{
|
||||||
margin-right : 15px;
|
margin-right : 12px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&:hover{
|
&:hover{
|
||||||
|
|||||||
@@ -22,9 +22,8 @@ const BrewItem = require('./brewItem/brewItem.jsx');
|
|||||||
const UserPage = createClass({
|
const UserPage = createClass({
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
username : '',
|
username : '',
|
||||||
brews : [],
|
brews : []
|
||||||
googleBrews : []
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "homebrewery",
|
"name": "homebrewery",
|
||||||
"version": "2.10.3",
|
"version": "2.10.4",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "homebrewery",
|
"name": "homebrewery",
|
||||||
"description": "Create authentic looking D&D homebrews using only markdown",
|
"description": "Create authentic looking D&D homebrews using only markdown",
|
||||||
"version": "2.10.3",
|
"version": "2.10.4",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "12.16.x"
|
"node": "12.16.x"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -152,6 +152,10 @@ app.get('/share/:id', (req, res, next)=>{
|
|||||||
const googleId = req.params.id.slice(0, -12);
|
const googleId = req.params.id.slice(0, -12);
|
||||||
const shareId = req.params.id.slice(-12);
|
const shareId = req.params.id.slice(-12);
|
||||||
GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, shareId, 'share')
|
GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, shareId, 'share')
|
||||||
|
.then((brew)=>{
|
||||||
|
GoogleActions.increaseView(googleId, shareId, 'share', brew);
|
||||||
|
return brew;
|
||||||
|
})
|
||||||
.then((brew)=>{
|
.then((brew)=>{
|
||||||
req.brew = brew; //TODO Need to sanitize later
|
req.brew = brew; //TODO Need to sanitize later
|
||||||
return next();
|
return next();
|
||||||
|
|||||||
@@ -87,11 +87,17 @@ GoogleActions = {
|
|||||||
|
|
||||||
oAuth2Client = GoogleActions.authCheck(req.account, res);
|
oAuth2Client = GoogleActions.authCheck(req.account, res);
|
||||||
|
|
||||||
|
//TODO: Change to service account to allow non-owners to view published files.
|
||||||
|
// Requires a driveId parameter in the drive.files.list command
|
||||||
|
// const keys = JSON.parse(config.get('service_account'));
|
||||||
|
// const auth = google.auth.fromJSON(keys);
|
||||||
|
// auth.scopes = ['https://www.googleapis.com/auth/drive'];
|
||||||
|
|
||||||
const drive = google.drive({ version: 'v3', auth: oAuth2Client });
|
const drive = google.drive({ version: 'v3', auth: oAuth2Client });
|
||||||
|
|
||||||
const obj = await drive.files.list({
|
const obj = await drive.files.list({
|
||||||
pageSize : 100,
|
pageSize : 100,
|
||||||
fields : 'nextPageToken, files(id, name, modifiedTime, properties)',
|
fields : 'nextPageToken, files(id, name, description, modifiedTime, properties)',
|
||||||
q : 'mimeType != \'application/vnd.google-apps.folder\' and trashed = false'
|
q : 'mimeType != \'application/vnd.google-apps.folder\' and trashed = false'
|
||||||
})
|
})
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
@@ -107,15 +113,16 @@ GoogleActions = {
|
|||||||
text : '',
|
text : '',
|
||||||
shareId : file.properties.shareId,
|
shareId : file.properties.shareId,
|
||||||
editId : file.properties.editId,
|
editId : file.properties.editId,
|
||||||
createdAt : null,
|
createdAt : file.createdTime,
|
||||||
updatedAt : file.modifiedTime,
|
updatedAt : file.modifiedTime,
|
||||||
gDrive : true,
|
gDrive : true,
|
||||||
googleId : file.id,
|
googleId : file.id,
|
||||||
|
|
||||||
title : file.properties.title,
|
title : file.properties.title,
|
||||||
description : '',
|
description : file.description,
|
||||||
|
views : file.properties.views,
|
||||||
tags : '',
|
tags : '',
|
||||||
published : false,
|
published : file.properties.published ? file.properties.published == 'true' : false,
|
||||||
authors : [req.account.username], //TODO: properly save and load authors to google drive
|
authors : [req.account.username], //TODO: properly save and load authors to google drive
|
||||||
systems : []
|
systems : []
|
||||||
};
|
};
|
||||||
@@ -129,6 +136,8 @@ GoogleActions = {
|
|||||||
|
|
||||||
const result = await drive.files.get({ fileId: id })
|
const result = await drive.files.get({ fileId: id })
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
|
console.log('error checking file exists...');
|
||||||
|
console.log(err);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -140,12 +149,24 @@ GoogleActions = {
|
|||||||
updateGoogleBrew : async (auth, brew)=>{
|
updateGoogleBrew : async (auth, brew)=>{
|
||||||
const drive = google.drive({ version: 'v3', auth: auth });
|
const drive = google.drive({ version: 'v3', auth: auth });
|
||||||
|
|
||||||
if(await GoogleActions.existsGoogleBrew(auth, brew.googleId) == true) {
|
console.log('trying to update a brew');
|
||||||
|
console.log(brew);
|
||||||
|
|
||||||
|
if(await GoogleActions.existsGoogleBrew(auth, brew.googleId) == true) {
|
||||||
|
console.log('the brew exists at least');
|
||||||
|
console.log('going to put this text:');
|
||||||
|
console.log(brew.text);
|
||||||
await drive.files.update({
|
await drive.files.update({
|
||||||
fileId : brew.googleId,
|
fileId : brew.googleId,
|
||||||
resource : { name : `${brew.title}.txt`,
|
resource : { name : `${brew.title}.txt`,
|
||||||
properties : { title: brew.title } //AppProperties is not accessible via API key
|
description : `${brew.description}`,
|
||||||
|
properties : { title : brew.title,
|
||||||
|
published : brew.published,
|
||||||
|
lastViewed : brew.lastViewed,
|
||||||
|
views : brew.views,
|
||||||
|
version : brew.version,
|
||||||
|
tags : brew.tags,
|
||||||
|
systems : brew.systems.join() }
|
||||||
},
|
},
|
||||||
media : { mimeType : 'text/plain',
|
media : { mimeType : 'text/plain',
|
||||||
body : brew.text }
|
body : brew.text }
|
||||||
@@ -171,12 +192,14 @@ GoogleActions = {
|
|||||||
const folderId = await GoogleActions.getGoogleFolder(auth);
|
const folderId = await GoogleActions.getGoogleFolder(auth);
|
||||||
|
|
||||||
const fileMetadata = {
|
const fileMetadata = {
|
||||||
'name' : `${brew.title}.txt`,
|
'name' : `${brew.title}.txt`,
|
||||||
'parents' : [folderId],
|
'description' : `${brew.description}`,
|
||||||
'properties' : { //AppProperties is not accessible
|
'parents' : [folderId],
|
||||||
|
'properties' : { //AppProperties is not accessible
|
||||||
'shareId' : nanoid(12),
|
'shareId' : nanoid(12),
|
||||||
'editId' : nanoid(12),
|
'editId' : nanoid(12),
|
||||||
'title' : brew.title,
|
'title' : brew.title,
|
||||||
|
'views' : '0'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -206,15 +229,15 @@ GoogleActions = {
|
|||||||
text : brew.text,
|
text : brew.text,
|
||||||
shareId : fileMetadata.properties.shareId,
|
shareId : fileMetadata.properties.shareId,
|
||||||
editId : fileMetadata.properties.editId,
|
editId : fileMetadata.properties.editId,
|
||||||
createdAt : null,
|
createdAt : new Date(),
|
||||||
updatedAt : null,
|
updatedAt : new Date(),
|
||||||
gDrive : true,
|
gDrive : true,
|
||||||
googleId : obj.data.id,
|
googleId : obj.data.id,
|
||||||
|
|
||||||
title : brew.title,
|
title : brew.title,
|
||||||
description : '',
|
description : brew.description,
|
||||||
tags : '',
|
tags : '',
|
||||||
published : false,
|
published : brew.published,
|
||||||
authors : [],
|
authors : [],
|
||||||
systems : []
|
systems : []
|
||||||
};
|
};
|
||||||
@@ -227,7 +250,7 @@ GoogleActions = {
|
|||||||
|
|
||||||
const obj = await drive.files.get({
|
const obj = await drive.files.get({
|
||||||
fileId : id,
|
fileId : id,
|
||||||
fields : 'properties'
|
fields : 'properties, createdTime, modifiedTime, description'
|
||||||
})
|
})
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.log('Error loading from Google');
|
console.log('Error loading from Google');
|
||||||
@@ -244,6 +267,7 @@ GoogleActions = {
|
|||||||
|
|
||||||
const file = await drive.files.get({
|
const file = await drive.files.get({
|
||||||
fileId : id,
|
fileId : id,
|
||||||
|
fields : 'description, properties',
|
||||||
alt : 'media'
|
alt : 'media'
|
||||||
})
|
})
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
@@ -252,20 +276,25 @@ GoogleActions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const brew = {
|
const brew = {
|
||||||
text : file.data,
|
shareId : obj.data.properties.shareId,
|
||||||
shareId : obj.data.properties.shareId,
|
editId : obj.data.properties.editId,
|
||||||
editId : obj.data.properties.editId,
|
title : obj.data.properties.title,
|
||||||
createdAt : null,
|
text : file.data,
|
||||||
updatedAt : null,
|
|
||||||
gDrive : true,
|
|
||||||
googleId : id,
|
|
||||||
|
|
||||||
title : obj.data.properties.title,
|
description : obj.data.description,
|
||||||
description : '',
|
tags : obj.data.properties.tags ? obj.data.properties.tags.split(',') : [],
|
||||||
tags : '',
|
systems : obj.data.properties.systems ? obj.data.properties.systems.split(',') : [],
|
||||||
published : false,
|
|
||||||
authors : [],
|
authors : [],
|
||||||
systems : []
|
published : obj.data.properties.published ? obj.data.properties.published == 'true' : false,
|
||||||
|
|
||||||
|
createdAt : obj.data.createdTime,
|
||||||
|
updatedAt : obj.data.modifiedTime,
|
||||||
|
lastViewed : obj.data.properties.lastViewed,
|
||||||
|
views : parseInt(obj.data.properties.views) || 0, //brews with no view parameter will return undefined
|
||||||
|
version : parseInt(obj.data.properties.version) || 0,
|
||||||
|
|
||||||
|
gDrive : true,
|
||||||
|
googleId : id
|
||||||
};
|
};
|
||||||
|
|
||||||
return (brew);
|
return (brew);
|
||||||
@@ -303,6 +332,29 @@ GoogleActions = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return res.status(200).send();
|
return res.status(200).send();
|
||||||
|
},
|
||||||
|
|
||||||
|
increaseView : async (id, accessId, accessType, brew)=>{
|
||||||
|
//service account because this is modifying another user's file properties
|
||||||
|
//so we need extended scope
|
||||||
|
const keys = JSON.parse(config.get('service_account'));
|
||||||
|
const auth = google.auth.fromJSON(keys);
|
||||||
|
auth.scopes = ['https://www.googleapis.com/auth/drive'];
|
||||||
|
|
||||||
|
const drive = google.drive({ version: 'v3', auth: auth });
|
||||||
|
|
||||||
|
await drive.files.update({
|
||||||
|
fileId : brew.googleId,
|
||||||
|
resource : { properties : { views : brew.views + 1,
|
||||||
|
lastViewed : new Date() } }
|
||||||
|
})
|
||||||
|
.catch((err)=>{
|
||||||
|
console.log('Error updating Google views');
|
||||||
|
console.error(err);
|
||||||
|
//return res.status(500).send('Error while saving');
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user