0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-05 21:02:43 +00:00

Prefix loading successfully from config/local.json for both Homebrewery and Google brews.

Concats switched to string literals to make Linter happy.
This commit is contained in:
G.Ambatte
2021-01-29 22:53:58 +13:00
parent 051773a084
commit c3bfd1e8bf
2 changed files with 12 additions and 7 deletions

View File

@@ -111,14 +111,15 @@ app.get('/source/:id', (req, res)=>{
//Download brew source page //Download brew source page
app.get('/download/:id', (req, res)=>{ app.get('/download/:id', (req, res)=>{
const prefix = config.get('filename-prefix'); const prefix = config.get('name_prefix');
if(req.params.id.length > 12) { if(req.params.id.length > 12) {
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)=>{ .then((brew)=>{
let fileName = sanitizeFilename(prefix + title).replaceAll(' ', '-'); let fileName = sanitizeFilename(`${prefix}${brew.title}`).replaceAll(' ', '');
if(!title || !title.length) { fileName = prefix + 'Untitled-Brew'; }; if(!fileName || !fileName.length) { fileName = `${prefix}-Untitled-Brew`; };
res.set({ res.set({
'Cache-Control' : 'no-cache', 'Cache-Control' : 'no-cache',
'Content-Type' : 'text/plain', 'Content-Type' : 'text/plain',
@@ -133,9 +134,8 @@ app.get('/download/:id', (req, res)=>{
} else { } else {
HomebrewModel.get({ shareId: req.params.id }) HomebrewModel.get({ shareId: req.params.id })
.then((brew)=>{ .then((brew)=>{
let fileName = sanitizeFilename(prefix + title).replaceAll(' ', '-'); let fileName = sanitizeFilename(`${prefix}${brew.title}`).replaceAll(' ', '');
console.log(title); if(!fileName || !fileName.length) { fileName = `${prefix}-Untitled-Brew`; };
if(!title || !title.length) { fileName = prefix + 'Untitled-Brew'; };
res.set({ res.set({
'Cache-Control' : 'no-cache', 'Cache-Control' : 'no-cache',
'Content-Type' : 'text/plain', 'Content-Type' : 'text/plain',

View File

@@ -258,7 +258,12 @@ GoogleActions = {
} }
//Access actual file with service account. Just api key is causing "automated query" errors. //Access actual file with service account. Just api key is causing "automated query" errors.
const keys = JSON.parse(config.get('service_account'));
const actionList = {
'string' : function() { return JSON.parse(config.get('service_account')); },
'object' : function() { return config.get('service_account'); }
};
const keys = actionList[typeof(config.get('service_account'))]();
const serviceAuth = google.auth.fromJSON(keys); const serviceAuth = google.auth.fromJSON(keys);
serviceAuth.scopes = ['https://www.googleapis.com/auth/drive']; serviceAuth.scopes = ['https://www.googleapis.com/auth/drive'];