mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-09 22:22:41 +00:00
Fix Share links
This commit is contained in:
@@ -290,6 +290,12 @@ const EditPage = createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
processShareId : function() {
|
||||||
|
return this.state.brew.googleId ?
|
||||||
|
this.state.brew.googleId + this.state.brew.shareId :
|
||||||
|
this.state.brew.shareId;
|
||||||
|
},
|
||||||
|
|
||||||
renderNavbar : function(){
|
renderNavbar : function(){
|
||||||
return <Navbar>
|
return <Navbar>
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
@@ -300,10 +306,10 @@ const EditPage = createClass({
|
|||||||
{this.renderGoogleDriveIcon()}
|
{this.renderGoogleDriveIcon()}
|
||||||
{this.renderSaveButton()}
|
{this.renderSaveButton()}
|
||||||
<ReportIssue />
|
<ReportIssue />
|
||||||
<Nav.item newTab={true} href={`/share/${this.props.brew.shareId}`} color='teal' icon='fa-share-alt'>
|
<Nav.item newTab={true} href={`/share/${this.processShareId()}`} color='teal' icon='fa-share-alt'>
|
||||||
Share
|
Share
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
<PrintLink shareId={this.props.brew.shareId} />
|
<PrintLink shareId={this.processShareId()} />
|
||||||
<RecentNavItem brew={this.props.brew} storageKey='edit' />
|
<RecentNavItem brew={this.props.brew} storageKey='edit' />
|
||||||
<Account />
|
<Account />
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
|
|||||||
@@ -45,15 +45,10 @@ const SharePage = createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
renderSourceButton : function() {
|
processShareId : function() {
|
||||||
let shareLink = this.props.brew.shareId;
|
return this.props.brew.googleId ?
|
||||||
if(this.props.brew.googleId) {
|
this.props.brew.googleId + this.props.brew.shareId :
|
||||||
shareLink = this.props.brew.googleId + shareLink;
|
this.props.brew.shareId;
|
||||||
}
|
|
||||||
|
|
||||||
return <Nav.item href={`/source/${shareLink}`} color='teal' icon='fa-code'>
|
|
||||||
source
|
|
||||||
</Nav.item>;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
@@ -65,8 +60,10 @@ const SharePage = createClass({
|
|||||||
</Nav.section>
|
</Nav.section>
|
||||||
|
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
<PrintLink shareId={this.props.brew.shareId} />
|
<PrintLink shareId={this.processShareId()} />
|
||||||
{this.renderSourceButton()}
|
<Nav.item href={`/source/${this.processShareId()}`} color='teal' icon='fa-code'>
|
||||||
|
source
|
||||||
|
</Nav.item>
|
||||||
<RecentNavItem brew={this.props.brew} storageKey='view' />
|
<RecentNavItem brew={this.props.brew} storageKey='view' />
|
||||||
<Account />
|
<Account />
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
|
|||||||
24
server.js
24
server.js
@@ -174,15 +174,33 @@ app.get('/share/:id', (req, res, next)=>{
|
|||||||
|
|
||||||
//Print Page
|
//Print Page
|
||||||
app.get('/print/:id', (req, res, next)=>{
|
app.get('/print/:id', (req, res, next)=>{
|
||||||
HomebrewModel.get({ shareId: req.params.id })
|
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)=>{
|
.then((brew)=>{
|
||||||
req.brew = brew.sanatize(true);
|
req.brew = brew; //TODO Need to sanitize later
|
||||||
return next();
|
return next();
|
||||||
})
|
})
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return res.status(400).send(`Can't get that`);
|
return res.status(400).send('Can\'t get brew from Google');
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
HomebrewModel.get({ shareId: req.params.id })
|
||||||
|
.then((brew)=>{
|
||||||
|
req.brew = brew.sanatize(true);
|
||||||
|
return next();
|
||||||
|
})
|
||||||
|
.catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return res.status(400).send(`Can't get that`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/source/:id', (req, res)=>{
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user