style: format static/player/validate.ts
This commit is contained in:
@@ -6,21 +6,29 @@ export const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|||||||
const isStringArray = (v: unknown): v is string[] =>
|
const isStringArray = (v: unknown): v is string[] =>
|
||||||
Array.isArray(v) && v.every((item) => typeof item === "string");
|
Array.isArray(v) && v.every((item) => typeof item === "string");
|
||||||
|
|
||||||
const isSubtitleItemArray = (v: unknown): v is { lang: string; token: string }[] =>
|
const isSubtitleItemArray = (v: unknown): v is Array<{ lang: string; token: string }> =>
|
||||||
Array.isArray(v) &&
|
Array.isArray(v) &&
|
||||||
v.every(
|
v.every(
|
||||||
(item) => isRecord(item) && typeof item.lang === "string" && typeof item.token === "string",
|
(item) => isRecord(item) && typeof item.lang === "string" && typeof item.token === "string",
|
||||||
);
|
);
|
||||||
|
|
||||||
export const parseModeSources = (v: unknown): Record<string, ModeSource> => {
|
export const parseModeSources = (v: unknown): Record<string, ModeSource> => {
|
||||||
if (!isRecord(v)) return {};
|
if (!isRecord(v)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
const out: Record<string, ModeSource> = {};
|
const out: Record<string, ModeSource> = {};
|
||||||
for (const [key, value] of Object.entries(v)) {
|
for (const [key, value] of Object.entries(v)) {
|
||||||
if (!isRecord(value)) continue;
|
if (!isRecord(value)) {
|
||||||
if (typeof value.token !== "string" || value.token === "") continue;
|
continue;
|
||||||
|
}
|
||||||
|
if (typeof value.token !== "string" || value.token === "") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const subtitles = value.subtitles == null ? [] : value.subtitles;
|
const subtitles = value.subtitles == null ? [] : value.subtitles;
|
||||||
if (!isSubtitleItemArray(subtitles)) continue;
|
if (!isSubtitleItemArray(subtitles)) {
|
||||||
const qualities = value.qualities;
|
continue;
|
||||||
|
}
|
||||||
|
const { qualities } = value;
|
||||||
out[key] = {
|
out[key] = {
|
||||||
token: value.token,
|
token: value.token,
|
||||||
type: typeof value.type === "string" ? value.type : undefined,
|
type: typeof value.type === "string" ? value.type : undefined,
|
||||||
@@ -32,15 +40,21 @@ export const parseModeSources = (v: unknown): Record<string, ModeSource> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const parseSegments = (v: unknown): SkipSegment[] => {
|
export const parseSegments = (v: unknown): SkipSegment[] => {
|
||||||
if (!Array.isArray(v)) return [];
|
if (!Array.isArray(v)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
const out: SkipSegment[] = [];
|
const out: SkipSegment[] = [];
|
||||||
for (const item of v) {
|
for (const item of v) {
|
||||||
if (!isRecord(item)) continue;
|
if (!isRecord(item)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const type = typeof item.type === "string" ? item.type : "";
|
const type = typeof item.type === "string" ? item.type : "";
|
||||||
const start = typeof item.start === "number" ? item.start : Number(item.start);
|
const start = typeof item.start === "number" ? item.start : Number(item.start);
|
||||||
const end = typeof item.end === "number" ? item.end : Number(item.end);
|
const end = typeof item.end === "number" ? item.end : Number(item.end);
|
||||||
const source = typeof item.source === "string" ? item.source : undefined;
|
const source = typeof item.source === "string" ? item.source : undefined;
|
||||||
if (!type || !Number.isFinite(start) || !Number.isFinite(end)) continue;
|
if (!type || !Number.isFinite(start) || !Number.isFinite(end)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
out.push({ type, start, end, source });
|
out.push({ type, start, end, source });
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
|||||||
Reference in New Issue
Block a user