WILDAN_IZZUDIN

[JS] REMINI

Sep 12th, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require('axios')
  2. const FormData = require('form-data')
  3. const md5 = require('md5')
  4.  
  5. class Utils {
  6.    constructor(token) {
  7.       this.creator = `@neoxr.js - Wildan Izzudin`
  8.       this.token = token
  9.    }
  10.  
  11.    binary = async i => {
  12.       try {
  13.          return await (await axios.get(i, {
  14.             responseType: 'arraybuffer'
  15.          })).data
  16.       } catch (e) {
  17.          return Buffer.alloc(0)
  18.       }
  19.    }
  20.  
  21.    // hash = () => {
  22.    //    const type = JSON.stringify({ "alg": "HS256", "typ": "JWT" })
  23.    //    const now = new Date()
  24.    //    const data = JSON.stringify({ "id": md5(now), "iat": now, "exp": now.setMinutes(now.getMinutes() + 1) })
  25.    //    const salt = 'rvnj23B6brYe_XgCEZcP2JElppBPYDXbnI_Q2LX93xs'
  26.    //    return Buffer.from(`${type}.${data}.${salt}`).toString('base64').replace(/=/g, '')
  27.    // }
  28. }
  29.  
  30. class Remini extends Utils {
  31.    constructor() {
  32.       super()
  33.    }
  34.  
  35.    upload = async (url, options = {}) => {
  36.       try {
  37.          const form = new FormData
  38.          form.append('image', await this.binary(url), 'image.jpg')
  39.          const json = await (await axios.post('https://api.pixcleaner.com/v2/image?relatedTo=%2Fimage-enhance', form, {
  40.             headers: {
  41.                ...form.getHeaders(),
  42.                'x-auth-token': this.token,
  43.                ...options
  44.             }
  45.          })).data
  46.          return {
  47.             creator: this.creator,
  48.             status: true,
  49.             data: json
  50.          }
  51.       } catch (e) {
  52.          return {
  53.             creator: this.creator,
  54.             status: false,
  55.             msg: e.response.data
  56.          }
  57.       }
  58.    }
  59.  
  60.    upscale = async (url, scale = 2, options = {}) => {
  61.       try {
  62.          const fn = await this.upload(url, options)
  63.          if (!fn.status) return fn
  64.          const json = await (await axios.post('https://api.pixcleaner.com/v2/upscale', {
  65.             id: json.data.id,
  66.             mode: 'SCALE_BY',
  67.             scale,
  68.             width: fn.data.originalImage.width,
  69.             height: fn.data.originalImage.height
  70.          }, {
  71.             headers: {
  72.                'x-auth-token': this.token,
  73.                ...options
  74.             }
  75.          })).data
  76.          return {
  77.             creator: this.creator,
  78.             status: true,
  79.             data: json
  80.          }
  81.       } catch (e) {
  82.          return {
  83.             creator: this.creator,
  84.             status: false,
  85.             msg: e.response.data
  86.          }
  87.       }
  88.    }
  89. }
  90.  
  91. const remini = new Remini('YOUR_TOKEN')
  92. remini.upscale('https://cdn.pixcleaner.com/assets/women_multioclor_background.jpg?d=400').then(console.log)
Add Comment
Please, Sign In to add comment