Added readme and index support

This commit is contained in:
Marcus Noble 2018-01-14 13:25:32 +00:00
parent 62e3714ecc
commit 6189d708ce
3 changed files with 68 additions and 0 deletions

43
README.md Normal file
View File

@ -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:
```
<img src="https://twitter-profile-pic.jsoxford.com/marcus_noble_?size=normal" />
```
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"
}
```

View File

@ -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(`
<html>
<head>
<title>Twitter-Profile-Pic</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css" />
<style>
.markdown-body { min-width: 200px;max-width: 980px;margin: 0 auto;padding: 45px; }
@media (max-width: 767px) {
.markdown-body { padding: 15px; }
}
</style>
</head>
<body class="markdown-body">
${md.makeHtml(data)}
</body>
`);
});
});
server.get('/:handle', async function (req, res) {
if (!req.params.handle) {
return res.send(400);

View File

@ -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": {