Created
December 22, 2025 15:13
-
-
Save siputzx/aa8a3dc415cbb2924498b110b6cb776c to your computer and use it in GitHub Desktop.
piscart upscale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PicsartEnhancer { | |
| constructor() { | |
| this.uploadUrl = 'https://upload.picsart.com/files'; | |
| this.aiUrl = 'https://ai.picsart.com'; | |
| this.jsUrl = 'https://picsart.com/-/landings/4.310.0/static/index-C3-HwnoW-GZgP7cLS.js'; | |
| this.token = null; | |
| this.headers = { | |
| 'origin': 'https://picsart.com', | |
| 'referer': 'https://picsart.com/', | |
| 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36', | |
| 'accept': '*/*' | |
| }; | |
| } | |
| async getToken() { | |
| const resp = await fetch(this.jsUrl, { headers: this.headers }); | |
| const text = await resp.text(); | |
| const match = text.match(/"x-app-authorization":"Bearer\s+([^"]+)"/); | |
| if (match?.[1]) { | |
| this.token = match[1]; | |
| return this.token; | |
| } | |
| throw new Error('Token not found'); | |
| } | |
| async upload(buffer) { | |
| const boundary = '----WebKitFormBoundary' + Math.random().toString(36).slice(2); | |
| let body = `--${boundary}\r\n`; | |
| body += 'Content-Disposition: form-data; name="type"\r\n\r\n'; | |
| body += 'editing-temp-landings\r\n'; | |
| body += `--${boundary}\r\n`; | |
| body += `Content-Disposition: form-data; name="file"; filename="image.jpg"\r\n`; | |
| body += `Content-Type: image/png\r\n\r\n`; | |
| const part1 = Buffer.from(body, 'utf-8'); | |
| const part2 = Buffer.from(`\r\n--${boundary}\r\nContent-Disposition: form-data; name="url"\r\n\r\n\r\n--${boundary}\r\nContent-Disposition: form-data; name="metainfo"\r\n\r\n\r\n--${boundary}--\r\n`, 'utf-8'); | |
| const data = Buffer.concat([part1, buffer, part2]); | |
| const resp = await fetch(this.uploadUrl, { | |
| method: 'POST', | |
| headers: { | |
| ...this.headers, | |
| 'content-type': `multipart/form-data; boundary=${boundary}`, | |
| 'accept': 'application/json' | |
| }, | |
| body: data | |
| }); | |
| return await resp.json(); | |
| } | |
| async enhance(url, scale) { | |
| if (!this.token) await this.getToken(); | |
| const params = new URLSearchParams({ | |
| picsart_cdn_url: url, | |
| format: 'PNG', | |
| model: 'REALESERGAN' | |
| }); | |
| const body = JSON.stringify({ | |
| image_url: url, | |
| colour_correction: { enabled: false, blending: 0.5 }, | |
| seed: 42, | |
| upscale: { enabled: true, node: 'esrgan', target_scale: scale }, | |
| face_enhancement: { | |
| enabled: true, blending: 1, max_faces: 1000, | |
| impression: false, gfpgan: true, node: 'ada' | |
| } | |
| }); | |
| const resp = await fetch(`${this.aiUrl}/gw1/diffbir-enhancement-service/v1.7.6?${params}`, { | |
| method: 'POST', | |
| headers: { | |
| ...this.headers, | |
| 'accept': 'application/json', | |
| 'content-type': 'application/json', | |
| 'platform': 'website', | |
| 'x-app-authorization': `Bearer ${this.token}`, | |
| 'x-touchpoint': 'widget_EnhancedImage', | |
| 'x-touchpoint-referrer': '/id/ai-image-enhancer/' | |
| }, | |
| body | |
| }); | |
| return await resp.json(); | |
| } | |
| async process(buffer, scale) { | |
| const upload = await this.upload(buffer); | |
| if (upload.status !== 'success') throw new Error('Upload failed'); | |
| return await this.enhance(upload.result.url, scale); | |
| } | |
| } | |
| async function contoh() { | |
| const enhancer = new PicsartEnhancer(); | |
| const fs = require('fs'); | |
| const buffer = fs.readFileSync('blur_image.png'); | |
| try { | |
| const result = await enhancer.process(buffer, 15); | |
| console.log('Hasil:', result.result); | |
| } catch (error) { | |
| console.error('Error:', error.message); | |
| } | |
| } | |
| contoh(); |
Author
siputzx
commented
Dec 22, 2025

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment