wibusoft
Version:
our features are few but we provide the best and it is not uncommon to find in other npmjs
184 lines (180 loc) โข 7.63 kB
JavaScript
/*
* mulut tuh di jaga. jangan di kontol kontolin, di kentod kentotin, di anjing anjingin
* jangan lupa follow ig @hardianto02_
* jangan hapus author asli, jika ingin menghapus author asli, silahkan hubungi hardianto02_ untuk gelud bersama
*/
const { default: axios } = require('axios')
const { randomBytes } = require('crypto')
const { fromBuffer } = require('file-type')
const Image = require('node-webpmux').Image
const Formdata = require('form-data')
const fs = require('fs')
const toBuffer = (url) => {
return new Promise(async (resolve, reject) => {
if (Buffer.isBuffer(url)) {
const file = await fromBuffer(url)
resolve({
buffer: url,
mime: file.mime,
})
}
if (typeof url === 'string' && !url.includes('http')) {
const base64 = url.replace(/^data:(.*?);base64,/, '')
const file = await fromBuffer(Buffer.from(base64, 'base64'))
resolve({
buffer: Buffer.from(url, 'base64'),
mime: file.mime,
})
} else {
axios.get(url, { responseType: 'arraybuffer' }).then((res) => {
resolve({
buffer: res.data,
mime: res.headers['content-type'],
})
})
}
})
}
const config = {
sessionInfo: {
WA_VERSION: '2.2106.5',
PAGE_UA: 'WhatsApp/2.2037.6 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
WA_AUTOMATE_VERSION: '3.6.10 UPDATE AVAILABLE: 3.6.11',
BROWSER_VERSION: 'HeadlessChrome/88.0.4324.190',
OS: 'Windows Server 2016',
START_TS: 1614310326309,
NUM: '6247',
LAUNCH_TIME_MS: 7934,
PHONE_VERSION: '2.20.205.16',
},
config: {
sessionId: 'session',
headless: true,
qrTimeout: 20,
authTimeout: 0,
cacheEnabled: false,
useChrome: true,
killProcessOnBrowserClose: true,
throwErrorOnTosBlock: false,
chromiumArgs: ['--no-sandbox', '--disable-setuid-sandbox', '--aggressive-cache-discard', '--disable-cache', '--disable-application-cache', '--disable-offline-load-stale-cache', '--disk-cache-size=0'],
executablePath: 'C:\\\\Program Files (x86)\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe',
skipBrokenMethodsCheck: true,
stickerServerEndpoint: true,
},
}
/**
* unshorten url
* @param {String} url url of the website
* @returns {Promise<String>}
*/
exports.expandedUrl = async (url) => {
let link
try {
const res = await axios.request({
method: 'get',
url: url,
maxRedirects: 0,
headers: {
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; Redmi 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.58 Mobile Safari/537.36',
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
},
})
link = res.headers.location
} catch (err) {
if (Math.trunc(err.response.status / 100) === 3) {
link = err.response.headers.location
} else {
throw err
}
} finally {
return link
}
}
exports.setExif = async (webpSticker, packname, author, extra = {}) => {
return new Promise(async (resolve, reject) => {
const img = new Image()
const stickerPackId = randomBytes(16).toString('hex').slice(0, 8)
const json = {
'sticker-pack-id': stickerPackId,
'sticker-pack-name': packname,
'sticker-pack-publisher': author,
'sticker-pack-publisher-id': author,
'sticker-pack-version': '1.0.0',
'android-app-store-link': 'https://wibusoft.site',
'ios-app-store-link': 'https://wibusoft.site',
'sticker-pack-description': 'sticker ini merupakan sticker yang telah di generate oleh jamal',
emojis: ['โค', '๐', '๐', '๐', '๐ป', '๐', '๐ฉโโคโ๐ฉ', '๐จโโคโ๐จ', '๐', '๐ฉโโคโ๐โ๐ฉ', '๐จโโคโ๐โ๐จ', '๐งก', '๐', '๐', '๐', '๐', '๐ค', '๐', 'โฃ', '๐', '๐', '๐', '๐', '๐', '๐', '๐', 'โฅ', '๐', '๐', '๐ฉโโค๏ธโ๐โ๐ฉ', '๐จโโค๏ธโ๐โ๐จ', '๐ฉโโค๏ธโ๐จ', '๐ฉโโค๏ธโ๐ฉ', '๐จโโค๏ธโ๐จ', '๐ฉโโค๏ธโ๐โ๐จ', '๐ฌ', '๐ญ', '๐ซ', '๐ฅฐ', '๐', '๐', '๐', '๐น', '๐ฝ', 'โฃ๏ธ', 'โค๏ธ', '๐', '๐', '๐', '๐', '๐', '๐
', '๐', '๐คฃ', '๐', '๐', '๐', '๐', '๐คช', '๐ค', '๐บ', '๐ธ', '๐น', 'โบ', '๐', '๐', '๐ค', '๐', '๐', '๐', '๐', '๐', '๐ฏโโ๏ธ', '๐ฏ', '๐ฏโโ๏ธ', '๐', '๐บ', '๐ฅ', 'โญ๏ธ', 'โจ', '๐ซ', '๐', '๐', '๐ป', '๐ฅ', '๐พ', '๐', '๐ฐ', 'โน', '๐ฃ', '๐', '๐ซ', '๐ฉ', '๐ข', '๐ญ', '๐', '๐', '๐', '๐', '๐ค', '๐ ', '๐ฅ', '๐ฐ', '๐จ', '๐ฟ', '๐พ', '๐', '๐โโ', '๐โโ', '๐', '๐', '๐ฅบ', '๐ค', 'โ๏ธ', 'โ', '๐ฉ', '๐ง,๐ฏ', '๐ฆ', '๐ง', '๐ฎ', '๐ฒ', '๐', '๐ฑ', '๐คฏ', '๐ณ', 'โ', 'โ', '๐คฌ', '๐ก', '๐ ', '๐', '๐ฟ', '๐พ', '๐ค', '๐ข', '๐บ', '๐ฏ๏ธ', '๐', '๐ฅต', '๐'],
...extra,
}
let exifAttr = Buffer.from([0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00])
let jsonBuffer = Buffer.from(JSON.stringify(json), 'utf8')
let exif = Buffer.concat([exifAttr, jsonBuffer])
exif.writeUIntLE(jsonBuffer.length, 14, 4)
await img.load(webpSticker)
img.exif = exif
return resolve(await img.save(null))
})
}
/**
* implement the sticker generator from @rayyreal
* @param {Buffer | String} file serah lu
* @param {Object} data config untuk sticker
* @returns {Promise<Buffer>}
*/
exports.makeSticker = async (
file,
datao = {
author: '',
pack: '',
keepScale: true,
removebg: 'HQ',
circle: false,
}
) => {
return new Promise(async (resolve, reject) => {
const buffer = await toBuffer(file)
if (buffer.mime == 'image/webp') return resolve(await this.setExif(buffer.buffer, datao.pack, datao.author))
const config2 = {
...datao,
processOptions: {
crop: !datao.keepScale,
fps: 10,
startTime: '00:00:00.0',
endTime: '00:00:7.0',
loop: 0,
},
}
const DEFAULT_URL = 'https://sticker-api.openwa.dev/'
let Type = buffer.mime.includes('image') ? 'image' : 'file'
let url = String(`${DEFAULT_URL}${Type === 'image' ? 'prepareWebp' : 'convertMp4BufferToWebpDataUrl'}`)
await axios(url, {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, /',
'Content-Type': 'application/json;charset=utf-8',
'User-Agent': 'WhatsApp/2.2037.6 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
},
data: JSON.stringify(
Object.assign(
config,
{ stickerMetadata: config2 },
{
[Type]: `data:${buffer.mime};base64,${buffer.buffer.toString('base64')}`,
}
)
),
maxBodyLength: Infinity,
maxContentLength: Infinity,
})
.then(async ({ data }) => {
if (Type === 'image') return resolve(await this.setExif(Buffer.from(data.webpBase64, 'base64'), datao.author, datao.pack))
else {
const webpBase = data.replace(/^data:(.*?);base64,/, '')
const webpBase64 = webpBase.replace(/ /g, '+')
const file = Buffer.from(webpBase64, 'base64')
resolve(await this.setExif(file, datao.pack, datao.author))
}
})
.catch((err) => reject(err))
})
}