mirror of
https://github.com/MisskeyIO/misskey
synced 2024-11-23 14:46:40 +09:00
Fix code scanning alert no. 27: DOM text reinterpreted as HTML (MisskeyIO#801)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
parent
443335c662
commit
ee135b7e3c
@ -11,6 +11,15 @@ import { RateLimiter } from '@/scripts/rate-limiter.js';
|
||||
let ctx: AudioContext;
|
||||
const cache = new Map<string, AudioBuffer>();
|
||||
|
||||
function isValidUrl(url: string): boolean {
|
||||
try {
|
||||
new URL(url);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export const soundsTypes = [
|
||||
// 音声なし
|
||||
null,
|
||||
@ -260,8 +269,12 @@ export function createSourceNode(buffer: AudioBuffer, opts: {
|
||||
*/
|
||||
export async function getSoundDuration(file: string): Promise<number> {
|
||||
const audioEl = document.createElement('audio');
|
||||
audioEl.src = file;
|
||||
return new Promise((resolve) => {
|
||||
audioEl.src = isValidUrl(file) ? file : '';
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!audioEl.src) {
|
||||
reject(new Error('Invalid URL'));
|
||||
return;
|
||||
}
|
||||
const si = setInterval(() => {
|
||||
if (audioEl.readyState > 0) {
|
||||
resolve(audioEl.duration * 1000);
|
||||
|
Loading…
Reference in New Issue
Block a user