testing / Dockerfile
nirkyy's picture
Update Dockerfile
3dc28b4 verified
raw
history blame
7.14 kB
FROM node:20-slim
WORKDIR /app
RUN cat <<'EOF' > /app/package.json
{
"name": "gemini-api-server",
"version": "1.0.0,
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"axios": "^1.6.8",
"cors": "^2.8.5",
"express": "^4.19.2"
}
}
EOF
RUN npm install --only=production
RUN cat <<'EOF' > /app/index.js
const express = require('express');
const cors = require('cors');
const axios = require('axios');
const app = express();
const PORT = 7860;
const chatApiUrl = 'https://www.blackbox.ai/api/chat';
const hardcodedHeaders = {
'Accept': '*/*',
'Accept-Language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
'Content-Type': 'application/json',
'Origin': 'https://www.blackbox.ai',
'Referer': 'https://www.blackbox.ai/',
'Sec-Ch-Ua': '"Chromium";v="140", "Not=A?Brand";v="24", "Android WebView";v="140"',
'Sec-Ch-Ua-Mobile': '?1',
'Sec-Ch-Ua-Platform': '"Android"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; RMX2185 Build/QP1A.190711.020) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.7339.207 Mobile Safari/537.36',
'X-Requested-With': 'mark.via.gp',
'Cookie': '__Host-authjs.csrf-token=ed355b358172e4e050f721e04571070c4fce9bc13dc1718dfbe9bc982b06f2d0%7C083bfcf62ec727151678b4d1dd305aed9bf4599f6b79640a08b79ab8c1f4f9f1; __Secure-authjs.callback-url=https%3A%2F%2Fwww.blackbox.ai%2Fchat%2Fv3lqW9e; intercom-id-x55eda6t=31841dc1-d158-4bb8-b24f-8c748509dedd; intercom-device-id-x55eda6t=c52c671c-4b1d-432f-892c-a4038dc76013; sessionId=7671e063-8a54-4b3e-96a1-439980e8a446; userCountry=%7B%22country%22%3A%22ID%22%2C%22currency%22%3A%22IDR%22%2C%22timestamp%22%3A1758795459179%2C%22expires%22%3A1759400259179%7D; discount-dialog-shown=true; ph_phc_TXdpocbGVeZVm5VJmAsHTMrCofBQu3e0kN8HGMNGTVW_posthog=%7B%22distinct_id%22%3A%2201998066-2b0a-76ff-8d4b-20b202d399d0%22%2C%22%24sesid%22%3A%5B1759069624381%2C%22019990b7-6079-739c-8ce1-d7065e91cd46%22%2C1759069560952%5D%7D; intercom-session-x55eda6t=UVcyeTZMajd6Vm1CYUNqV1pNUitDZHFYV3lsOVcrUG9Rdk1PeWJQb1c5OTI0UDgrRUNNM0NIYmdYTGlDY1ByWGZpYmEzaXlueDdGUWQ1Y0JOWDM0OEUvSHYyaDRFdUxLQVZwWUpqM3RYRms9LS1OTVh5TVRDY0tJR3kxaFNzMExCY3lnPT0=--e7f6016070d315ac11335141bcebc9394a68d7f7; __Secure-authjs.session-token=eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwia2lkIjoiUGlDZ216aEVpaHh1enpfRVQwVms0WENENDR6Z2FjRTcyOTV4T2VFWkFJblFFZTJhMUV4eWZ1akpIdDJmeG5qSzFPME9qTDFXYVliVlNjWlRXNHJoR0EifQ..iSV2pccgt2nqwH0_m1hyvQ.Ppx_FjkipBsnPN46_l1wIaHIIm8oitiJQvyMNWYLicl12sfjj6GvMrGqlestre-_5qQRAYbcAzwSxzNSAXhDGf8Wk8tleslL9DFxBpUr8yDE-cKWURAjPfR-n0_0wuz8dsuvPH9E_2_fj2I6nNbNS9CS1tG6Nteq9yHazEwlOZXbuQ34gQRGB2lcazSFPBvKHr2402htSysMcVWh8WZearczfZ0S7aIFkd_6QO4-hKkayPo7j23syZYwaIun04dU6MHSxKbuOuIvJTz7wEjW7RYwPhx2Fyh8o1iLjDQBh9eXlRD6ZTFDQURi-gxuRwzl1AhaBJ6cYkLDdOb4SzkpDRC-OXQ1GkikZYoYdTxl1vIZFELHQ_FiZAes4RfnjGNdx5pkhEQ7I82ixP9bPW9BWVeSFtGnHLWl3yuW0gXwvDDlsQjQmrUZCtAoL0_M00NEiWPeX0ePG73cAsENzKnAXZiFpDDTmtQ78nrQVh4plhXC0GmRcGGGjTmML61MBnBJUBXhQtx0h102cuYTWKO3ET5pWfVP9Kb_sZQh-CCpEr0.kiIiz5OSA-68BCVIF5MQvpV4XZRzHo1OmVwVM-qlY84; ph_phc_9T0rgpbTO2ItkwbH8HNZuavYKcQ3h3wxzJwELM6JHV4_posthog=%7B%22distinct_id%22%3A%220199463a-b34d-76e9-be02-2925eae882fa%22%2C%22%24sesid%22%3A%5B1759142073019%2C%2201999508-4136-7e06-a044-1ca9903d8020%22%2C1759141970229%5D%2C%22%24initial_person_info%22%3A%7B%22r%22%3A%22%24direct%22%2C%22u%22%3A%22https%3A%2F%2Fwww.blackbox.ai%2F%22%7D%7D'
};
const generateId = (size = 7) => {
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
return Array.from({ length: size }, () => alphabet[Math.floor(Math.random() * alphabet.length)]).join('');
};
const parseApiResponse = (data) => {
const delimiter = '$~~~$';
if (typeof data === 'string' && data.includes(delimiter)) {
const parts = data.split(delimiter);
try {
const answer = parts[2] ? parts[2].trim() : '';
return answer;
} catch { return data; }
}
return data;
};
const createPayload = (prompt) => {
return {
"messages": [{ "role": "user", "content": prompt, "id": generateId() }],
"id": generateId(),
"previewToken": null,
"userId": null,
"codeModelMode": true,
"trendingAgentMode": {},
"isMicMode": false,
"userSystemPrompt": null,
"maxTokens": 1024,
"playgroundTopP": null,
"playgroundTemperature": null,
"isChromeExt": false,
"githubToken": "",
"clickedAnswer2": false,
"clickedAnswer3": false,
"clickedForceWebSearch": false,
"visitFromDelta": false,
"isMemoryEnabled": false,
"mobileClient": false,
"userSelectedModel": null,
"userSelectedAgent": "VscodeAgent",
"validated": "a38f5889-8fef-46d4-8ede-bf4668b6a9bb",
"imageGenerationMode": false,
"imageGenMode": "autoMode",
"webSearchModePrompt": false,
"deepSearchMode": false,
"promptSelection": "",
"domains": null,
"vscodeClient": false,
"codeInterpreterMode": false,
"customProfile": { "name": "", "occupation": "", "traits": [], "additionalInfo": "", "enableNewChats": false },
"webSearchModeOption": { "autoMode": true, "webMode": false, "offlineMode": false },
"session": {
"user": { "name": "Riki PurPur", "email": "rikipurpur98@gmail.com", "image": "https://lh3.googleusercontent.com/a/ACg8ocKHaWelcSDldvbm6wh0CegljUr_Iyv8NYNFVlaCb0qk_LrecA4=s96-c", "id": "105532451547066425912" },
"expires": "2025-10-29T10:34:29.189Z",
"isNewUser": false
},
"isPremium": false,
"subscriptionCache": { "status": "FREE", "customerId": null, "expiryTimestamp": null, "lastChecked": 1759069451898, "isTrialSubscription": false, "hasPaymentVerificationFailure": false, "verificationFailureTimestamp": null, "requiresAuthentication": false },
"beastMode": false,
"reasoningMode": false,
"designerMode": false,
"workspaceId": "",
"asyncMode": false,
"integrations": {},
"isTaskPersistent": false,
"selectedElement": null
};
};
app.use(cors());
app.use(express.json());
app.post('/api/generate', async (req, res) => {
const { prompt } = req.body;
if (!prompt) {
return res.status(400).json({ error: 'Request body harus menyertakan "prompt"' });
}
try {
const payload = createPayload(prompt);
const response = await axios.post(chatApiUrl, payload, { headers: hardcodedHeaders });
const finalAnswer = parseApiResponse(response.data);
res.send(finalAnswer);
} catch (error) {
console.error("Error pada /api/generate:", error.message);
res.status(500).send("Terjadi kesalahan pada server saat memproses permintaan.");
}
});
app.listen(PORT, () => {
console.log(`Server berjalan di http://localhost:${PORT}`);
console.log('Endpoint tersedia: POST /api/generate');
});
EOF
EXPOSE 7860
CMD ["npm", "start"]