From 6189d708ce08fded717dbafc05080cddd487944c Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Sun, 14 Jan 2018 13:25:32 +0000 Subject: [PATCH] Added readme and index support --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ index.js | 24 ++++++++++++++++++++++++ package.json | 1 + 3 files changed, 68 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..daa5b64 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# [Twitter-Profile-Pic](https://github.com/AverageMarcus/TwitterProfilePic) + +> Get a twitter profile pic using a given handle + +> Live at: [https://twitter-profile-pic.marcusnoble.co.uk/](https://twitter-profile-pic.marcusnoble.co.uk/) + +## Features + +* Multiple image size support (currently supported: `normal`, `bigger`, `mini`, `original`, `200x200`, `400x400`) +* JSON support using `application/json` content type header +* Returns a default profile pic for unknown users + +## Example: HTML + +Code: +``` + +``` +Result: + +![](https://twitter-profile-pic.jsoxford.com/marcus_noble_?size=normal) + +## Example: JSON +cURL Request: +``` +curl -X GET \ + https://twitter-profile-pic.marcusnoble.co.uk/marcus_noble_ \ + -H 'cache-control: no-cache' \ + -H 'content-type: application/json' \ + -H 'postman-token: 680d968e-9b13-85c8-f7d5-9b48a333702f' +``` + +Result: +``` +{ + "normal": "https://pbs.twimg.com/profile_images/776738772759277569/hfaM5zhA_normal.jpg", + "bigger": "https://pbs.twimg.com/profile_images/776738772759277569/hfaM5zhA_bigger.jpg", + "mini": "https://pbs.twimg.com/profile_images/776738772759277569/hfaM5zhA_mini.jpg", + "original": "https://pbs.twimg.com/profile_images/776738772759277569/hfaM5zhA.jpg", + "200x200": "https://pbs.twimg.com/profile_images/776738772759277569/hfaM5zhA_200x200.jpg", + "400x400": "https://pbs.twimg.com/profile_images/776738772759277569/hfaM5zhA_400x400.jpg" +} +``` diff --git a/index.js b/index.js index 53dd817..cb3d1a6 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,9 @@ const request = require('request'); const restify = require('restify'); const server = restify.createServer(); const Twitter = require('./twitter'); +const fs = require('fs'); +const showdown = require('showdown'); +const md = new showdown.Converter(); const handleResponse = (profileURLs, req, res) => { if (req.getContentType() === 'application/json') { @@ -21,6 +24,27 @@ const handleResponse = (profileURLs, req, res) => { server.use(restify.plugins.queryParser()); +server.get(/(\/|\/index.html)$/, function(req, res) { + fs.readFile(`${__dirname}/README.md`, { encoding: 'utf8' }, (err, data) => { + return res.sendRaw(` + + + Twitter-Profile-Pic + + + + + ${md.makeHtml(data)} + + `); + }); +}); + server.get('/:handle', async function (req, res) { if (!req.params.handle) { return res.send(400); diff --git a/package.json b/package.json index b05fcfe..c798d32 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "request": "^2.83.0", "restify": "^6.3.4", "restify-clients": "^1.5.2", + "showdown": "^1.8.6", "twitter": "^1.7.1" }, "devDependencies": {