UNPKG

cky-image-public

Version:

public image to public host

83 lines (72 loc) 2.06 kB
const fs = require("fs"); const request = require('request').defaults({ headers: { Origin: 'https://www.dropshots.com', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36', 'Content-Type': 'multipart/form-data', 'Accept': 'text/plain, */*; q=0.01', 'X-Requested-With': 'XMLHttpRequest', Connection: 'keep-alive', DNT: 1 } }) let helper = require('../helper'); class Dropshots { constructor (options = {}) { let { user_name } = options; this.user_name = user_name; } upload (imgPath, callback) { if (!this.user_name) return callback('ENOUSERNAME', 'Invalid User name'); request({ url: 'https://www.dropshots.com/uploadie.php', method: 'POST', headers: { Referer: `https://www.dropshots.com/${this.user_name}` }, formData: { albumid: '', photo_limit: 0, video_limit: 0, username: this.user_name, sid: '', file0: { value: fs.createReadStream(imgPath), options: { filename: imgPath, contentType: 'image/jpeg' } }, } }, (err, response, body) => { if (err) return callback('EUPLOAD', err); this.getMedia(callback); }); } getMedia (callback) { if (!this.user_name) return callback(null, null); let options = { url: 'https://www.dropshots.com/V1.0/Media.getRecentMedia', method: 'GET', headers: { Referer: `https://www.dropshots.com/${this.user_name}` }, qs: { appid: 'dropshots', username: this.user_name, mediatype: 'photo', passwordprotection: false, page: 1, per_page: 1, tag: 'cover', output: 'json' } } request(options, (err, response, body) => { if (err || !body) return callback(null); body = helper.safeParse(body); return callback(null, body); }); } } module.exports = Dropshots;