termai commited on
Commit
1fef182
·
verified ·
1 Parent(s): b650bb0

Delete edit.js

Browse files
Files changed (1) hide show
  1. edit.js +0 -77
edit.js DELETED
@@ -1,77 +0,0 @@
1
- const fs = require("fs");
2
- const Form = require("form-data");
3
-
4
- global.data = {
5
- messages: {},
6
- taskId: {},
7
- listimageedit: ["omnigen"],
8
- };
9
-
10
- class Edit {
11
- static async omnigen(buffer, prompt) {
12
- try {
13
- const formData = new FormData();
14
-
15
- const file = new File([buffer], "image.png", { type: "image/png" });
16
- formData.append("image", file);
17
-
18
- formData.append("prompt", prompt);
19
-
20
- const response = await fetch(
21
- "https://omnigenai.org/api/ai/image/image-editor",
22
- {
23
- method: "POST",
24
- headers: {
25
- accept: "*/*",
26
- "accept-language": "id-ID,id;q=0.9,en-US;q=0.8",
27
- Referer: "https://omnigenai.org/ai-image-editor",
28
- },
29
- credentials: "include",
30
- body: formData,
31
- }
32
- );
33
-
34
- if (!response.ok) {
35
- throw new Error(`Gagal: ${response.status} ${response.statusText}`);
36
- }
37
-
38
- const result = await response.json();
39
- return result;
40
- } catch (error) {
41
- console.error("Error:", error);
42
- throw error;
43
- }
44
- }
45
- }
46
-
47
- let changeList = function (list) {
48
- if (!(list in data)) return;
49
- data[list].push(data[list].shift());
50
- };
51
- const edit = async (image, retries = 20, delay = 1000) => {
52
- for (let attempt = 1; attempt <= retries; attempt++) {
53
- try {
54
- let ai = await Edit[data.listimageedit[0]](image);
55
- console.log({ ai });
56
-
57
- console.log(`[${data.listimageedit[0]}]`, ai);
58
- changeList("listimageedit");
59
- } catch (error) {
60
- changeList("listimageedit");
61
- if (attempt < retries) {
62
- console.log(
63
- `IMAGE_EDIT[${
64
- data.listimageedit[data.listimageedit.length - 1]
65
- }]: Retryng ${attempt} failed.`,
66
- error
67
- );
68
- await new Promise((resolve) => setTimeout(resolve, delay));
69
- } else {
70
- return new Error(`Failed after ${retries} attempts: ${error.message}`);
71
- }
72
- }
73
- }
74
- };
75
-
76
- let image = fetch.readFileSync("./a.jpg");
77
- edit(image).then((a) => console.log(a));