Upload 4 files
Browse files- fast.js +78 -70
- package.json +10 -10
- plugins/deepseek.js +85 -124
- plugins/index.ejs +227 -227
fast.js
CHANGED
|
@@ -1,71 +1,79 @@
|
|
| 1 |
-
const fastify = require('fastify')({ logger: true });
|
| 2 |
-
const fs = require('fs');
|
| 3 |
-
const path = require('path');
|
| 4 |
-
const chokidar = require('chokidar');
|
| 5 |
-
|
| 6 |
-
const pluginsDir = path.join(__dirname, 'plugins');
|
| 7 |
-
|
| 8 |
-
// Registrasi
|
| 9 |
-
fastify.register(require('@fastify/
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
process.
|
| 65 |
-
|
| 66 |
-
};
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
start();
|
|
|
|
| 1 |
+
const fastify = require('fastify')({ logger: true });
|
| 2 |
+
const fs = require('fs');
|
| 3 |
+
const path = require('path');
|
| 4 |
+
const chokidar = require('chokidar');
|
| 5 |
+
|
| 6 |
+
const pluginsDir = path.join(__dirname, 'plugins');
|
| 7 |
+
|
| 8 |
+
// 1. Registrasi Multipart (WAJIB untuk POST file/OCR)
|
| 9 |
+
fastify.register(require('@fastify/multipart'), {
|
| 10 |
+
limits: { fileSize: 10 * 1024 * 1024 } // Batas 10MB
|
| 11 |
+
});
|
| 12 |
+
|
| 13 |
+
// 2. Registrasi EJS
|
| 14 |
+
fastify.register(require('@fastify/view'), {
|
| 15 |
+
engine: { ejs: require('ejs') },
|
| 16 |
+
root: pluginsDir
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
let availablePlugins = [];
|
| 20 |
+
|
| 21 |
+
async function loadPlugins() {
|
| 22 |
+
// Membersihkan rute lama agar tidak duplikat saat reload (Opsional: Restart server lebih aman)
|
| 23 |
+
availablePlugins = [];
|
| 24 |
+
if (!fs.existsSync(pluginsDir)) return;
|
| 25 |
+
|
| 26 |
+
const files = fs.readdirSync(pluginsDir);
|
| 27 |
+
files.forEach(file => {
|
| 28 |
+
if (file.endsWith('.js')) {
|
| 29 |
+
const filePath = path.join(pluginsDir, file);
|
| 30 |
+
delete require.cache[require.resolve(filePath)];
|
| 31 |
+
|
| 32 |
+
try {
|
| 33 |
+
const plugin = require(filePath);
|
| 34 |
+
if (plugin.path && plugin.handler) {
|
| 35 |
+
// Daftarkan route
|
| 36 |
+
fastify.route({
|
| 37 |
+
method: plugin.method || 'GET',
|
| 38 |
+
url: plugin.path,
|
| 39 |
+
handler: plugin.handler
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
availablePlugins.push({
|
| 43 |
+
name: file.replace('.js', ''),
|
| 44 |
+
path: plugin.path,
|
| 45 |
+
method: plugin.method || 'GET',
|
| 46 |
+
description: plugin.description || 'No description'
|
| 47 |
+
});
|
| 48 |
+
}
|
| 49 |
+
} catch (err) {
|
| 50 |
+
console.error(`Error loading ${file}:`, err.message);
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
});
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
fastify.get('/', async (request, reply) => {
|
| 57 |
+
return reply.view('index.ejs', { plugins: availablePlugins });
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
const start = async () => {
|
| 61 |
+
try {
|
| 62 |
+
await loadPlugins();
|
| 63 |
+
// Port 7860 untuk Hugging Face, atau 3000 untuk lokal
|
| 64 |
+
const port = process.env.PORT || 7860;
|
| 65 |
+
await fastify.listen({ port: port, host: '0.0.0.0' });
|
| 66 |
+
console.log(`Server running on port ${port}`);
|
| 67 |
+
} catch (err) {
|
| 68 |
+
fastify.log.error(err);
|
| 69 |
+
process.exit(1);
|
| 70 |
+
}
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
+
chokidar.watch(pluginsDir, { ignoreInitial: true }).on('all', () => {
|
| 74 |
+
console.log("Plugins changed, reloading...");
|
| 75 |
+
// Catatan: Fastify tidak mendukung penghapusan route secara native tanpa plugin tambahan.
|
| 76 |
+
// Untuk hasil terbaik di produksi, proses harus di-restart.
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
start();
|
package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
{
|
| 2 |
"dependencies": {
|
| 3 |
-
"@fastify/
|
| 4 |
-
"@fastify/swagger
|
| 5 |
-
"@fastify/
|
| 6 |
-
"
|
| 7 |
-
"
|
| 8 |
-
"
|
| 9 |
-
"
|
| 10 |
-
"
|
| 11 |
-
"
|
| 12 |
-
"
|
| 13 |
}
|
| 14 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"dependencies": {
|
| 3 |
+
"@fastify/multipart": "^10.0.0",
|
| 4 |
+
"@fastify/swagger": "^9.7.0",
|
| 5 |
+
"@fastify/swagger-ui": "^5.2.5",
|
| 6 |
+
"@fastify/view": "^11.1.1",
|
| 7 |
+
"axios": "^1.15.0",
|
| 8 |
+
"chokidar": "^5.0.0",
|
| 9 |
+
"ejs": "^5.0.2",
|
| 10 |
+
"fastify": "^5.8.5",
|
| 11 |
+
"puppeteer": "^24.41.0",
|
| 12 |
+
"undici": "^8.1.0"
|
| 13 |
}
|
| 14 |
}
|
plugins/deepseek.js
CHANGED
|
@@ -1,125 +1,86 @@
|
|
| 1 |
-
const fetch = require('node-fetch');
|
| 2 |
-
const FormData = require('form-data');
|
| 3 |
-
const
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
const
|
| 13 |
-
const
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
method: "POST",
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
});
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
await fetch(`${API_BASE}/queue/join`, {
|
| 88 |
-
method: "POST",
|
| 89 |
-
headers: { "Content-Type": "application/json" },
|
| 90 |
-
body: JSON.stringify(payload)
|
| 91 |
-
});
|
| 92 |
-
|
| 93 |
-
const streamUrl = `${API_BASE}/queue/data?session_hash=${session_hash}`;
|
| 94 |
-
const response = await fetch(streamUrl);
|
| 95 |
-
|
| 96 |
-
return new Promise((resolve, reject) => {
|
| 97 |
-
response.body.on('data', (chunk) => {
|
| 98 |
-
const lines = chunk.toString().split("\n");
|
| 99 |
-
for (let line of lines) {
|
| 100 |
-
if (!line.includes("data: ")) continue;
|
| 101 |
-
try {
|
| 102 |
-
const json = JSON.parse(line.replace("data: ", ""));
|
| 103 |
-
if (json.msg === "process_completed") {
|
| 104 |
-
if (json.success) {
|
| 105 |
-
resolve({
|
| 106 |
-
status: "success",
|
| 107 |
-
method: request.method,
|
| 108 |
-
fileName: fileName,
|
| 109 |
-
result: json.output.data[0]
|
| 110 |
-
});
|
| 111 |
-
} else {
|
| 112 |
-
throw new Error(json.output.error || "Gagal memproses OCR");
|
| 113 |
-
}
|
| 114 |
-
}
|
| 115 |
-
} catch (e) {}
|
| 116 |
-
}
|
| 117 |
-
});
|
| 118 |
-
setTimeout(() => reject(new Error("Timeout processing OCR")), 60000);
|
| 119 |
-
});
|
| 120 |
-
|
| 121 |
-
} catch (err) {
|
| 122 |
-
return reply.status(500).send({ status: "error", message: err.message });
|
| 123 |
-
}
|
| 124 |
-
}
|
| 125 |
};
|
|
|
|
| 1 |
+
const fetch = require('node-fetch');
|
| 2 |
+
const FormData = require('form-data');
|
| 3 |
+
const path = require('path');
|
| 4 |
+
|
| 5 |
+
module.exports = {
|
| 6 |
+
path: '/deepseek-ocr',
|
| 7 |
+
method: ['GET', 'POST'], // Mendukung dua metode
|
| 8 |
+
description: 'OCR DeepSeek: Kirim URL via GET (?image=) atau File via POST.',
|
| 9 |
+
handler: async (request, reply) => {
|
| 10 |
+
const WORKER_PREFIX = "https://proxy2.afjasaku.workers.dev/?u=";
|
| 11 |
+
const HF_DOMAIN = "https://merterbak-deepseek-ocr-demo.hf.space";
|
| 12 |
+
const API_BASE = `${WORKER_PREFIX}${encodeURIComponent(HF_DOMAIN + "/gradio_api")}`;
|
| 13 |
+
const session_hash = Math.random().toString(36).substring(2);
|
| 14 |
+
|
| 15 |
+
try {
|
| 16 |
+
let fileData;
|
| 17 |
+
let fileName;
|
| 18 |
+
|
| 19 |
+
if (request.method === 'POST') {
|
| 20 |
+
const data = await request.file(); // Membutuhkan @fastify/multipart
|
| 21 |
+
if (!data) throw new Error("No file uploaded");
|
| 22 |
+
fileData = await data.toBuffer();
|
| 23 |
+
fileName = data.filename;
|
| 24 |
+
} else {
|
| 25 |
+
const { image } = request.query;
|
| 26 |
+
if (!image) throw new Error("Query 'image' (URL) diperlukan");
|
| 27 |
+
const res = await fetch(image);
|
| 28 |
+
fileData = await res.buffer();
|
| 29 |
+
fileName = "url_upload.png";
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
// 1. Upload ke Gradio
|
| 33 |
+
const form = new FormData();
|
| 34 |
+
form.append('files', fileData, { filename: fileName });
|
| 35 |
+
|
| 36 |
+
const uploadRes = await fetch(`${API_BASE}/upload?upload_id=${session_hash}`, {
|
| 37 |
+
method: "POST",
|
| 38 |
+
body: form,
|
| 39 |
+
headers: form.getHeaders()
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
const uploadData = await uploadRes.json();
|
| 43 |
+
const remotePath = uploadData[0];
|
| 44 |
+
|
| 45 |
+
// 2. Join Antrean
|
| 46 |
+
const payload = {
|
| 47 |
+
"data": [null, {
|
| 48 |
+
"path": remotePath,
|
| 49 |
+
"url": `${HF_DOMAIN}/gradio_api/file=${remotePath}`,
|
| 50 |
+
"orig_name": fileName,
|
| 51 |
+
"size": fileData.length,
|
| 52 |
+
"mime_type": "image/png",
|
| 53 |
+
"meta": { "_type": "gradio.FileData" }
|
| 54 |
+
}, "📋 Markdown", null, 1],
|
| 55 |
+
"fn_index": 6,
|
| 56 |
+
"session_hash": session_hash
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
await fetch(`${API_BASE}/queue/join`, {
|
| 60 |
+
method: "POST",
|
| 61 |
+
headers: { "Content-Type": "application/json" },
|
| 62 |
+
body: JSON.stringify(payload)
|
| 63 |
+
});
|
| 64 |
+
|
| 65 |
+
// 3. Stream Response
|
| 66 |
+
return new Promise((resolve, reject) => {
|
| 67 |
+
const streamUrl = `${API_BASE}/queue/data?session_hash=${session_hash}`;
|
| 68 |
+
fetch(streamUrl).then(res => {
|
| 69 |
+
res.body.on('data', (chunk) => {
|
| 70 |
+
const lines = chunk.toString().split("\n");
|
| 71 |
+
for (let line of lines) {
|
| 72 |
+
if (line.includes('"process_completed"')) {
|
| 73 |
+
const json = JSON.parse(line.replace("data: ", ""));
|
| 74 |
+
resolve({ status: "success", result: json.output.data[0] });
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
});
|
| 78 |
+
});
|
| 79 |
+
setTimeout(() => reject(new Error("Timeout")), 60000);
|
| 80 |
+
});
|
| 81 |
+
|
| 82 |
+
} catch (err) {
|
| 83 |
+
return { status: "error", message: err.message };
|
| 84 |
+
}
|
| 85 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
};
|
plugins/index.ejs
CHANGED
|
@@ -1,228 +1,228 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>API Plugins Dashboard</title>
|
| 7 |
-
<style>
|
| 8 |
-
:root {
|
| 9 |
-
--bg: #0d1117;
|
| 10 |
-
--card-bg: #161b22;
|
| 11 |
-
--text: #c9d1d9;
|
| 12 |
-
--accent: #58a6ff;
|
| 13 |
-
--success: #238636;
|
| 14 |
-
--border: #30363d;
|
| 15 |
-
--code-bg: #010409;
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
body {
|
| 19 |
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
| 20 |
-
background: var(--bg);
|
| 21 |
-
color: var(--text);
|
| 22 |
-
padding: 40px;
|
| 23 |
-
margin: 0;
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
h1 {
|
| 27 |
-
margin-bottom: 30px;
|
| 28 |
-
text-align: center;
|
| 29 |
-
color: var(--accent);
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
.grid {
|
| 33 |
-
display: grid;
|
| 34 |
-
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
| 35 |
-
gap: 25px;
|
| 36 |
-
max-width: 1200px;
|
| 37 |
-
margin: 0 auto;
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
.card {
|
| 41 |
-
background: var(--card-bg);
|
| 42 |
-
padding: 24px;
|
| 43 |
-
border-radius: 12px;
|
| 44 |
-
border: 1px solid var(--border);
|
| 45 |
-
transition: transform 0.2s, border-color 0.2s;
|
| 46 |
-
display: flex;
|
| 47 |
-
flex-direction: column;
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
.card:hover {
|
| 51 |
-
border-color: var(--accent);
|
| 52 |
-
transform: translateY(-5px);
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
.method-badge {
|
| 56 |
-
font-weight: bold;
|
| 57 |
-
color: var(--success);
|
| 58 |
-
background: rgba(35, 134, 54, 0.1);
|
| 59 |
-
padding: 2px 8px;
|
| 60 |
-
border-radius: 6px;
|
| 61 |
-
font-size: 12px;
|
| 62 |
-
margin-right: 8px;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
.path {
|
| 66 |
-
color: var(--accent);
|
| 67 |
-
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
|
| 68 |
-
font-size: 14px;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
h3 { margin: 15px 0 10px 0; font-size: 1.2rem; }
|
| 72 |
-
|
| 73 |
-
small { color: #8b949e; margin-bottom: 20px; display: block; min-height: 40px; }
|
| 74 |
-
|
| 75 |
-
.test-input {
|
| 76 |
-
width: 100%;
|
| 77 |
-
background: var(--code-bg);
|
| 78 |
-
border: 1px solid var(--border);
|
| 79 |
-
color: white;
|
| 80 |
-
padding: 12px;
|
| 81 |
-
border-radius: 6px;
|
| 82 |
-
margin-bottom: 12px;
|
| 83 |
-
box-sizing: border-box;
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
.btn-run {
|
| 87 |
-
background: var(--success);
|
| 88 |
-
color: white;
|
| 89 |
-
border: none;
|
| 90 |
-
padding: 12px;
|
| 91 |
-
border-radius: 6px;
|
| 92 |
-
cursor: pointer;
|
| 93 |
-
font-weight: bold;
|
| 94 |
-
width: 100%;
|
| 95 |
-
transition: opacity 0.2s;
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
.btn-run:hover { opacity: 0.9; }
|
| 99 |
-
|
| 100 |
-
.result-box {
|
| 101 |
-
margin-top: 20px;
|
| 102 |
-
background: var(--code-bg);
|
| 103 |
-
border-radius: 8px;
|
| 104 |
-
padding: 15px;
|
| 105 |
-
display: none;
|
| 106 |
-
max-height: 400px;
|
| 107 |
-
overflow-y: auto;
|
| 108 |
-
border: 1px solid var(--border);
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
.status { font-size: 13px; margin-bottom: 10px; font-style: italic; }
|
| 112 |
-
|
| 113 |
-
pre {
|
| 114 |
-
font-size: 12px;
|
| 115 |
-
white-space: pre-wrap;
|
| 116 |
-
word-break: break-all;
|
| 117 |
-
color: #d1d5da;
|
| 118 |
-
margin: 0;
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
.preview-img {
|
| 122 |
-
margin-top: 15px;
|
| 123 |
-
width: 100%;
|
| 124 |
-
border-radius: 8px;
|
| 125 |
-
border: 1px solid var(--border);
|
| 126 |
-
}
|
| 127 |
-
</style>
|
| 128 |
-
</head>
|
| 129 |
-
<body>
|
| 130 |
-
<h1>API Plugins Dashboard</h1>
|
| 131 |
-
|
| 132 |
-
<div class="grid">
|
| 133 |
-
<% plugins.forEach((plugin, index) => { %>
|
| 134 |
-
<div class="card">
|
| 135 |
-
<div>
|
| 136 |
-
<span class="method-badge"><%= Array.isArray(plugin.method) ? plugin.method.join('/') : plugin.method %></span>
|
| 137 |
-
<span class="path"><%= plugin.path %></span>
|
| 138 |
-
</div>
|
| 139 |
-
|
| 140 |
-
<h3><%= plugin.name.toUpperCase().replace(/_/g, ' ') %></h3>
|
| 141 |
-
<small><%= plugin.description %></small>
|
| 142 |
-
|
| 143 |
-
<div class="form-container">
|
| 144 |
-
<% if (plugin.path.includes('ocr')) { %>
|
| 145 |
-
<input type="text" id="url-<%= index %>" class="test-input" placeholder="Paste image URL...">
|
| 146 |
-
<div style="text-align: center; margin: 5px 0; font-size: 11px; color: #8b949e;">OR</div>
|
| 147 |
-
<input type="file" id="file-<%= index %>" class="test-input" accept="image/*">
|
| 148 |
-
<% } else { %>
|
| 149 |
-
<input type="text" id="input-<%= index %>" class="test-input"
|
| 150 |
-
placeholder="<%= plugin.path.includes('bonsai') ? 'Tanya sesuatu...' : 'Masukkan prompt gambar...' %>">
|
| 151 |
-
<% } %>
|
| 152 |
-
|
| 153 |
-
<button class="btn-run" onclick="runTest('<%= plugin.path %>', <%= index %>)">Run Plugin</button>
|
| 154 |
-
</div>
|
| 155 |
-
|
| 156 |
-
<div class="result-box" id="result-container-<%= index %>">
|
| 157 |
-
<div id="status-<%= index %>" class="status"></div>
|
| 158 |
-
<pre id="json-<%= index %>"></pre>
|
| 159 |
-
<div id="media-<%= index %>"></div>
|
| 160 |
-
</div>
|
| 161 |
-
</div>
|
| 162 |
-
<% }) %>
|
| 163 |
-
</div>
|
| 164 |
-
|
| 165 |
-
<script>
|
| 166 |
-
async function runTest(path, id) {
|
| 167 |
-
const container = document.getElementById(`result-container-${id}`);
|
| 168 |
-
const status = document.getElementById(`status-${id}`);
|
| 169 |
-
const jsonPre = document.getElementById(`json-${id}`);
|
| 170 |
-
const media = document.getElementById(`media-${id}`);
|
| 171 |
-
|
| 172 |
-
// Reset UI
|
| 173 |
-
container.style.display = 'block';
|
| 174 |
-
status.innerHTML = '⏳ Processing...';
|
| 175 |
-
jsonPre.innerText = '';
|
| 176 |
-
media.innerHTML = '';
|
| 177 |
-
|
| 178 |
-
try {
|
| 179 |
-
let response;
|
| 180 |
-
|
| 181 |
-
// Logika khusus OCR (DeepSeek)
|
| 182 |
-
if (path.includes('ocr')) {
|
| 183 |
-
const urlVal = document.getElementById(`url-${id}`).value;
|
| 184 |
-
const fileInput = document.getElementById(`file-${id}`).files[0];
|
| 185 |
-
|
| 186 |
-
if (fileInput) {
|
| 187 |
-
// POST: Kirim file lokal
|
| 188 |
-
const formData = new FormData();
|
| 189 |
-
formData.append('file', fileInput);
|
| 190 |
-
response = await fetch(path, { method: 'POST', body: formData });
|
| 191 |
-
} else if (urlVal) {
|
| 192 |
-
// GET: Kirim URL gambar
|
| 193 |
-
response = await fetch(`${path}?image=${encodeURIComponent(urlVal)}`);
|
| 194 |
-
} else {
|
| 195 |
-
throw new Error("Pilih file atau masukkan URL gambar!");
|
| 196 |
-
}
|
| 197 |
-
}
|
| 198 |
-
// Logika untuk plugin lainnya
|
| 199 |
-
else {
|
| 200 |
-
const val = document.getElementById(`input-${id}`).value;
|
| 201 |
-
// Pilih param 'q' untuk bonsai/chat, 'prompt' untuk gen image
|
| 202 |
-
const param = (path.includes('bonsai') || path.includes('chat')) ? 'q' : 'prompt';
|
| 203 |
-
response = await fetch(`${path}?${param}=${encodeURIComponent(val)}`);
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
const data = await response.json();
|
| 207 |
-
status.innerHTML = response.ok ? '✅ Success' : '❌ Failed';
|
| 208 |
-
jsonPre.innerText = JSON.stringify(data, null, 2);
|
| 209 |
-
|
| 210 |
-
// Preview Gambar jika ada (Illustrious/NSFW)
|
| 211 |
-
const imgs = data.images || (data.result && Array.isArray(data.result) ? data.result : null);
|
| 212 |
-
if (imgs && Array.isArray(imgs)) {
|
| 213 |
-
imgs.forEach(url => {
|
| 214 |
-
const img = document.createElement('img');
|
| 215 |
-
img.src = url;
|
| 216 |
-
img.className = 'preview-img';
|
| 217 |
-
media.appendChild(img);
|
| 218 |
-
});
|
| 219 |
-
}
|
| 220 |
-
|
| 221 |
-
} catch (err) {
|
| 222 |
-
status.innerHTML = '❌ Error';
|
| 223 |
-
jsonPre.innerText = err.message;
|
| 224 |
-
}
|
| 225 |
-
}
|
| 226 |
-
</script>
|
| 227 |
-
</body>
|
| 228 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>API Plugins Dashboard</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root {
|
| 9 |
+
--bg: #0d1117;
|
| 10 |
+
--card-bg: #161b22;
|
| 11 |
+
--text: #c9d1d9;
|
| 12 |
+
--accent: #58a6ff;
|
| 13 |
+
--success: #238636;
|
| 14 |
+
--border: #30363d;
|
| 15 |
+
--code-bg: #010409;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
body {
|
| 19 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
| 20 |
+
background: var(--bg);
|
| 21 |
+
color: var(--text);
|
| 22 |
+
padding: 40px;
|
| 23 |
+
margin: 0;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
h1 {
|
| 27 |
+
margin-bottom: 30px;
|
| 28 |
+
text-align: center;
|
| 29 |
+
color: var(--accent);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.grid {
|
| 33 |
+
display: grid;
|
| 34 |
+
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
| 35 |
+
gap: 25px;
|
| 36 |
+
max-width: 1200px;
|
| 37 |
+
margin: 0 auto;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.card {
|
| 41 |
+
background: var(--card-bg);
|
| 42 |
+
padding: 24px;
|
| 43 |
+
border-radius: 12px;
|
| 44 |
+
border: 1px solid var(--border);
|
| 45 |
+
transition: transform 0.2s, border-color 0.2s;
|
| 46 |
+
display: flex;
|
| 47 |
+
flex-direction: column;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.card:hover {
|
| 51 |
+
border-color: var(--accent);
|
| 52 |
+
transform: translateY(-5px);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.method-badge {
|
| 56 |
+
font-weight: bold;
|
| 57 |
+
color: var(--success);
|
| 58 |
+
background: rgba(35, 134, 54, 0.1);
|
| 59 |
+
padding: 2px 8px;
|
| 60 |
+
border-radius: 6px;
|
| 61 |
+
font-size: 12px;
|
| 62 |
+
margin-right: 8px;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
.path {
|
| 66 |
+
color: var(--accent);
|
| 67 |
+
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
|
| 68 |
+
font-size: 14px;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
h3 { margin: 15px 0 10px 0; font-size: 1.2rem; }
|
| 72 |
+
|
| 73 |
+
small { color: #8b949e; margin-bottom: 20px; display: block; min-height: 40px; }
|
| 74 |
+
|
| 75 |
+
.test-input {
|
| 76 |
+
width: 100%;
|
| 77 |
+
background: var(--code-bg);
|
| 78 |
+
border: 1px solid var(--border);
|
| 79 |
+
color: white;
|
| 80 |
+
padding: 12px;
|
| 81 |
+
border-radius: 6px;
|
| 82 |
+
margin-bottom: 12px;
|
| 83 |
+
box-sizing: border-box;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.btn-run {
|
| 87 |
+
background: var(--success);
|
| 88 |
+
color: white;
|
| 89 |
+
border: none;
|
| 90 |
+
padding: 12px;
|
| 91 |
+
border-radius: 6px;
|
| 92 |
+
cursor: pointer;
|
| 93 |
+
font-weight: bold;
|
| 94 |
+
width: 100%;
|
| 95 |
+
transition: opacity 0.2s;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn-run:hover { opacity: 0.9; }
|
| 99 |
+
|
| 100 |
+
.result-box {
|
| 101 |
+
margin-top: 20px;
|
| 102 |
+
background: var(--code-bg);
|
| 103 |
+
border-radius: 8px;
|
| 104 |
+
padding: 15px;
|
| 105 |
+
display: none;
|
| 106 |
+
max-height: 400px;
|
| 107 |
+
overflow-y: auto;
|
| 108 |
+
border: 1px solid var(--border);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
.status { font-size: 13px; margin-bottom: 10px; font-style: italic; }
|
| 112 |
+
|
| 113 |
+
pre {
|
| 114 |
+
font-size: 12px;
|
| 115 |
+
white-space: pre-wrap;
|
| 116 |
+
word-break: break-all;
|
| 117 |
+
color: #d1d5da;
|
| 118 |
+
margin: 0;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
.preview-img {
|
| 122 |
+
margin-top: 15px;
|
| 123 |
+
width: 100%;
|
| 124 |
+
border-radius: 8px;
|
| 125 |
+
border: 1px solid var(--border);
|
| 126 |
+
}
|
| 127 |
+
</style>
|
| 128 |
+
</head>
|
| 129 |
+
<body>
|
| 130 |
+
<h1>API Plugins Dashboard</h1>
|
| 131 |
+
|
| 132 |
+
<div class="grid">
|
| 133 |
+
<% plugins.forEach((plugin, index) => { %>
|
| 134 |
+
<div class="card">
|
| 135 |
+
<div>
|
| 136 |
+
<span class="method-badge"><%= Array.isArray(plugin.method) ? plugin.method.join('/') : plugin.method %></span>
|
| 137 |
+
<span class="path"><%= plugin.path %></span>
|
| 138 |
+
</div>
|
| 139 |
+
|
| 140 |
+
<h3><%= plugin.name.toUpperCase().replace(/_/g, ' ') %></h3>
|
| 141 |
+
<small><%= plugin.description %></small>
|
| 142 |
+
|
| 143 |
+
<div class="form-container">
|
| 144 |
+
<% if (plugin.path.includes('ocr')) { %>
|
| 145 |
+
<input type="text" id="url-<%= index %>" class="test-input" placeholder="Paste image URL...">
|
| 146 |
+
<div style="text-align: center; margin: 5px 0; font-size: 11px; color: #8b949e;">OR</div>
|
| 147 |
+
<input type="file" id="file-<%= index %>" class="test-input" accept="image/*">
|
| 148 |
+
<% } else { %>
|
| 149 |
+
<input type="text" id="input-<%= index %>" class="test-input"
|
| 150 |
+
placeholder="<%= plugin.path.includes('bonsai') ? 'Tanya sesuatu...' : 'Masukkan prompt gambar...' %>">
|
| 151 |
+
<% } %>
|
| 152 |
+
|
| 153 |
+
<button class="btn-run" onclick="runTest('<%= plugin.path %>', <%= index %>)">Run Plugin</button>
|
| 154 |
+
</div>
|
| 155 |
+
|
| 156 |
+
<div class="result-box" id="result-container-<%= index %>">
|
| 157 |
+
<div id="status-<%= index %>" class="status"></div>
|
| 158 |
+
<pre id="json-<%= index %>"></pre>
|
| 159 |
+
<div id="media-<%= index %>"></div>
|
| 160 |
+
</div>
|
| 161 |
+
</div>
|
| 162 |
+
<% }) %>
|
| 163 |
+
</div>
|
| 164 |
+
|
| 165 |
+
<script>
|
| 166 |
+
async function runTest(path, id) {
|
| 167 |
+
const container = document.getElementById(`result-container-${id}`);
|
| 168 |
+
const status = document.getElementById(`status-${id}`);
|
| 169 |
+
const jsonPre = document.getElementById(`json-${id}`);
|
| 170 |
+
const media = document.getElementById(`media-${id}`);
|
| 171 |
+
|
| 172 |
+
// Reset UI
|
| 173 |
+
container.style.display = 'block';
|
| 174 |
+
status.innerHTML = '⏳ Processing...';
|
| 175 |
+
jsonPre.innerText = '';
|
| 176 |
+
media.innerHTML = '';
|
| 177 |
+
|
| 178 |
+
try {
|
| 179 |
+
let response;
|
| 180 |
+
|
| 181 |
+
// Logika khusus OCR (DeepSeek)
|
| 182 |
+
if (path.includes('ocr')) {
|
| 183 |
+
const urlVal = document.getElementById(`url-${id}`).value;
|
| 184 |
+
const fileInput = document.getElementById(`file-${id}`).files[0];
|
| 185 |
+
|
| 186 |
+
if (fileInput) {
|
| 187 |
+
// POST: Kirim file lokal
|
| 188 |
+
const formData = new FormData();
|
| 189 |
+
formData.append('file', fileInput);
|
| 190 |
+
response = await fetch(path, { method: 'POST', body: formData });
|
| 191 |
+
} else if (urlVal) {
|
| 192 |
+
// GET: Kirim URL gambar
|
| 193 |
+
response = await fetch(`${path}?image=${encodeURIComponent(urlVal)}`);
|
| 194 |
+
} else {
|
| 195 |
+
throw new Error("Pilih file atau masukkan URL gambar!");
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
// Logika untuk plugin lainnya
|
| 199 |
+
else {
|
| 200 |
+
const val = document.getElementById(`input-${id}`).value;
|
| 201 |
+
// Pilih param 'q' untuk bonsai/chat, 'prompt' untuk gen image
|
| 202 |
+
const param = (path.includes('bonsai') || path.includes('chat')) ? 'q' : 'prompt';
|
| 203 |
+
response = await fetch(`${path}?${param}=${encodeURIComponent(val)}`);
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
const data = await response.json();
|
| 207 |
+
status.innerHTML = response.ok ? '✅ Success' : '❌ Failed';
|
| 208 |
+
jsonPre.innerText = JSON.stringify(data, null, 2);
|
| 209 |
+
|
| 210 |
+
// Preview Gambar jika ada (Illustrious/NSFW)
|
| 211 |
+
const imgs = data.images || (data.result && Array.isArray(data.result) ? data.result : null);
|
| 212 |
+
if (imgs && Array.isArray(imgs)) {
|
| 213 |
+
imgs.forEach(url => {
|
| 214 |
+
const img = document.createElement('img');
|
| 215 |
+
img.src = url;
|
| 216 |
+
img.className = 'preview-img';
|
| 217 |
+
media.appendChild(img);
|
| 218 |
+
});
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
} catch (err) {
|
| 222 |
+
status.innerHTML = '❌ Error';
|
| 223 |
+
jsonPre.innerText = err.message;
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
</script>
|
| 227 |
+
</body>
|
| 228 |
</html>
|