Update plugins/gptold.js
Browse files- plugins/gptold.js +13 -4
plugins/gptold.js
CHANGED
@@ -12,6 +12,7 @@ import { authenticateApiKey, authenticateApiKeyPremium, apiLimiter } from '../mi
|
|
12 |
const GptRoutes = express.Router();
|
13 |
|
14 |
import fs from "fs";
|
|
|
15 |
|
16 |
/**
|
17 |
* @swagger
|
@@ -37,20 +38,28 @@ import fs from "fs";
|
|
37 |
* description: Success
|
38 |
*/
|
39 |
GptRoutes.get("/api/v1/ai/openai/whisper-large-v3-turbo", authenticateApiKey, apiLimiter, async (req, res) => {
|
40 |
-
API_BASE_URL = `https://api.cloudflare.com/client/v4/accounts/${process.env['ACCOUNT_ID']}/ai/run/@cf/openai/whisper-large-v3-turbo
|
41 |
-
headers = {
|
|
|
|
|
42 |
const url = req.query.url;
|
43 |
|
44 |
const path = await audioContent(url);
|
45 |
if (!path) {
|
46 |
return res.status(500).json({ error: "Failed to download audio file" });
|
47 |
}
|
|
|
48 |
try {
|
49 |
const audioBytes = fs.readFileSync(path);
|
50 |
const audioBase64 = Buffer.from(audioBytes).toString("base64");
|
|
|
51 |
const inputData = { audio: audioBase64 };
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
54 |
} catch (error) {
|
55 |
console.error("Error making API request:", error.message);
|
56 |
return res.status(500).json({ error: null });
|
|
|
12 |
const GptRoutes = express.Router();
|
13 |
|
14 |
import fs from "fs";
|
15 |
+
import got from "got";
|
16 |
|
17 |
/**
|
18 |
* @swagger
|
|
|
38 |
* description: Success
|
39 |
*/
|
40 |
GptRoutes.get("/api/v1/ai/openai/whisper-large-v3-turbo", authenticateApiKey, apiLimiter, async (req, res) => {
|
41 |
+
const API_BASE_URL = `https://api.cloudflare.com/client/v4/accounts/${process.env['ACCOUNT_ID']}/ai/run/@cf/openai/whisper-large-v3-turbo`;
|
42 |
+
const headers = {
|
43 |
+
Authorization: `Bearer ${process.env['CLOUDFLARE_API_KEY']}`,
|
44 |
+
};
|
45 |
const url = req.query.url;
|
46 |
|
47 |
const path = await audioContent(url);
|
48 |
if (!path) {
|
49 |
return res.status(500).json({ error: "Failed to download audio file" });
|
50 |
}
|
51 |
+
|
52 |
try {
|
53 |
const audioBytes = fs.readFileSync(path);
|
54 |
const audioBase64 = Buffer.from(audioBytes).toString("base64");
|
55 |
+
|
56 |
const inputData = { audio: audioBase64 };
|
57 |
+
|
58 |
+
const response = await got.post(API_BASE_URL, {
|
59 |
+
headers,
|
60 |
+
json: inputData,
|
61 |
+
}).json();
|
62 |
+
return res.json(response);
|
63 |
} catch (error) {
|
64 |
console.error("Error making API request:", error.message);
|
65 |
return res.status(500).json({ error: null });
|