Update plugins/carbon.js
Browse files- plugins/carbon.js +11 -6
plugins/carbon.js
CHANGED
@@ -5,12 +5,17 @@ import { Readable } from "stream";
|
|
5 |
import sharp from "sharp";
|
6 |
const CarbonRoutes = express.Router();
|
7 |
|
|
|
|
|
|
|
|
|
|
|
8 |
async function MakerCarbon(args) {
|
9 |
const url = ParametersUrl("maker/carbon");
|
10 |
try {
|
11 |
-
const
|
|
|
12 |
method: "GET",
|
13 |
-
body: JSON.stringify({ code: args }),
|
14 |
});
|
15 |
|
16 |
if (!response.ok) {
|
@@ -37,7 +42,7 @@ async function MakerCarbon(args) {
|
|
37 |
* schema:
|
38 |
* type: object
|
39 |
* properties:
|
40 |
-
*
|
41 |
* type: string
|
42 |
* description: null.
|
43 |
* responses:
|
@@ -55,12 +60,12 @@ async function MakerCarbon(args) {
|
|
55 |
*/
|
56 |
CarbonRoutes.post("/api/v1/maker/carbon", async (req, res) => {
|
57 |
try {
|
58 |
-
const
|
59 |
-
if (!
|
60 |
return res.status(400).send("Query parameter is missing");
|
61 |
}
|
62 |
|
63 |
-
const imageBytes = await MakerCarbon(
|
64 |
if (!imageBytes) {
|
65 |
return res.status(500).json({ error: "Failed to fetch image bytes" });
|
66 |
}
|
|
|
5 |
import sharp from "sharp";
|
6 |
const CarbonRoutes = express.Router();
|
7 |
|
8 |
+
function paramCode(code) {
|
9 |
+
const params = new URLSearchParams({ code: code });
|
10 |
+
return params
|
11 |
+
}
|
12 |
+
|
13 |
async function MakerCarbon(args) {
|
14 |
const url = ParametersUrl("maker/carbon");
|
15 |
try {
|
16 |
+
const params = paramCode(args);
|
17 |
+
const response = await fetch(`${url}?${params}`, {
|
18 |
method: "GET",
|
|
|
19 |
});
|
20 |
|
21 |
if (!response.ok) {
|
|
|
42 |
* schema:
|
43 |
* type: object
|
44 |
* properties:
|
45 |
+
* code:
|
46 |
* type: string
|
47 |
* description: null.
|
48 |
* responses:
|
|
|
60 |
*/
|
61 |
CarbonRoutes.post("/api/v1/maker/carbon", async (req, res) => {
|
62 |
try {
|
63 |
+
const code = req.body.code;
|
64 |
+
if (!code) {
|
65 |
return res.status(400).send("Query parameter is missing");
|
66 |
}
|
67 |
|
68 |
+
const imageBytes = await MakerCarbon(code);
|
69 |
if (!imageBytes) {
|
70 |
return res.status(500).json({ error: "Failed to fetch image bytes" });
|
71 |
}
|