Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require('axios')
- const FormData = require('form-data')
- const md5 = require('md5')
- class Utils {
- constructor(token) {
- this.creator = `@neoxr.js - Wildan Izzudin`
- this.token = token
- }
- binary = async i => {
- try {
- return await (await axios.get(i, {
- responseType: 'arraybuffer'
- })).data
- } catch (e) {
- return Buffer.alloc(0)
- }
- }
- // hash = () => {
- // const type = JSON.stringify({ "alg": "HS256", "typ": "JWT" })
- // const now = new Date()
- // const data = JSON.stringify({ "id": md5(now), "iat": now, "exp": now.setMinutes(now.getMinutes() + 1) })
- // const salt = 'rvnj23B6brYe_XgCEZcP2JElppBPYDXbnI_Q2LX93xs'
- // return Buffer.from(`${type}.${data}.${salt}`).toString('base64').replace(/=/g, '')
- // }
- }
- class Remini extends Utils {
- constructor() {
- super()
- }
- upload = async (url, options = {}) => {
- try {
- const form = new FormData
- form.append('image', await this.binary(url), 'image.jpg')
- const json = await (await axios.post('https://api.pixcleaner.com/v2/image?relatedTo=%2Fimage-enhance', form, {
- headers: {
- ...form.getHeaders(),
- 'x-auth-token': this.token,
- ...options
- }
- })).data
- return {
- creator: this.creator,
- status: true,
- data: json
- }
- } catch (e) {
- return {
- creator: this.creator,
- status: false,
- msg: e.response.data
- }
- }
- }
- upscale = async (url, scale = 2, options = {}) => {
- try {
- const fn = await this.upload(url, options)
- if (!fn.status) return fn
- const json = await (await axios.post('https://api.pixcleaner.com/v2/upscale', {
- id: json.data.id,
- mode: 'SCALE_BY',
- scale,
- width: fn.data.originalImage.width,
- height: fn.data.originalImage.height
- }, {
- headers: {
- 'x-auth-token': this.token,
- ...options
- }
- })).data
- return {
- creator: this.creator,
- status: true,
- data: json
- }
- } catch (e) {
- return {
- creator: this.creator,
- status: false,
- msg: e.response.data
- }
- }
- }
- }
- const remini = new Remini('YOUR_TOKEN')
- remini.upscale('https://cdn.pixcleaner.com/assets/women_multioclor_background.jpg?d=400').then(console.log)
Add Comment
Please, Sign In to add comment