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;
|
let ctx: AudioContext;
|
||||||
const cache = new Map<string, AudioBuffer>();
|
const cache = new Map<string, AudioBuffer>();
|
||||||
|
|
||||||
|
function isValidUrl(url: string): boolean {
|
||||||
|
try {
|
||||||
|
new URL(url);
|
||||||
|
return true;
|
||||||
|
} catch (_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const soundsTypes = [
|
export const soundsTypes = [
|
||||||
// 音声なし
|
// 音声なし
|
||||||
null,
|
null,
|
||||||
@ -260,8 +269,12 @@ export function createSourceNode(buffer: AudioBuffer, opts: {
|
|||||||
*/
|
*/
|
||||||
export async function getSoundDuration(file: string): Promise<number> {
|
export async function getSoundDuration(file: string): Promise<number> {
|
||||||
const audioEl = document.createElement('audio');
|
const audioEl = document.createElement('audio');
|
||||||
audioEl.src = file;
|
audioEl.src = isValidUrl(file) ? file : '';
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!audioEl.src) {
|
||||||
|
reject(new Error('Invalid URL'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
const si = setInterval(() => {
|
const si = setInterval(() => {
|
||||||
if (audioEl.readyState > 0) {
|
if (audioEl.readyState > 0) {
|
||||||
resolve(audioEl.duration * 1000);
|
resolve(audioEl.duration * 1000);
|
||||||
|
Loading…
Reference in New Issue
Block a user