hippofish/packages/backend/src/server/api/endpoints/get-sounds.ts

31 lines
833 B
TypeScript
Raw Normal View History

import { readdir } from "fs/promises";
import define from "../define.js";
export const meta = {
tags: ["meta"],
requireCredential: false,
requireCredentialPrivateMode: false,
} as const;
export const paramDef = {
type: "object",
properties: {},
required: [],
} as const;
export default define(meta, paramDef, async () => {
2023-02-11 22:16:45 +01:00
const music_files: (string | null)[] = [null];
const directory = (
await readdir("./assets/sounds", { withFileTypes: true })
).filter((potentialFolder) => potentialFolder.isDirectory());
for await (const folder of directory) {
2023-02-11 22:16:45 +01:00
const files = (await readdir(`./assets/sounds/${folder.name}`)).filter(
(potentialSong) => potentialSong.endsWith(".mp3"),
);
for await (const file of files) {
2023-02-11 22:16:45 +01:00
music_files.push(`${folder.name}/${file.replace(".mp3", "")}`);
}
}
2023-02-11 22:16:45 +01:00
return music_files;
});