mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-26 20:22:42 +00:00
Unwinding refactored code + corrections.
This commit is contained in:
@@ -65,7 +65,7 @@ const BrewItem = createClass({
|
||||
</a>;
|
||||
},
|
||||
|
||||
renderSourceLink : function(){
|
||||
renderShareLink : function(){
|
||||
if(!this.props.brew.shareId) return;
|
||||
|
||||
let shareLink = this.props.brew.shareId;
|
||||
@@ -74,7 +74,7 @@ const BrewItem = createClass({
|
||||
}
|
||||
|
||||
return <a href={`/share/${shareLink}`} target='_blank' rel='noopener noreferrer'>
|
||||
<i className={'fa fa-share-alt' />
|
||||
<i className='fa fa-share-alt' />
|
||||
</a>;
|
||||
},
|
||||
|
||||
@@ -87,7 +87,7 @@ const BrewItem = createClass({
|
||||
}
|
||||
|
||||
return <a href={`/download/${shareLink}`}>
|
||||
<i className={'fa fa-download' />
|
||||
<i className='fa fa-download' />
|
||||
</a>;
|
||||
},
|
||||
|
||||
|
||||
22
server.js
22
server.js
@@ -78,9 +78,9 @@ app.get('/source/:id', (req, res)=>{
|
||||
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)=>{
|
||||
.then((brew)=>{
|
||||
const replaceStrings = { '&': '&', '<': '<', '>': '>' };
|
||||
const text = brew.text;
|
||||
var text = brew.text;
|
||||
for (const replaceStr in replaceStrings) {
|
||||
text = text.replaceAll(replaceStr, replaceStrings[replaceStr]);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ app.get('/source/:id', (req, res)=>{
|
||||
HomebrewModel.get({ shareId: req.params.id })
|
||||
.then((brew)=>{
|
||||
const replaceStrings = { '&': '&', '<': '<', '>': '>' };
|
||||
const text = brew.text;
|
||||
var text = brew.text;
|
||||
for (const replaceStr in replaceStrings) {
|
||||
text = text.replaceAll(replaceStr, replaceStrings[replaceStr]);
|
||||
}
|
||||
@@ -116,14 +116,14 @@ app.get('/download/:id', (req, res)=>{
|
||||
const shareId = req.params.id.slice(-12);
|
||||
GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, shareId, 'share')
|
||||
.then((brew)=>{
|
||||
const fileName = sanitizeFilename(title).replaceAll(' ', '-');
|
||||
if (!fileName || !fileName.length) { fileName = 'Untitled-Brew'; };
|
||||
var fileName = sanitizeFilename(title).replaceAll(' ', '-');
|
||||
if(!fileName || !fileName.length) { fileName = 'Untitled-Brew'; };
|
||||
res.set({
|
||||
'Cache-Control' : 'no-cache',
|
||||
'Content-Type' : 'text/plain',
|
||||
'Content-Disposition' : `attachment; filename="HomeBrewery-${fileName}.txt"`
|
||||
});
|
||||
res.status(200).send(getSourceText(brew.text, type));
|
||||
res.status(200).send(brew.text);
|
||||
})
|
||||
.catch((err)=>{
|
||||
console.log(err);
|
||||
@@ -132,8 +132,14 @@ app.get('/download/:id', (req, res)=>{
|
||||
} else {
|
||||
HomebrewModel.get({ shareId: req.params.id })
|
||||
.then((brew)=>{
|
||||
setSourceHeaders(res, brew.title, type);
|
||||
res.send(getSourceText(brew.text, type));
|
||||
var fileName = sanitizeFilename(title).replaceAll(' ', '-');
|
||||
if(!fileName || !fileName.length) { fileName = 'Untitled-Brew'; };
|
||||
res.set({
|
||||
'Cache-Control' : 'no-cache',
|
||||
'Content-Type' : 'text/plain',
|
||||
'Content-Disposition' : `attachment; filename="HomeBrewery-${fileName}.txt"`
|
||||
});
|
||||
res.status(200).send(brew.text);
|
||||
})
|
||||
.catch((err)=>{
|
||||
console.log(err);
|
||||
|
||||
Reference in New Issue
Block a user