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