Remove hardcoding of sounds (#9510) (#9607)

Co-authored-by: Kio-td <kio.thedev@gmail.com>
Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9607
Co-authored-by: daikei <daikei@noreply.codeberg.org>
Co-committed-by: daikei <daikei@noreply.codeberg.org>
This commit is contained in:
daikei 2023-02-11 21:09:43 +00:00 committed by Kainoa Kanter
parent 13af804543
commit 861fbcab41
29 changed files with 35 additions and 28 deletions

View File

@ -15,8 +15,9 @@ gulp.task('copy:backend:views', () =>
gulp.src('./packages/backend/src/server/web/views/**/*').pipe(gulp.dest('./packages/backend/built/server/web/views'))
);
gulp.task('copy:backend:custom', () =>
gulp.src('./custom/assets/*').pipe(gulp.dest('./packages/backend/assets/'))
gulp.src('./custom/assets/**/*').pipe(gulp.dest('./packages/backend/assets/'))
);
gulp.task('copy:client:fonts', () =>

View File

@ -222,6 +222,7 @@ import * as ep___messaging_messages_create from "./endpoints/messaging/messages/
import * as ep___messaging_messages_delete from "./endpoints/messaging/messages/delete.js";
import * as ep___messaging_messages_read from "./endpoints/messaging/messages/read.js";
import * as ep___meta from "./endpoints/meta.js";
import * as ep___sounds from "./endpoints/get-sounds.js";
import * as ep___miauth_genToken from "./endpoints/miauth/gen-token.js";
import * as ep___mute_create from "./endpoints/mute/create.js";
import * as ep___mute_delete from "./endpoints/mute/delete.js";
@ -668,6 +669,7 @@ const eps = [
["users/stats", ep___users_stats],
["admin/drive-capacity-override", ep___admin_driveCapOverride],
["fetch-rss", ep___fetchRss],
["get-sounds", ep___sounds]
];
export interface IEndpointMeta {

View File

@ -0,0 +1,28 @@
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 () => {
const music_files: (string|null)[] = [null, ];
const directory = (await readdir('./assets/sounds', { withFileTypes: true }))
.filter(potentialFolder => potentialFolder.isDirectory())
for await (const folder of directory) {
const files = (await readdir(`./assets/sounds/${folder.name}`))
.filter(potentialSong => potentialSong.endsWith('.mp3'))
for await (const file of files) {
music_files.push(`${folder.name}/${file.replace('.mp3','')}`);
}
}
return music_files
});

View File

@ -50,32 +50,8 @@ const sounds = ref({
channel: ColdDeviceStorage.get('sound_channel'),
});
const soundsTypes = [
null,
'syuilo/up',
'syuilo/down',
'syuilo/pope1',
'syuilo/pope2',
'syuilo/waon',
'syuilo/popo',
'syuilo/triple',
'syuilo/poi1',
'syuilo/poi2',
'syuilo/pirori',
'syuilo/pirori-wet',
'syuilo/pirori-square-wet',
'syuilo/square-pico',
'syuilo/reverved',
'syuilo/ryukyu',
'syuilo/kick',
'syuilo/snare',
'syuilo/queue-jammed',
'aisha/1',
'aisha/2',
'aisha/3',
'noizenecio/kick_gaba',
'noizenecio/kick_gaba2',
];
const soundsTypes = await os.api('get-sounds')
async function edit(type) {
const { canceled, result } = await os.form(i18n.t('_sfx.' + type), {

View File

@ -7,7 +7,7 @@ export function getAudio(file: string, useCache = true): HTMLAudioElement {
if (useCache && cache.has(file)) {
audio = cache.get(file);
} else {
audio = new Audio(`/client-assets/sounds/${file}.mp3`);
audio = new Audio(`/static-assets/sounds/${file}.mp3`);
if (useCache) cache.set(file, audio);
}
return audio;