Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as cheerio from 'cheerio';
|
|
| 3 |
import { createRequire } from 'module';
|
| 4 |
import os from 'os';
|
| 5 |
import express from 'express';
|
| 6 |
-
import { promisify } from 'util';
|
| 7 |
import { fileTypeFromBuffer } from 'file-type';
|
| 8 |
import ffmpeg from 'fluent-ffmpeg';
|
| 9 |
import nodeID3 from 'node-id3';
|
|
@@ -130,19 +130,12 @@ app.post("/eval", async (req, res) => {
|
|
| 130 |
|
| 131 |
let _return;
|
| 132 |
try {
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
reject(err);
|
| 140 |
-
}
|
| 141 |
-
})
|
| 142 |
-
: eval(code); // Untuk kode tanpa await
|
| 143 |
-
} catch (err) {
|
| 144 |
-
_return = err.toString();
|
| 145 |
-
}
|
| 146 |
|
| 147 |
// Handle Buffer atau Base64
|
| 148 |
if (Buffer.isBuffer(_return) || typeof _return === "string" && _return.startsWith("data:")) {
|
|
@@ -165,9 +158,9 @@ app.post("/eval", async (req, res) => {
|
|
| 165 |
case "json":
|
| 166 |
try {
|
| 167 |
const jsonFormatted = typeof _return === "string" ? JSON.parse(_return) : _return;
|
| 168 |
-
return res.json(jsonFormatted);
|
| 169 |
} catch (err) {
|
| 170 |
-
return res.json({ error: "Invalid JSON format", result: _return });
|
| 171 |
}
|
| 172 |
|
| 173 |
case "file":
|
|
|
|
| 3 |
import { createRequire } from 'module';
|
| 4 |
import os from 'os';
|
| 5 |
import express from 'express';
|
| 6 |
+
import { promisify, format } from 'util';
|
| 7 |
import { fileTypeFromBuffer } from 'file-type';
|
| 8 |
import ffmpeg from 'fluent-ffmpeg';
|
| 9 |
import nodeID3 from 'node-id3';
|
|
|
|
| 130 |
|
| 131 |
let _return;
|
| 132 |
try {
|
| 133 |
+
_return = /await/i.test(code)
|
| 134 |
+
? eval("(async() => { " + code + " })()")
|
| 135 |
+
: eval(code);
|
| 136 |
+
} catch (e) {
|
| 137 |
+
_return = e;
|
| 138 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
// Handle Buffer atau Base64
|
| 141 |
if (Buffer.isBuffer(_return) || typeof _return === "string" && _return.startsWith("data:")) {
|
|
|
|
| 158 |
case "json":
|
| 159 |
try {
|
| 160 |
const jsonFormatted = typeof _return === "string" ? JSON.parse(_return) : _return;
|
| 161 |
+
return res.json(format(jsonFormatted));
|
| 162 |
} catch (err) {
|
| 163 |
+
return res.json({ error: "Invalid JSON format", result: format(_return) });
|
| 164 |
}
|
| 165 |
|
| 166 |
case "file":
|