kyuurzy

AceImg Uploader

Dec 22nd, 2025
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.11 KB | Source Code | 0 0
  1. // upload.js
  2. const fs = require('fs').promises;
  3. const crypto = require('crypto');
  4.  
  5. class AceImageUploader {
  6.     constructor() {
  7.         this.baseUrl = 'https://api.aceimg.com/api/upload';
  8.         this.cdnBaseUrl = 'https://cdn.aceimg.com';
  9.     }
  10.  
  11.     generateVisitorId() {
  12.         return crypto.randomUUID();
  13.     }
  14.  
  15.     extractFileName(link) {
  16.         const match = link.match(/f=([^&]+)/);
  17.         return match ? match[1] : null;
  18.     }
  19.  
  20.     async uploadImage(filePath) {
  21.         const fileData = await fs.readFile(filePath);
  22.         const fileName = crypto.randomBytes(8).toString('hex') + '.jpg';
  23.         const visitorId = this.generateVisitorId();
  24.        
  25.         const boundary = '----WebKitFormBoundary' + crypto.randomBytes(16).toString('hex');
  26.        
  27.         const body = Buffer.concat([
  28.             Buffer.from(`--${boundary}\r\n`),
  29.             Buffer.from(`Content-Disposition: form-data; name="file"; filename="${fileName}"\r\n`),
  30.             Buffer.from(`Content-Type: image/jpeg\r\n\r\n`),
  31.             fileData,
  32.             Buffer.from(`\r\n--${boundary}--\r\n`)
  33.         ]);
  34.  
  35.         const headers = {
  36.             'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Mobile Safari/537.36',
  37.             'Content-Type': `multipart/form-data; boundary=${boundary}`
  38.         };
  39.  
  40.         const url = `${this.baseUrl}?visitorId=${visitorId}`;
  41.  
  42.         try {
  43.             const response = await fetch(url, {
  44.                 method: 'POST',
  45.                 headers: headers,
  46.                 body: body
  47.             });
  48.  
  49.             const result = await response.json();
  50.            
  51.             if (result.status && result.link) {
  52.                 const fileName = this.extractFileName(result.link);
  53.                 if (fileName) {
  54.                     result.cdnUrl = `${this.cdnBaseUrl}/${fileName}`;
  55.                 }
  56.             }
  57.            
  58.             return result;
  59.            
  60.         } catch (error) {
  61.             return {
  62.                 status: false,
  63.                 error: error.message
  64.             };
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment