diff --git a/client/homebrew/pages/sharePage/sharePage.jsx b/client/homebrew/pages/sharePage/sharePage.jsx
index 01145ec4c..9867e9dc3 100644
--- a/client/homebrew/pages/sharePage/sharePage.jsx
+++ b/client/homebrew/pages/sharePage/sharePage.jsx
@@ -62,7 +62,7 @@ const SharePage = createClass({
view source
-
+
download source
diff --git a/client/homebrew/pages/sharePage/source_dl.jsx b/client/homebrew/pages/sharePage/source_dl.jsx
new file mode 100644
index 000000000..e37ed9be4
--- /dev/null
+++ b/client/homebrew/pages/sharePage/source_dl.jsx
@@ -0,0 +1,14 @@
+const sourceDL = function(res, brew) {
+ const fileName = brew.title.replaceAll(' ', '-').replaceAll(':', '').replaceAll('/', '');
+
+ res.status(200);
+ res.set({
+ 'Cache-Control' : 'no-cache',
+ 'Content-Type' : 'text/plain',
+ 'Content-Disposition' : `attachment; filename="HomeBrewery-${fileName}.txt"`
+ });
+
+ return res;
+};
+
+module.exports = sourceDL;
\ No newline at end of file
diff --git a/server.js b/server.js
index d2de44ae5..dfd14580c 100644
--- a/server.js
+++ b/server.js
@@ -97,22 +97,14 @@ app.get('/source/:id', (req, res)=>{
//Source download page
app.get('/source_dl/:id', (req, res)=>{
+ const sourceDL = require ('./client/homebrew/pages/sharePage/source_dl.jsx');
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)=>{
- const text = brew.text.replaceAll('<', '<').replaceAll('>', '>');
- const fileName = brew.title.replaceAll(' ', '-');
-
- res.status(200);
- res.set({
- 'Cache-Control' : 'no-cache',
- 'Content-Type' : 'text/plain',
- 'Content-Disposition' : `attachment; filename="HomeBrewery-${fileName}.txt"`
- });
-
- return res.send(text);
+ res = sourceDL(res, brew);
+ return res.send(brew.text);
})
.catch((err)=>{
console.log(err);
@@ -120,23 +112,14 @@ app.get('/source_dl/:id', (req, res)=>{
});
} else {
HomebrewModel.get({ shareId: req.params.id })
- .then((brew)=>{
- const text = brew.text.replaceAll('<', '<').replaceAll('>', '>');
- const fileName = brew.title.replaceAll(' ', '-');
-
- res.status(200);
- res.set({
- 'Cache-Control' : 'no-cache',
- 'Content-Type' : 'text/plain',
- 'Content-Disposition' : `attachment; filename="HomeBrewery-${fileName}.txt"`
- });
-
- return res.send(text);
- })
- .catch((err)=>{
- console.log(err);
- return res.status(404).send('Could not find Homebrew with that id');
- });
+ .then((brew)=>{
+ res = sourceDL(res, brew);
+ return res.send(brew.text);
+ })
+ .catch((err)=>{
+ console.log(err);
+ return res.status(404).send('Could not find Homebrew with that id');
+ });
}
});