mirror of https://github.com/sgoudham/carbon.git
Remove semicolons
parent
7e69ca2897
commit
3cbcb49c27
@ -1,4 +1,5 @@
|
||||
{
|
||||
singleQuote: true,
|
||||
printWidth: 100
|
||||
printWidth: 100,
|
||||
semi: false
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,46 +1,46 @@
|
||||
const Twitter = require('twitter');
|
||||
const morph = require('morphmorph');
|
||||
const Twitter = require('twitter')
|
||||
const morph = require('morphmorph')
|
||||
|
||||
const RATE_LIMIT_CODE = 420;
|
||||
const RATE_LIMIT_CODE = 420
|
||||
|
||||
const client = new Twitter({
|
||||
consumer_key: process.env.TWITTER_CONSUMER_KEY,
|
||||
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
|
||||
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
|
||||
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
|
||||
});
|
||||
})
|
||||
|
||||
const uploadImage = data => client.post('media/upload', { media_data: data });
|
||||
const uploadImage = data => client.post('media/upload', { media_data: data })
|
||||
const uploadTweet = (media = {}) =>
|
||||
client.post('statuses/update', {
|
||||
status: `Carbon Copy #${media.media_id_string.slice(0, 8)}`,
|
||||
media_ids: media.media_id_string
|
||||
});
|
||||
})
|
||||
|
||||
const extractImageUrl = morph.get('entities.media.0.display_url');
|
||||
const extractErrorCode = morph.get('0.code');
|
||||
const extractImageUrl = morph.get('entities.media.0.display_url')
|
||||
const extractErrorCode = morph.get('0.code')
|
||||
|
||||
const respondSuccess = (res, url) => res.json({ url });
|
||||
const respondSuccess = (res, url) => res.json({ url })
|
||||
const respondFail = (res, err) => {
|
||||
const errorCode = extractErrorCode(err);
|
||||
const errorCode = extractErrorCode(err)
|
||||
|
||||
// check for rate limit
|
||||
if (errorCode === RATE_LIMIT_CODE) {
|
||||
return res.status(420).send();
|
||||
return res.status(420).send()
|
||||
}
|
||||
|
||||
console.error(`Error: ${err.message || JSON.stringify(err, null, 2)}`);
|
||||
res.status(500).send();
|
||||
};
|
||||
console.error(`Error: ${err.message || JSON.stringify(err, null, 2)}`)
|
||||
res.status(500).send()
|
||||
}
|
||||
|
||||
module.exports = (req, res) => {
|
||||
if (!req.body.data) {
|
||||
return res.status(400).send();
|
||||
return res.status(400).send()
|
||||
}
|
||||
|
||||
uploadImage(req.body.data)
|
||||
.then(uploadTweet)
|
||||
.then(extractImageUrl)
|
||||
.then(respondSuccess.bind(null, res))
|
||||
.catch(respondFail.bind(null, res));
|
||||
};
|
||||
.catch(respondFail.bind(null, res))
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
import Editor from './editor';
|
||||
export default Editor;
|
||||
import Editor from './editor'
|
||||
export default Editor
|
||||
|
@ -1,38 +1,38 @@
|
||||
const express = require('express');
|
||||
const morgan = require('morgan');
|
||||
const bodyParser = require('body-parser');
|
||||
const next = require('next');
|
||||
const express = require('express')
|
||||
const morgan = require('morgan')
|
||||
const bodyParser = require('body-parser')
|
||||
const next = require('next')
|
||||
|
||||
const port = parseInt(process.env.PORT, 10) || 3000;
|
||||
const dev = process.env.NODE_ENV !== 'production' && !process.env.NOW;
|
||||
const app = next({ dev });
|
||||
const handle = app.getRequestHandler();
|
||||
const port = parseInt(process.env.PORT, 10) || 3000
|
||||
const dev = process.env.NODE_ENV !== 'production' && !process.env.NOW
|
||||
const app = next({ dev })
|
||||
const handle = app.getRequestHandler()
|
||||
|
||||
function wrap(handler) {
|
||||
return (req, res) =>
|
||||
handler(req, res).catch(err => {
|
||||
console.log('ERR:', err);
|
||||
});
|
||||
console.log('ERR:', err)
|
||||
})
|
||||
}
|
||||
|
||||
app.prepare().then(() => {
|
||||
const server = express();
|
||||
const server = express()
|
||||
|
||||
server.use(morgan('tiny'));
|
||||
server.use(morgan('tiny'))
|
||||
|
||||
server.get('/about', (req, res) => app.render(req, res, '/about'));
|
||||
server.get('/about', (req, res) => app.render(req, res, '/about'))
|
||||
|
||||
// if root, render webpage from next
|
||||
server.get('/*', (req, res) => app.render(req, res, '/', req.query));
|
||||
server.get('/*', (req, res) => app.render(req, res, '/', req.query))
|
||||
|
||||
// otherwise, try and get gist
|
||||
server.get('*', handle);
|
||||
server.get('*', handle)
|
||||
|
||||
// api endpoints
|
||||
server.post('/twitter', bodyParser.json({ limit: '5mb' }), require('./handlers/twitter'));
|
||||
server.post('/twitter', bodyParser.json({ limit: '5mb' }), require('./handlers/twitter'))
|
||||
|
||||
server.listen(port, err => {
|
||||
if (err) throw err;
|
||||
console.log(`> Ready on http://localhost:${port}`);
|
||||
});
|
||||
});
|
||||
if (err) throw err
|
||||
console.log(`> Ready on http://localhost:${port}`)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue