fix streaming query bug

This commit is contained in:
syuilo 2022-01-02 02:11:35 +09:00
parent a05f47d5cc
commit f3640add23

View File

@ -3,13 +3,13 @@ import { EventEmitter } from 'eventemitter3';
import ReconnectingWebsocket from 'reconnecting-websocket'; import ReconnectingWebsocket from 'reconnecting-websocket';
import { BroadcastEvents, Channels } from './streaming.types'; import { BroadcastEvents, Channels } from './streaming.types';
export function urlQuery(obj: Record<string, unknown>): string { export function urlQuery(obj: Record<string, string | number | boolean | undefined>): string {
const params = Object.entries(obj) const params = Object.entries(obj)
.filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined) .filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined)
.reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, unknown>); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.reduce((a, [k, v]) => (a[k] = v!, a), {} as Record<string, string | number | boolean>);
return Object.entries(params) return Object.entries(params)
.map((e) => `${e[0]}=${e[1]}`)
.map((e) => `${e[0]}=${encodeURIComponent(e[1])}`) .map((e) => `${e[0]}=${encodeURIComponent(e[1])}`)
.join('&'); .join('&');
} }