From 861fbcab41c44063de01ccfe41cf7a80acf702b6 Mon Sep 17 00:00:00 2001 From: daikei Date: Sat, 11 Feb 2023 21:09:43 +0000 Subject: [PATCH] Remove hardcoding of sounds (#9510) (#9607) Co-authored-by: Kio-td Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9607 Co-authored-by: daikei Co-committed-by: daikei --- gulpfile.js | 3 +- .../assets/sounds/None.mp3 | 0 .../assets/sounds/aisha/1.mp3 | 0 .../assets/sounds/aisha/2.mp3 | 0 .../assets/sounds/aisha/3.mp3 | 0 .../assets/sounds/noizenecio/kick_gaba.mp3 | 0 .../assets/sounds/noizenecio/kick_gaba2.mp3 | 0 .../assets/sounds/syuilo/down.mp3 | 0 .../assets/sounds/syuilo/kick.mp3 | 0 .../sounds/syuilo/pirori-square-wet.mp3 | 0 .../assets/sounds/syuilo/pirori-wet.mp3 | 0 .../assets/sounds/syuilo/pirori.mp3 | 0 .../assets/sounds/syuilo/poi1.mp3 | 0 .../assets/sounds/syuilo/poi2.mp3 | 0 .../assets/sounds/syuilo/pope1.mp3 | 0 .../assets/sounds/syuilo/pope2.mp3 | 0 .../assets/sounds/syuilo/popo.mp3 | 0 .../assets/sounds/syuilo/queue-jammed.mp3 | 0 .../assets/sounds/syuilo/reverved.mp3 | 0 .../assets/sounds/syuilo/ryukyu.mp3 | 0 .../assets/sounds/syuilo/snare.mp3 | 0 .../assets/sounds/syuilo/square-pico.mp3 | 0 .../assets/sounds/syuilo/triple.mp3 | 0 .../assets/sounds/syuilo/up.mp3 | 0 .../assets/sounds/syuilo/waon.mp3 | 0 packages/backend/src/server/api/endpoints.ts | 2 ++ .../src/server/api/endpoints/get-sounds.ts | 28 +++++++++++++++++++ packages/client/src/pages/settings/sounds.vue | 28 ++----------------- packages/client/src/scripts/sound.ts | 2 +- 29 files changed, 35 insertions(+), 28 deletions(-) rename packages/{client => backend}/assets/sounds/None.mp3 (100%) rename packages/{client => backend}/assets/sounds/aisha/1.mp3 (100%) rename packages/{client => backend}/assets/sounds/aisha/2.mp3 (100%) rename packages/{client => backend}/assets/sounds/aisha/3.mp3 (100%) rename packages/{client => backend}/assets/sounds/noizenecio/kick_gaba.mp3 (100%) rename packages/{client => backend}/assets/sounds/noizenecio/kick_gaba2.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/down.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/kick.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/pirori-square-wet.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/pirori-wet.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/pirori.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/poi1.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/poi2.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/pope1.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/pope2.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/popo.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/queue-jammed.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/reverved.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/ryukyu.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/snare.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/square-pico.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/triple.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/up.mp3 (100%) rename packages/{client => backend}/assets/sounds/syuilo/waon.mp3 (100%) create mode 100644 packages/backend/src/server/api/endpoints/get-sounds.ts diff --git a/gulpfile.js b/gulpfile.js index 89a6acb83..87063c0bc 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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', () => diff --git a/packages/client/assets/sounds/None.mp3 b/packages/backend/assets/sounds/None.mp3 similarity index 100% rename from packages/client/assets/sounds/None.mp3 rename to packages/backend/assets/sounds/None.mp3 diff --git a/packages/client/assets/sounds/aisha/1.mp3 b/packages/backend/assets/sounds/aisha/1.mp3 similarity index 100% rename from packages/client/assets/sounds/aisha/1.mp3 rename to packages/backend/assets/sounds/aisha/1.mp3 diff --git a/packages/client/assets/sounds/aisha/2.mp3 b/packages/backend/assets/sounds/aisha/2.mp3 similarity index 100% rename from packages/client/assets/sounds/aisha/2.mp3 rename to packages/backend/assets/sounds/aisha/2.mp3 diff --git a/packages/client/assets/sounds/aisha/3.mp3 b/packages/backend/assets/sounds/aisha/3.mp3 similarity index 100% rename from packages/client/assets/sounds/aisha/3.mp3 rename to packages/backend/assets/sounds/aisha/3.mp3 diff --git a/packages/client/assets/sounds/noizenecio/kick_gaba.mp3 b/packages/backend/assets/sounds/noizenecio/kick_gaba.mp3 similarity index 100% rename from packages/client/assets/sounds/noizenecio/kick_gaba.mp3 rename to packages/backend/assets/sounds/noizenecio/kick_gaba.mp3 diff --git a/packages/client/assets/sounds/noizenecio/kick_gaba2.mp3 b/packages/backend/assets/sounds/noizenecio/kick_gaba2.mp3 similarity index 100% rename from packages/client/assets/sounds/noizenecio/kick_gaba2.mp3 rename to packages/backend/assets/sounds/noizenecio/kick_gaba2.mp3 diff --git a/packages/client/assets/sounds/syuilo/down.mp3 b/packages/backend/assets/sounds/syuilo/down.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/down.mp3 rename to packages/backend/assets/sounds/syuilo/down.mp3 diff --git a/packages/client/assets/sounds/syuilo/kick.mp3 b/packages/backend/assets/sounds/syuilo/kick.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/kick.mp3 rename to packages/backend/assets/sounds/syuilo/kick.mp3 diff --git a/packages/client/assets/sounds/syuilo/pirori-square-wet.mp3 b/packages/backend/assets/sounds/syuilo/pirori-square-wet.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/pirori-square-wet.mp3 rename to packages/backend/assets/sounds/syuilo/pirori-square-wet.mp3 diff --git a/packages/client/assets/sounds/syuilo/pirori-wet.mp3 b/packages/backend/assets/sounds/syuilo/pirori-wet.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/pirori-wet.mp3 rename to packages/backend/assets/sounds/syuilo/pirori-wet.mp3 diff --git a/packages/client/assets/sounds/syuilo/pirori.mp3 b/packages/backend/assets/sounds/syuilo/pirori.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/pirori.mp3 rename to packages/backend/assets/sounds/syuilo/pirori.mp3 diff --git a/packages/client/assets/sounds/syuilo/poi1.mp3 b/packages/backend/assets/sounds/syuilo/poi1.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/poi1.mp3 rename to packages/backend/assets/sounds/syuilo/poi1.mp3 diff --git a/packages/client/assets/sounds/syuilo/poi2.mp3 b/packages/backend/assets/sounds/syuilo/poi2.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/poi2.mp3 rename to packages/backend/assets/sounds/syuilo/poi2.mp3 diff --git a/packages/client/assets/sounds/syuilo/pope1.mp3 b/packages/backend/assets/sounds/syuilo/pope1.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/pope1.mp3 rename to packages/backend/assets/sounds/syuilo/pope1.mp3 diff --git a/packages/client/assets/sounds/syuilo/pope2.mp3 b/packages/backend/assets/sounds/syuilo/pope2.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/pope2.mp3 rename to packages/backend/assets/sounds/syuilo/pope2.mp3 diff --git a/packages/client/assets/sounds/syuilo/popo.mp3 b/packages/backend/assets/sounds/syuilo/popo.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/popo.mp3 rename to packages/backend/assets/sounds/syuilo/popo.mp3 diff --git a/packages/client/assets/sounds/syuilo/queue-jammed.mp3 b/packages/backend/assets/sounds/syuilo/queue-jammed.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/queue-jammed.mp3 rename to packages/backend/assets/sounds/syuilo/queue-jammed.mp3 diff --git a/packages/client/assets/sounds/syuilo/reverved.mp3 b/packages/backend/assets/sounds/syuilo/reverved.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/reverved.mp3 rename to packages/backend/assets/sounds/syuilo/reverved.mp3 diff --git a/packages/client/assets/sounds/syuilo/ryukyu.mp3 b/packages/backend/assets/sounds/syuilo/ryukyu.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/ryukyu.mp3 rename to packages/backend/assets/sounds/syuilo/ryukyu.mp3 diff --git a/packages/client/assets/sounds/syuilo/snare.mp3 b/packages/backend/assets/sounds/syuilo/snare.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/snare.mp3 rename to packages/backend/assets/sounds/syuilo/snare.mp3 diff --git a/packages/client/assets/sounds/syuilo/square-pico.mp3 b/packages/backend/assets/sounds/syuilo/square-pico.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/square-pico.mp3 rename to packages/backend/assets/sounds/syuilo/square-pico.mp3 diff --git a/packages/client/assets/sounds/syuilo/triple.mp3 b/packages/backend/assets/sounds/syuilo/triple.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/triple.mp3 rename to packages/backend/assets/sounds/syuilo/triple.mp3 diff --git a/packages/client/assets/sounds/syuilo/up.mp3 b/packages/backend/assets/sounds/syuilo/up.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/up.mp3 rename to packages/backend/assets/sounds/syuilo/up.mp3 diff --git a/packages/client/assets/sounds/syuilo/waon.mp3 b/packages/backend/assets/sounds/syuilo/waon.mp3 similarity index 100% rename from packages/client/assets/sounds/syuilo/waon.mp3 rename to packages/backend/assets/sounds/syuilo/waon.mp3 diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts index 6ee1a977e..35ab738a2 100644 --- a/packages/backend/src/server/api/endpoints.ts +++ b/packages/backend/src/server/api/endpoints.ts @@ -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 { diff --git a/packages/backend/src/server/api/endpoints/get-sounds.ts b/packages/backend/src/server/api/endpoints/get-sounds.ts new file mode 100644 index 000000000..aa3ef24e7 --- /dev/null +++ b/packages/backend/src/server/api/endpoints/get-sounds.ts @@ -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 +}); diff --git a/packages/client/src/pages/settings/sounds.vue b/packages/client/src/pages/settings/sounds.vue index 970b75ca3..c2297e212 100644 --- a/packages/client/src/pages/settings/sounds.vue +++ b/packages/client/src/pages/settings/sounds.vue @@ -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), { diff --git a/packages/client/src/scripts/sound.ts b/packages/client/src/scripts/sound.ts index 82233dd6c..29dd181e9 100644 --- a/packages/client/src/scripts/sound.ts +++ b/packages/client/src/scripts/sound.ts @@ -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;