mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 20:42:43 +00:00
Initial commit
This commit is contained in:
@@ -60,7 +60,10 @@ const SharePage = createClass({
|
||||
<Nav.section>
|
||||
<PrintLink shareId={this.processShareId()} />
|
||||
<Nav.item href={`/source/${this.processShareId()}`} color='teal' icon='fa-code'>
|
||||
source
|
||||
view source
|
||||
</Nav.item>
|
||||
<Nav.item href={`/source_dl/${this.processShareId()}`} color='teal' icon='fa-download'>
|
||||
download source
|
||||
</Nav.item>
|
||||
<RecentNavItem brew={this.props.brew} storageKey='view' />
|
||||
<Account />
|
||||
|
||||
49
server.js
49
server.js
@@ -76,7 +76,7 @@ app.get('/source/:id', (req, res)=>{
|
||||
GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, shareId, 'share')
|
||||
.then((brew)=>{
|
||||
const text = brew.text.replaceAll('<', '<').replaceAll('>', '>');
|
||||
return res.send(`<code><pre style="white-space: pre-wrap;">${text}</pre></code>`);
|
||||
return res.status(200).send(`<code><pre style="white-space: pre-wrap;">${text}</pre></code>`);
|
||||
})
|
||||
.catch((err)=>{
|
||||
console.log(err);
|
||||
@@ -86,7 +86,52 @@ app.get('/source/:id', (req, res)=>{
|
||||
HomebrewModel.get({ shareId: req.params.id })
|
||||
.then((brew)=>{
|
||||
const text = brew.text.replaceAll('<', '<').replaceAll('>', '>');
|
||||
return res.send(`<code><pre style="white-space: pre-wrap;">${text}</pre></code>`);
|
||||
return res.status(200).send(`<code><pre style="white-space: pre-wrap;">${text}</pre></code>`);
|
||||
})
|
||||
.catch((err)=>{
|
||||
console.log(err);
|
||||
return res.status(404).send('Could not find Homebrew with that id');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//Source download page
|
||||
app.get('/source_dl/:id', (req, res)=>{
|
||||
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);
|
||||
})
|
||||
.catch((err)=>{
|
||||
console.log(err);
|
||||
return res.status(400).send('Can\'t get brew from Google');
|
||||
});
|
||||
} 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);
|
||||
|
||||
Reference in New Issue
Block a user