LucasMod

glidplus

Nov 9th, 2025
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.37 KB | Source Code | 0 0
  1. //By: 𖧄 𝐋𝐔𝐂𝐀𝐒 𝐌𝐎𝐃 𝐃𝐎𝐌𝐈𝐍𝐀 𖧄
  2. //Canal: https://whatsapp.com/channel/0029Vb69bDnAe5VmzSMwBH11
  3.  
  4. const { fromBuffer } = require('file-type')
  5. const FormData = require("form-data")
  6. const crypto = require("node:crypto")
  7. const axios = require("axios")
  8.  
  9. class GridPlus {
  10. constructor() {
  11. this.ins = axios.create({
  12. baseURL: 'https://api.grid.plus/v1',
  13. headers: {
  14. 'user-agent': 'Mozilla/5.0 (Android 15; Mobile; SM-F958; rv:130.0) Gecko/130.0 Firefox/130.0',
  15. 'X-AppID': '808645',
  16. 'X-Platform': 'h5',
  17. 'X-Version': '8.9.7',
  18. 'X-SessionToken': '',
  19. 'X-UniqueID': this.uid(),
  20. 'X-GhostID': this.uid(),
  21. 'X-DeviceID': this.uid(),
  22. 'X-MCC': 'id-ID',
  23. 'sig': `XX${this.uid() + this.uid()}`
  24. }
  25. });
  26. }
  27. uid() {
  28. return crypto.randomUUID().replace(/-/g, '');
  29. }
  30. form(dt) {
  31. const form = new FormData();
  32. Object.entries(dt).forEach(([key, value]) => {
  33. form.append(key, String(value));
  34. });
  35. return form;
  36. }
  37.  
  38. async upload(buff, method) {
  39. try {
  40. if (!Buffer.isBuffer(buff)) throw new Error('Os dados não são um buffer!');
  41. const fileType = await fromBuffer(buff);
  42. if (!fileType) throw new Error('Não foi possível determinar o tipo de arquivo.');
  43. const { mime, ext } = fileType;
  44. const d = await this.ins.post('/ai/web/nologin/getuploadurl', this.form({
  45. ext, method
  46. })).then(i => i.data);
  47. await axios.put(d.data.upload_url, buff, {
  48. headers: {
  49. 'content-type': mime
  50. }
  51. });
  52. return d.data.img_url;
  53. } catch(e) {
  54. throw new Error('Ocorreu um erro ao carregar a imagem: ' + e.message);
  55. }
  56. }
  57.  
  58. async task({ path, data, sl = () => false }) {
  59. const [start, interval, timeout] = [
  60. Date.now(), 3000, 60000
  61. ];
  62. return new Promise(async (resolve, reject) => {
  63. const check = async () => {
  64. if (Date.now() - start > timeout) {
  65. return reject(new Error(`O tempo limite de sondagem para o caminho foi excedido: ${path}`));
  66. }
  67. try {
  68. const dt = await this.ins({
  69. url: path,
  70. method: data ? 'POST' : 'GET',
  71. ...(data ? { data } : {})
  72. });
  73. if (dt.errmsg?.trim()) {
  74. return reject(new Error(`API error: ${dt.errmsg}`));
  75. }
  76. if (sl(dt.data)) {
  77. return resolve(dt.data);
  78. }
  79. setTimeout(check, interval);
  80. } catch (error) {
  81. reject(error);
  82. }
  83. };
  84. check();
  85. });
  86. }
  87.  
  88. async edit(buff, prompt) {
  89. try {
  90. const up = await this.upload(buff, 'wn_aistyle_nano');
  91. const dn = await this.ins.post('/ai/nano/upload', this.form({
  92. prompt,
  93. url: up
  94. })).then(i => i.data);
  95. if (!dn.task_id) throw new Error('taskId não encontrado na solicitação');
  96. const res = await this.task({
  97. path: `/ai/nano/get_result/${dn.task_id}`,
  98. sl: (dt) => dt.code === 0 && !!dt.image_url,
  99. });
  100. return res.image_url;
  101. } catch(e) {
  102. throw new Error('Falha na edição: ' + e.message);
  103. }
  104. }
  105. }
  106.  
  107. module.exports = GridPlus
  108.  
  109. /*
  110. EXEMPLO DE USO:
  111.  
  112. const fs = require("fs");
  113. const GridPlus = require("./gridplus");
  114.  
  115. async function exemploUso() {
  116. try {
  117. const gp = new GridPlus();
  118. const img = fs.readFileSync("./caminho/para/sua/imagem.jpg");
  119. // Define o prompt de edição
  120. const prompt = "Crie uma miniatura comercial em escala 1/7 dos personagens da imagem, em estilo realista e em um ambiente real. A miniatura está posicionada sobre uma mesa de computador. A miniatura possui um globo transparente redondo.";
  121. const res = await gp.edit(img, prompt);
  122. console.log("Imagem processada com sucesso:");
  123. console.log(res);
  124. } catch (error) {
  125. console.error("Erro ao processar imagem:", error.message);
  126. }
  127. }
  128. // exemploUso();
  129. */
Advertisement
Add Comment
Please, Sign In to add comment