diff --git a/server.js b/server.js index 0bb5e55a7..ac3f160e2 100644 --- a/server.js +++ b/server.js @@ -111,14 +111,15 @@ app.get('/source/:id', (req, res)=>{ //Download brew source page app.get('/download/:id', (req, res)=>{ - const prefix = config.get('filename-prefix'); + const prefix = config.get('name_prefix'); + if(req.params.id.length > 12) { const googleId = req.params.id.slice(0, -12); const shareId = req.params.id.slice(-12); GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, shareId, 'share') .then((brew)=>{ - let fileName = sanitizeFilename(prefix + title).replaceAll(' ', '-'); - if(!title || !title.length) { fileName = prefix + 'Untitled-Brew'; }; + let fileName = sanitizeFilename(`${prefix}${brew.title}`).replaceAll(' ', ''); + if(!fileName || !fileName.length) { fileName = `${prefix}-Untitled-Brew`; }; res.set({ 'Cache-Control' : 'no-cache', 'Content-Type' : 'text/plain', @@ -133,9 +134,8 @@ app.get('/download/:id', (req, res)=>{ } else { HomebrewModel.get({ shareId: req.params.id }) .then((brew)=>{ - let fileName = sanitizeFilename(prefix + title).replaceAll(' ', '-'); - console.log(title); - if(!title || !title.length) { fileName = prefix + 'Untitled-Brew'; }; + let fileName = sanitizeFilename(`${prefix}${brew.title}`).replaceAll(' ', ''); + if(!fileName || !fileName.length) { fileName = `${prefix}-Untitled-Brew`; }; res.set({ 'Cache-Control' : 'no-cache', 'Content-Type' : 'text/plain', diff --git a/server/googleActions.js b/server/googleActions.js index 1fc93a861..2473561a1 100644 --- a/server/googleActions.js +++ b/server/googleActions.js @@ -258,7 +258,12 @@ GoogleActions = { } //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); serviceAuth.scopes = ['https://www.googleapis.com/auth/drive'];