mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 17:52:47 +00:00
Merge pull request #1242 from G-Ambatte/importPage
Import from Share ID
This commit is contained in:
@@ -44,10 +44,10 @@ const Homebrew = createClass({
|
|||||||
<Switch>
|
<Switch>
|
||||||
<Route path='/edit/:id' component={(routeProps)=><EditPage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
<Route path='/edit/:id' component={(routeProps)=><EditPage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
||||||
<Route path='/share/:id' component={(routeProps)=><SharePage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
<Route path='/share/:id' component={(routeProps)=><SharePage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
||||||
|
<Route path='/new/:id' component={(routeProps)=><NewPage id={routeProps.match.params.id} brew={this.props.brew} />}/>
|
||||||
<Route path='/user/:username' component={(routeProps)=><UserPage username={routeProps.match.params.username} brews={this.props.brews} />}/>
|
<Route path='/user/:username' component={(routeProps)=><UserPage username={routeProps.match.params.username} brews={this.props.brews} />}/>
|
||||||
<Route path='/print/:id' component={(routeProps)=><PrintPage brew={this.props.brew} query={queryString.parse(routeProps.location.search)} /> } />
|
<Route path='/print/:id' component={(routeProps)=><PrintPage brew={this.props.brew} query={queryString.parse(routeProps.location.search)} /> } />
|
||||||
<Route path='/print' exact component={(routeProps)=><PrintPage query={queryString.parse(routeProps.location.search)} /> } />
|
<Route path='/print' exact component={(routeProps)=><PrintPage query={queryString.parse(routeProps.location.search)} /> } />
|
||||||
<Route path='/new' exact component={NewPage}/>
|
|
||||||
<Route path='/changelog' exact component={()=><SharePage brew={{ title: 'Changelog', text: this.props.changelog }} />}/>
|
<Route path='/changelog' exact component={()=><SharePage brew={{ title: 'Changelog', text: this.props.changelog }} />}/>
|
||||||
<Route path='/' component={()=><HomePage welcomeText={this.props.welcomeText}/>}/>
|
<Route path='/' component={()=><HomePage welcomeText={this.props.welcomeText}/>}/>
|
||||||
</Switch>
|
</Switch>
|
||||||
|
|||||||
@@ -20,10 +20,30 @@ const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
|||||||
const KEY = 'homebrewery-new';
|
const KEY = 'homebrewery-new';
|
||||||
|
|
||||||
const NewPage = createClass({
|
const NewPage = createClass({
|
||||||
|
getDefaultProps : function() {
|
||||||
|
return {
|
||||||
|
brew : {
|
||||||
|
text : '',
|
||||||
|
shareId : null,
|
||||||
|
editId : null,
|
||||||
|
createdAt : null,
|
||||||
|
updatedAt : null,
|
||||||
|
gDrive : false,
|
||||||
|
|
||||||
|
title : '',
|
||||||
|
description : '',
|
||||||
|
tags : '',
|
||||||
|
published : false,
|
||||||
|
authors : [],
|
||||||
|
systems : []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
brew : {
|
brew : {
|
||||||
text : '',
|
text : this.props.brew.text,
|
||||||
gDrive : false,
|
gDrive : false,
|
||||||
title : '',
|
title : '',
|
||||||
description : '',
|
description : '',
|
||||||
@@ -41,7 +61,7 @@ const NewPage = createClass({
|
|||||||
|
|
||||||
componentDidMount : function() {
|
componentDidMount : function() {
|
||||||
const storage = localStorage.getItem(KEY);
|
const storage = localStorage.getItem(KEY);
|
||||||
if(storage){
|
if(!this.props.brew.text && storage){
|
||||||
this.setState({
|
this.setState({
|
||||||
brew : { text: storage }
|
brew : { text: storage }
|
||||||
});
|
});
|
||||||
|
|||||||
28
server.js
28
server.js
@@ -1,3 +1,4 @@
|
|||||||
|
/*eslint max-lines: ["warn", {"max": 250, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const jwt = require('jwt-simple');
|
const jwt = require('jwt-simple');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
@@ -143,6 +144,33 @@ app.get('/edit/:id', (req, res, next)=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//New Page
|
||||||
|
app.get('/new/:id', (req, res, next)=>{
|
||||||
|
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)=>{
|
||||||
|
req.brew = brew; //TODO Need to sanitize later
|
||||||
|
return next();
|
||||||
|
})
|
||||||
|
.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)=>{
|
||||||
|
req.brew = brew;
|
||||||
|
return next();
|
||||||
|
})
|
||||||
|
.catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return res.status(400).send(`Can't get that`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Share Page
|
//Share Page
|
||||||
app.get('/share/:id', (req, res, next)=>{
|
app.get('/share/:id', (req, res, next)=>{
|
||||||
if(req.params.id.length > 12) {
|
if(req.params.id.length > 12) {
|
||||||
|
|||||||
Reference in New Issue
Block a user