Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Random Pigtails Girl

node v10.24.1
version: 1.0.0
endpointsharetweet
const _ = require("lodash") const PHOTOS = [ 'https://i.loli.net/2019/06/21/5d0bb066cb89643361.jpg', 'https://i.loli.net/2019/06/21/5d0bb0dcc1e9522500.jpg', 'https://i.loli.net/2019/06/21/5d0bb102ea81522007.jpg', 'https://i.loli.net/2019/06/21/5d0bb1191de8d45768.jpg', 'https://i.loli.net/2019/06/21/5d0bb17bc26d315307.jpg', 'https://i.loli.net/2019/06/21/5d0bb1d15ee9c48959.jpg', ] const PICTURES = [ 'https://i.loli.net/2019/06/21/5d0bb088aaa0c31763.jpg', 'https://i.loli.net/2019/06/21/5d0bb0acd6b7652477.jpg', 'https://i.loli.net/2019/06/21/5d0bb0ca48d4875411.jpg', 'https://i.loli.net/2019/06/21/5d0bb2053ec1e35729.jpg', 'https://i.loli.net/2019/06/21/5d0bb21e60c9963628.jpg', 'https://i.loli.net/2019/06/21/5d0bb23d5796c15065.jpg', ] const GALLERYS = { PHOTOS, PICTURES } exports.endpoint = function(request, response) { const gallery = _.sample(GALLERYS) const url = _.sample(gallery) const { query } = require('url').parse(request.url, true) const format = _.get(query, 'format', 'img') if (format === 'json') { response.setHeader('Content-Type', 'application/json') response.end(JSON.stringify({ url })) } else if (format === 'text') { response.setHeader('Content-Type', 'text/plain') response.end(url) } else if (format === 'img') { response.writeHead(301, { Location: url }) response.end() } else if (format === 'html') { response.setHeader('Content-Type', 'text/html') response.end(`<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style type="text/css"> img { max-width: 100%; } </style> </head> <body> <img src="${url}"/> </body> </html> `) } }
Loading…

no comments

    sign in to comment