Update Dockerfile
Browse files- Dockerfile +123 -74
Dockerfile
CHANGED
|
@@ -24,27 +24,62 @@ RUN cat <<'EOF' > /app/index.js
|
|
| 24 |
const express = require('express');
|
| 25 |
const cors = require('cors');
|
| 26 |
const axios = require('axios');
|
|
|
|
| 27 |
|
| 28 |
const app = express();
|
| 29 |
const PORT = 7860;
|
| 30 |
-
|
| 31 |
const chatApiUrl = 'https://www.blackbox.ai/api/chat';
|
| 32 |
|
| 33 |
-
const
|
| 34 |
-
'
|
| 35 |
-
'
|
| 36 |
-
'
|
| 37 |
-
'
|
| 38 |
-
'
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
};
|
| 49 |
|
| 50 |
const generateId = (size = 7) => {
|
|
@@ -52,83 +87,97 @@ const generateId = (size = 7) => {
|
|
| 52 |
return Array.from({ length: size }, () => alphabet[Math.floor(Math.random() * alphabet.length)]).join('');
|
| 53 |
};
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
const parseApiResponse = (data) => {
|
| 56 |
const delimiter = '$~~~$';
|
| 57 |
if (typeof data === 'string' && data.includes(delimiter)) {
|
| 58 |
const parts = data.split(delimiter);
|
| 59 |
try {
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
}
|
| 64 |
return data;
|
| 65 |
};
|
| 66 |
|
| 67 |
-
const createPayload = (prompt) => {
|
| 68 |
-
return {
|
| 69 |
-
"messages": [{ "role": "user", "content": prompt, "id": generateId() }],
|
| 70 |
-
"id": generateId(),
|
| 71 |
-
"previewToken": null,
|
| 72 |
-
"userId": null,
|
| 73 |
-
"codeModelMode": true,
|
| 74 |
-
"trendingAgentMode": {},
|
| 75 |
-
"isMicMode": false,
|
| 76 |
-
"userSystemPrompt": null,
|
| 77 |
-
"maxTokens": 1024,
|
| 78 |
-
"playgroundTopP": null,
|
| 79 |
-
"playgroundTemperature": null,
|
| 80 |
-
"isChromeExt": false,
|
| 81 |
-
"githubToken": "",
|
| 82 |
-
"clickedAnswer2": false,
|
| 83 |
-
"clickedAnswer3": false,
|
| 84 |
-
"clickedForceWebSearch": false,
|
| 85 |
-
"visitFromDelta": false,
|
| 86 |
-
"isMemoryEnabled": false,
|
| 87 |
-
"mobileClient": false,
|
| 88 |
-
"userSelectedModel": null,
|
| 89 |
-
"userSelectedAgent": "VscodeAgent",
|
| 90 |
-
"validated": "a38f5889-8fef-46d4-8ede-bf4668b6a9bb",
|
| 91 |
-
"imageGenerationMode": false,
|
| 92 |
-
"imageGenMode": "autoMode",
|
| 93 |
-
"webSearchModePrompt": false,
|
| 94 |
-
"deepSearchMode": false,
|
| 95 |
-
"promptSelection": "",
|
| 96 |
-
"domains": null,
|
| 97 |
-
"vscodeClient": false,
|
| 98 |
-
"codeInterpreterMode": false,
|
| 99 |
-
"customProfile": { "name": "", "occupation": "", "traits": [], "additionalInfo": "", "enableNewChats": false },
|
| 100 |
-
"webSearchModeOption": { "autoMode": true, "webMode": false, "offlineMode": false },
|
| 101 |
-
"session": {
|
| 102 |
-
"user": { "name": "Riki PurPur", "email": "rikipurpur98@gmail.com", "image": "https://lh3.googleusercontent.com/a/ACg8ocKHaWelcSDldvbm6wh0CegljUr_Iyv8NYNFVlaCb0qk_LrecA4=s96-c", "id": "105532451547066425912" },
|
| 103 |
-
"expires": "2025-10-29T10:34:29.189Z",
|
| 104 |
-
"isNewUser": false
|
| 105 |
-
},
|
| 106 |
-
"isPremium": false,
|
| 107 |
-
"subscriptionCache": { "status": "FREE", "customerId": null, "expiryTimestamp": null, "lastChecked": 1759069451898, "isTrialSubscription": false, "hasPaymentVerificationFailure": false, "verificationFailureTimestamp": null, "requiresAuthentication": false },
|
| 108 |
-
"beastMode": false,
|
| 109 |
-
"reasoningMode": false,
|
| 110 |
-
"designerMode": false,
|
| 111 |
-
"workspaceId": "",
|
| 112 |
-
"asyncMode": false,
|
| 113 |
-
"integrations": {},
|
| 114 |
-
"isTaskPersistent": false,
|
| 115 |
-
"selectedElement": null
|
| 116 |
-
};
|
| 117 |
-
};
|
| 118 |
-
|
| 119 |
app.use(cors());
|
| 120 |
-
app.use(express.json());
|
|
|
|
| 121 |
|
| 122 |
app.post('/api/generate', async (req, res) => {
|
| 123 |
const { prompt } = req.body;
|
| 124 |
if (!prompt) {
|
| 125 |
return res.status(400).json({ error: 'Request body harus menyertakan "prompt"' });
|
| 126 |
}
|
|
|
|
| 127 |
try {
|
| 128 |
-
const
|
| 129 |
-
const
|
|
|
|
|
|
|
|
|
|
| 130 |
const finalAnswer = parseApiResponse(response.data);
|
|
|
|
|
|
|
| 131 |
res.send(finalAnswer);
|
|
|
|
| 132 |
} catch (error) {
|
| 133 |
console.error("Error pada /api/generate:", error.message);
|
| 134 |
res.status(500).send("Terjadi kesalahan pada server saat memproses permintaan.");
|
|
|
|
| 24 |
const express = require('express');
|
| 25 |
const cors = require('cors');
|
| 26 |
const axios = require('axios');
|
| 27 |
+
const crypto = require('crypto');
|
| 28 |
|
| 29 |
const app = express();
|
| 30 |
const PORT = 7860;
|
|
|
|
| 31 |
const chatApiUrl = 'https://www.blackbox.ai/api/chat';
|
| 32 |
|
| 33 |
+
const userAgents = [
|
| 34 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
|
| 35 |
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
|
| 36 |
+
'Mozilla/5.0 (Linux; Android 13; SM-S908B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36',
|
| 37 |
+
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1',
|
| 38 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0'
|
| 39 |
+
];
|
| 40 |
+
|
| 41 |
+
const firstNames = ['Adi', 'Budi', 'Citra', 'Dewi', 'Eka', 'Fajar', 'Gita', 'Hadi', 'Indah', 'Joko'];
|
| 42 |
+
const lastNames = ['Santoso', 'Wijaya', 'Kusuma', 'Lestari', 'Pratama', 'Nugroho', 'Wahyuni', 'Setiawan'];
|
| 43 |
+
|
| 44 |
+
const getRandomElement = (arr) => arr[Math.floor(Math.random() * arr.length)];
|
| 45 |
+
|
| 46 |
+
const generateRandomSession = () => {
|
| 47 |
+
const firstName = getRandomElement(firstNames);
|
| 48 |
+
const lastName = getRandomElement(lastNames);
|
| 49 |
+
const name = `${firstName} ${lastName}`;
|
| 50 |
+
const email = `${firstName.toLowerCase()}.${lastName.toLowerCase()}${Math.floor(Math.random() * 1000)}@gmail.com`;
|
| 51 |
+
const id = (BigInt(10**20) + BigInt(Math.floor(Math.random() * 9 * 10**20))).toString();
|
| 52 |
+
const expires = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString();
|
| 53 |
+
|
| 54 |
+
return {
|
| 55 |
+
user: { name, email, image: `https://ui-avatars.com/api/?name=${encodeURIComponent(name)}`, id },
|
| 56 |
+
expires,
|
| 57 |
+
isNewUser: false
|
| 58 |
+
};
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
const createHeaders = () => {
|
| 62 |
+
const userAgent = getRandomElement(userAgents);
|
| 63 |
+
const isMobile = userAgent.includes('Mobile') || userAgent.includes('Android') || userAgent.includes('iPhone');
|
| 64 |
+
const platform = userAgent.includes('Win') ? '"Windows"' : userAgent.includes('Mac') ? '"macOS"' : '"Android"';
|
| 65 |
+
const chromeVersion = userAgent.match(/Chrome\/(\d+)/)?.[1] || '125';
|
| 66 |
+
|
| 67 |
+
const headers = {
|
| 68 |
+
'Accept': '*/*',
|
| 69 |
+
'Accept-Language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
|
| 70 |
+
'Content-Type': 'application/json',
|
| 71 |
+
'Origin': 'https://www.blackbox.ai',
|
| 72 |
+
'Referer': 'https://www.blackbox.ai/',
|
| 73 |
+
'User-Agent': userAgent,
|
| 74 |
+
'Sec-Ch-Ua': `"Google Chrome";v="${chromeVersion}", "Not(A:Brand";v="8", "Chromium";v="${chromeVersion}"`,
|
| 75 |
+
'Sec-Ch-Ua-Mobile': isMobile ? '?1' : '?0',
|
| 76 |
+
'Sec-Ch-Ua-Platform': platform,
|
| 77 |
+
'Sec-Fetch-Dest': 'empty',
|
| 78 |
+
'Sec-Fetch-Mode': 'cors',
|
| 79 |
+
'Sec-Fetch-Site': 'same-origin',
|
| 80 |
+
'Cookie': `sessionId=${crypto.randomUUID()}`
|
| 81 |
+
};
|
| 82 |
+
return { headers, isMobile };
|
| 83 |
};
|
| 84 |
|
| 85 |
const generateId = (size = 7) => {
|
|
|
|
| 87 |
return Array.from({ length: size }, () => alphabet[Math.floor(Math.random() * alphabet.length)]).join('');
|
| 88 |
};
|
| 89 |
|
| 90 |
+
const createPayload = (prompt, session, isMobile) => {
|
| 91 |
+
return {
|
| 92 |
+
messages: [{ role: "user", content: prompt, id: generateId() }],
|
| 93 |
+
id: generateId(),
|
| 94 |
+
previewToken: null,
|
| 95 |
+
userId: crypto.randomUUID(),
|
| 96 |
+
codeModelMode: true,
|
| 97 |
+
trendingAgentMode: {},
|
| 98 |
+
isMicMode: false,
|
| 99 |
+
userSystemPrompt: null,
|
| 100 |
+
maxTokens: 1024,
|
| 101 |
+
playgroundTopP: null,
|
| 102 |
+
playgroundTemperature: null,
|
| 103 |
+
isChromeExt: false,
|
| 104 |
+
githubToken: "",
|
| 105 |
+
clickedAnswer2: false,
|
| 106 |
+
clickedAnswer3: false,
|
| 107 |
+
clickedForceWebSearch: false,
|
| 108 |
+
visitFromDelta: false,
|
| 109 |
+
isMemoryEnabled: false,
|
| 110 |
+
mobileClient: isMobile,
|
| 111 |
+
userSelectedModel: null,
|
| 112 |
+
userSelectedAgent: "VscodeAgent",
|
| 113 |
+
validated: "a38f5889-8fef-46d4-8ede-bf4668b6a9bb",
|
| 114 |
+
imageGenerationMode: false,
|
| 115 |
+
imageGenMode: "autoMode",
|
| 116 |
+
webSearchModePrompt: false,
|
| 117 |
+
deepSearchMode: false,
|
| 118 |
+
promptSelection: "",
|
| 119 |
+
domains: null,
|
| 120 |
+
vscodeClient: false,
|
| 121 |
+
codeInterpreterMode: false,
|
| 122 |
+
customProfile: { name: "", occupation: "", traits: [], additionalInfo: "", enableNewChats: false },
|
| 123 |
+
webSearchModeOption: { autoMode: true, webMode: false, offlineMode: false },
|
| 124 |
+
session: session,
|
| 125 |
+
isPremium: false,
|
| 126 |
+
subscriptionCache: {
|
| 127 |
+
status: "FREE",
|
| 128 |
+
customerId: null,
|
| 129 |
+
expiryTimestamp: null,
|
| 130 |
+
lastChecked: Date.now(),
|
| 131 |
+
isTrialSubscription: false,
|
| 132 |
+
hasPaymentVerificationFailure: false,
|
| 133 |
+
verificationFailureTimestamp: null,
|
| 134 |
+
requiresAuthentication: false
|
| 135 |
+
},
|
| 136 |
+
beastMode: false,
|
| 137 |
+
reasoningMode: false,
|
| 138 |
+
designerMode: false,
|
| 139 |
+
workspaceId: "",
|
| 140 |
+
asyncMode: false,
|
| 141 |
+
integrations: {},
|
| 142 |
+
isTaskPersistent: false,
|
| 143 |
+
selectedElement: null
|
| 144 |
+
};
|
| 145 |
+
};
|
| 146 |
+
|
| 147 |
const parseApiResponse = (data) => {
|
| 148 |
const delimiter = '$~~~$';
|
| 149 |
if (typeof data === 'string' && data.includes(delimiter)) {
|
| 150 |
const parts = data.split(delimiter);
|
| 151 |
try {
|
| 152 |
+
return parts[2] ? parts[2].trim() : data;
|
| 153 |
+
} catch {
|
| 154 |
+
return data;
|
| 155 |
+
}
|
| 156 |
}
|
| 157 |
return data;
|
| 158 |
};
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
app.use(cors());
|
| 161 |
+
app.use(express.json({ limit: '50mb' }));
|
| 162 |
+
app.use(express.urlencoded({ extended: true, limit: '50mb' }));
|
| 163 |
|
| 164 |
app.post('/api/generate', async (req, res) => {
|
| 165 |
const { prompt } = req.body;
|
| 166 |
if (!prompt) {
|
| 167 |
return res.status(400).json({ error: 'Request body harus menyertakan "prompt"' });
|
| 168 |
}
|
| 169 |
+
|
| 170 |
try {
|
| 171 |
+
const session = generateRandomSession();
|
| 172 |
+
const { headers, isMobile } = createHeaders();
|
| 173 |
+
const payload = createPayload(prompt, session, isMobile);
|
| 174 |
+
|
| 175 |
+
const response = await axios.post(chatApiUrl, payload, { headers: headers });
|
| 176 |
const finalAnswer = parseApiResponse(response.data);
|
| 177 |
+
|
| 178 |
+
res.setHeader('Content-Type', 'text/plain');
|
| 179 |
res.send(finalAnswer);
|
| 180 |
+
|
| 181 |
} catch (error) {
|
| 182 |
console.error("Error pada /api/generate:", error.message);
|
| 183 |
res.status(500).send("Terjadi kesalahan pada server saat memproses permintaan.");
|