feat: add docs
This commit is contained in:
parent
55840b54e5
commit
5ee0962917
3 changed files with 189 additions and 9 deletions
30
index.ts
30
index.ts
|
|
@ -3,13 +3,25 @@ const app = new Hono()
|
|||
const joypixels = require("emoji-toolkit");
|
||||
import { mkdirSync, writeFileSync, existsSync, rmSync, readFileSync, readFile, writeFile } from 'fs'
|
||||
import { $ } from 'bun';
|
||||
import { cors } from 'hono/cors'
|
||||
import ytSearch from 'yt-search';
|
||||
import { writeMDFPWMv3 } from './mdfpwmWriter';
|
||||
let ytdlpPath = "yt-dlp"
|
||||
if(existsSync("./yt-dlp")) {
|
||||
ytdlpPath = "./yt-dlp"
|
||||
}
|
||||
const openApi = JSON.parse(readFileSync("openapi.json").toString("utf8"))
|
||||
const index = readFileSync("index.html").toString("utf8")
|
||||
|
||||
app.use("*", cors())
|
||||
|
||||
app.get("/", async (c) => {
|
||||
return c.html(index)
|
||||
})
|
||||
|
||||
app.get("/openapi.json", async (c) => {
|
||||
return c.json(openApi);
|
||||
})
|
||||
app.post("/youtube", async (c) => {
|
||||
const auth = c.req.header('Authorization')
|
||||
if (auth !== process.env.PASSWORD) {
|
||||
|
|
@ -62,14 +74,14 @@ app.post("/youtube", async (c) => {
|
|||
rmSync("test.opus")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return c.body(readFileSync(filename), {
|
||||
headers: {
|
||||
'Content-Type': `audio/vnd.${body.mdfpwm ? "m" : ""}dfpwm`,
|
||||
'Content-Disposition': `attachment; filename="${filename}"`,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
app.post('/render', async (c) => {
|
||||
const auth = c.req.header('Authorization')
|
||||
|
|
@ -100,7 +112,7 @@ app.post('/render', async (c) => {
|
|||
size = { width: w, height: h };
|
||||
|
||||
extraArgs += ` -W ${w} -H ${h}`;
|
||||
}
|
||||
}
|
||||
if(body?.extraArgs) {
|
||||
if (typeof body.extraArgs !== 'string') {
|
||||
return c.text('extraArgs must be a string', 400)
|
||||
|
|
@ -159,17 +171,17 @@ app.post('/render', async (c) => {
|
|||
if (!existsSync('cache')) {
|
||||
mkdirSync('cache');
|
||||
}
|
||||
|
||||
|
||||
writeFileSync(filename, buffer);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
return c.text('Please provide either emoji or imageUrl', 400);
|
||||
}
|
||||
|
||||
if(!existsSync(filename+".bimg")) {
|
||||
let sanjuuniPath = "sanjuuni";
|
||||
|
||||
|
||||
if(existsSync("./sanjuuni")) {
|
||||
sanjuuniPath = "./sanjuuni";
|
||||
}
|
||||
|
|
@ -182,8 +194,8 @@ app.post('/render', async (c) => {
|
|||
return c.text(bimg)
|
||||
})
|
||||
|
||||
export default {
|
||||
export default {
|
||||
port: 7427,
|
||||
host: "127.0.0.1",
|
||||
fetch: app.fetch,
|
||||
}
|
||||
fetch: app.fetch,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue