s
This commit is contained in:
@@ -13,15 +13,25 @@ export type YoutubeProChannel = {
|
||||
};
|
||||
|
||||
const STORAGE_KEY = "live-hub-youtube-pro-v2";
|
||||
const YOUTUBE_PRO_PM2_PREFIX = "youtube2__";
|
||||
const PM2_SANITIZE_RE = /[^a-zA-Z0-9_.-]+/g;
|
||||
const RESERVED_PRO_PM2_NAMES = new Set(["youtube", "douyin_youtube", "tiktok", "obs", "web"]);
|
||||
|
||||
export function sanitizeYoutubePm2Name(value: string): string {
|
||||
return (value || "").trim().replace(PM2_SANITIZE_RE, "_");
|
||||
}
|
||||
|
||||
export function normalizeYoutubeProPm2Name(value: string, channelId: string): string {
|
||||
const raw = sanitizeYoutubePm2Name(value);
|
||||
if (!raw || RESERVED_PRO_PM2_NAMES.has(raw) || raw === YOUTUBE_PRO_PM2_PREFIX) {
|
||||
return defaultPm2NameForChannel(channelId);
|
||||
}
|
||||
if (raw.startsWith(YOUTUBE_PRO_PM2_PREFIX)) return raw;
|
||||
return defaultPm2NameForChannel(raw);
|
||||
}
|
||||
|
||||
export function resolveYoutubeProChannelPm2(channel: Pick<YoutubeProChannel, "id" | "pm2Name">): string {
|
||||
const raw = sanitizeYoutubePm2Name(String(channel.pm2Name || ""));
|
||||
return raw || defaultPm2NameForChannel(String(channel.id || ""));
|
||||
return normalizeYoutubeProPm2Name(String(channel.pm2Name || ""), String(channel.id || ""));
|
||||
}
|
||||
|
||||
export function parseYoutubeProChannelList(raw: unknown): YoutubeProChannel[] {
|
||||
@@ -42,7 +52,7 @@ function migrateRow(x: Record<string, unknown>): YoutubeProChannel | null {
|
||||
streamKeySuffix: typeof x.streamKeySuffix === "string" ? x.streamKeySuffix : undefined,
|
||||
streamKey: typeof x.streamKey === "string" ? x.streamKey : undefined,
|
||||
urlLines: typeof x.urlLines === "string" ? x.urlLines : undefined,
|
||||
pm2Name: typeof x.pm2Name === "string" ? x.pm2Name : undefined,
|
||||
pm2Name: normalizeYoutubeProPm2Name(typeof x.pm2Name === "string" ? x.pm2Name : "", id),
|
||||
notes: typeof x.notes === "string" ? x.notes : undefined,
|
||||
};
|
||||
}
|
||||
@@ -126,5 +136,5 @@ export function newChannelId(): string {
|
||||
}
|
||||
|
||||
export function defaultPm2NameForChannel(channelId: string): string {
|
||||
return `youtube2__${sanitizeYoutubePm2Name(channelId) || "channel"}`;
|
||||
return `${YOUTUBE_PRO_PM2_PREFIX}${sanitizeYoutubePm2Name(channelId) || "channel"}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user