feat(v0.6): sponsor / key-provider credit toggle

Adds a new optional "🎁 Thanks to {sponsor} for providing the
{platform} key of this game." line to the generated description, for
creators who get review / press keys from publishers or developers.

- Editor: new SponsorCreditEditor (sponsor name + key platform) inside
  the Attribution accordion. Editor store v2 → v3 with a trivial
  migration that back-fills empty strings for old drafts.
- Settings: new `showSponsorCredit` toggle under Tag Settings. Off by
  default so existing users see no behaviour change. Settings store
  v3 → v4; healSettings back-fills the new default.
- Engine: `buildDescription` / `renderAll` take a `showSponsorCredit`
  option. Renders only when the toggle is on AND BOTH sponsor fields
  are non-empty — partial data is treated as "not ready, skip" rather
  than rendered with holes. Positioned above the music section and
  donate block so the thank-you is visually prominent.
- i18n: added sponsor-section UI labels/placeholders, the
  `settings.showSponsorCredit` toggle label, and
  `description.sections.sponsorCredit` template across all 6 locales
  (en, vi, ja, es, ko, zh) + schema.
- Tests: 7 new description-builder cases (render / toggle-off / blank
  name / blank platform / trim / ordering / vi localization) + 1
  healSettings case for the v3 → v4 back-fill.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 4.7 committed 2026-04-24 10:46:34 +07:00
1 parent 24055f9668
commit edea7e80ff
26 files changed
+272 -20

No files matched your search

@@ -0,0 +1,32 @@
import { useTranslation } from "react-i18next";
import { Input } from "@components/ui/Input";
import { useEditorStore } from "@store/editor-store";
/**
* Publisher/developer + platform pair for the "🎁 Thanks to …" credit
* line. Rendered in the description only when the Settings toggle
* `showSponsorCredit` is on AND both inputs are non-empty.
*/
export function SponsorCreditEditor() {
const { t } = useTranslation("ui");
const sponsorName = useEditorStore((s) => s.sponsorName);
const sponsorPlatform = useEditorStore((s) => s.sponsorPlatform);
const set = useEditorStore((s) => s.set);
return (
<div className="flex flex-col gap-2">
<Input
label={t("editor.sponsorName")}
placeholder={t("editor.sponsorNamePlaceholder")}
value={sponsorName ?? ""}
onChange={(e) => set("sponsorName", e.target.value)}
/>
<Input
label={t("editor.sponsorPlatform")}
placeholder={t("editor.sponsorPlatformPlaceholder")}
value={sponsorPlatform ?? ""}
onChange={(e) => set("sponsorPlatform", e.target.value)}
/>
</div>
);
}
+4
View File
@@ -22,6 +22,8 @@ export interface EditorDefaults {
playlistLink: string;
contactEmail: string;
musicAttribution: string;
sponsorName: string;
sponsorPlatform: string;
thumbnailText: string;
pinnedComment: string;
spoilerWarning: boolean;
@@ -59,6 +61,8 @@ export const DEFAULTS = {
playlistLink: "",
contactEmail: "",
musicAttribution: "",
sponsorName: "",
sponsorPlatform: "",
thumbnailText: "",
pinnedComment: "",
spoilerWarning: false,
+29 -1
View File
@@ -42,6 +42,9 @@ export interface BuildDescriptionOptions {
/** When true, appends a localised usage-policy block after the
* copyright line. */
showUsagePolicy?: boolean;
/** When true and both `sponsorName` and `sponsorPlatform` are set,
* emits a "🎁 Thanks to …" credit line above the music section. */
showSponsorCredit?: boolean;
}
export function buildDescription(
@@ -49,7 +52,12 @@ export function buildDescription(
t: TranslationFn,
options: BuildDescriptionOptions = {},
): string {
const { hashtagCount = 3, showCopyright = false, showUsagePolicy = false } = options;
const {
hashtagCount = 3,
showCopyright = false,
showUsagePolicy = false,
showSponsorCredit = false,
} = options;
const sections: string[] = [];
const gameName =
input.gameNameLocalized?.[input.language] ?? input.gameName;
@@ -145,6 +153,26 @@ export function buildDescription(
sections.push(t("description.sections.matureWarning"));
}
// 8.3. Sponsor credit — appears above the music / donate block so the
// "thanks to X" line stands out. Only renders when both the toggle is
// on AND the creator has filled in BOTH the sponsor name and the
// platform; partial data is treated as "not ready, skip" rather than
// rendered with holes.
if (
showSponsorCredit &&
input.sponsorName &&
input.sponsorName.trim() &&
input.sponsorPlatform &&
input.sponsorPlatform.trim()
) {
sections.push(
t("description.sections.sponsorCredit", {
sponsor: input.sponsorName.trim(),
platform: input.sponsorPlatform.trim(),
}),
);
}
// 8.5. Music / sound attribution — sits right before the donate
// block because both are "credits"-adjacent sections.
if (input.musicAttribution && input.musicAttribution.trim()) {
+7
View File
@@ -23,6 +23,12 @@ export interface RenderOptions extends TagOptions {
* (📋 USAGE POLICY) after the copyright line.
*/
showUsagePolicy?: boolean;
/**
* When true and both `sponsorName` and `sponsorPlatform` are set on
* the input, the description emits a "🎁 Thanks to …" credit line
* above the music / donate block.
*/
showSponsorCredit?: boolean;
}
export function renderAll(
@@ -35,6 +41,7 @@ export function renderAll(
hashtagCount: options?.hashtagCount,
showCopyright: options?.showCopyright,
showUsagePolicy: options?.showUsagePolicy,
showSponsorCredit: options?.showSponsorCredit,
});
const tags = generateTags(input, options);
const tagString = formatTagString(tags);
+11
View File
@@ -109,6 +109,17 @@ export interface GeneratorInput {
* before the donate links.
*/
musicAttribution?: string;
/**
* Name of the publisher / developer who provided the game key. Combined
* with {@link sponsorPlatform} and the `showSponsorCredit` render
* option to emit a "🎁 Thanks to …" line in the description.
*/
sponsorName?: string;
/**
* Storefront the provided key unlocks on (e.g. "Steam", "Epic Games").
* Free-form string so regional / non-listed stores still work.
*/
sponsorPlatform?: string;
spoilerWarning: boolean;
matureWarning: boolean;
storeLinks: Partial<Record<string, string>>;
+7
View File
@@ -14,6 +14,7 @@ export function useGeneratedOutput(): GeneratorOutput {
showQualityBadge,
showCopyright,
showUsagePolicy,
showSponsorCredit,
} = useSettingsStore();
const input: GeneratorInput = useMemo(
@@ -36,6 +37,8 @@ export function useGeneratedOutput(): GeneratorOutput {
playlistLink: state.playlistLink,
contactEmail: state.contactEmail,
musicAttribution: state.musicAttribution,
sponsorName: state.sponsorName,
sponsorPlatform: state.sponsorPlatform,
spoilerWarning: state.spoilerWarning,
matureWarning: state.matureWarning,
storeLinks: state.storeLinks,
@@ -62,6 +65,8 @@ export function useGeneratedOutput(): GeneratorOutput {
state.playlistLink,
state.contactEmail,
state.musicAttribution,
state.sponsorName,
state.sponsorPlatform,
state.spoilerWarning,
state.matureWarning,
state.storeLinks,
@@ -82,6 +87,7 @@ export function useGeneratedOutput(): GeneratorOutput {
showQualityBadge,
showCopyright,
showUsagePolicy,
showSponsorCredit,
}),
[
input,
@@ -92,6 +98,7 @@ export function useGeneratedOutput(): GeneratorOutput {
showQualityBadge,
showCopyright,
showUsagePolicy,
showSponsorCredit,
],
);
}
+4 -2
View File
@@ -16,6 +16,8 @@
"playlistLink", "playlistLinkPlaceholder",
"contactEmail", "contactEmailPlaceholder", "contactEmailHelp",
"musicAttribution", "musicAttributionPlaceholder",
"sponsorName", "sponsorNamePlaceholder",
"sponsorPlatform", "sponsorPlatformPlaceholder",
"thumbnailText", "thumbnailTextPlaceholder",
"pinnedComment", "pinnedCommentPlaceholder",
"videoSettings", "quickPreview", "version",
@@ -42,7 +44,7 @@
"presets": ["title", "createNew", "editPreset", "loadPreset", "deleteConfirm", "emptyState", "selectPreset", "noPresets", "exportPresets", "importPresets"],
"templates": ["title", "createNew", "saveAsTemplate", "templateName", "templateNamePlaceholder", "loadTemplate", "deleteConfirm", "emptyState", "saveHint", "savedAs", "appliedToast", "exportTemplates", "importTemplates"],
"history": ["title", "emptyState", "clearAll", "clearConfirm", "searchPlaceholder"],
"settings": ["title", "appearance", "defaults", "editorSettings", "tagSettings", "historySettings", "theme", "appLanguage", "defaultOutputLanguage", "defaultGenre", "showCharCount", "compactTagDisplay", "historyLimit", "multilingualTags", "trendingTags", "hashtagCount", "showQualityBadge", "showCopyright", "showUsagePolicy"],
"settings": ["title", "appearance", "defaults", "editorSettings", "tagSettings", "historySettings", "theme", "appLanguage", "defaultOutputLanguage", "defaultGenre", "showCharCount", "compactTagDisplay", "historyLimit", "multilingualTags", "trendingTags", "hashtagCount", "showQualityBadge", "showCopyright", "showUsagePolicy", "showSponsorCredit"],
"batch": ["title", "startPart", "endPart", "generateBatch", "copyAllBatch", "emptyState"],
"shortcuts": ["title", "generate", "copyAll", "saveDraft", "help", "close"],
"validation": ["emailInvalid", "emailMaxExceeded", "urlInvalid", "urlPrefixMismatch"],
@@ -56,7 +58,7 @@
"description": ["noCommentaryLine"],
"description.sections": [
"timestamps", "storeLinksBuy", "storeLinksDownload", "videoSettings", "rig",
"spoilerWarning", "matureWarning", "music", "donate", "social",
"spoilerWarning", "matureWarning", "sponsorCredit", "music", "donate", "social",
"playlist", "contact", "cta",
"copyright", "usagePolicyHeader", "usagePolicy"
],
+1
View File
@@ -57,6 +57,7 @@
"rig": "💻 MY RIG",
"spoilerWarning": "⚠️ SPOILER WARNING: This video may contain spoilers. Watch at your own risk!",
"matureWarning": "🔞 MATURE CONTENT (18+): Contains violence / strong language / graphic content.",
"sponsorCredit": "🎁 Thanks to {{sponsor}} for providing the {{platform}} key of this game.",
"music": "🎵 MUSIC / SOUND",
"donate": "☕ SUPPORT THE CHANNEL",
"social": "🔗 FOLLOW ME",
+6 -1
View File
@@ -58,6 +58,10 @@
"contactEmailPlaceholder": "business@example.com",
"musicAttribution": "Music / Sound Attribution",
"musicAttributionPlaceholder": "Music by Karl Casey @ White Bat Audio\nSFX from Freesound.org",
"sponsorName": "Sponsor (publisher / developer)",
"sponsorNamePlaceholder": "e.g. Ubisoft, Capcom, Devolver Digital",
"sponsorPlatform": "Key platform",
"sponsorPlatformPlaceholder": "e.g. Steam, Epic Games, GOG",
"thumbnailText": "Thumbnail Text",
"thumbnailTextPlaceholder": "e.g. SECRET BOSS NO HIT",
"pinnedComment": "Pinned Comment Template",
@@ -275,7 +279,8 @@
"hashtagCount": "Hashtag Count",
"showQualityBadge": "Show quality badge in title (e.g. [2K 60FPS])",
"showCopyright": "Append © copyright line to description",
"showUsagePolicy": "Append usage policy block to description"
"showUsagePolicy": "Append usage policy block to description",
"showSponsorCredit": "Show sponsor credit line in description (thanks for the key)"
},
"batch": {
"title": "Batch Mode",
+1
View File
@@ -57,6 +57,7 @@
"rig": "💻 MI EQUIPO",
"spoilerWarning": "⚠️ ADVERTENCIA DE SPOILERS: Este video puede contener spoilers. ¡Míralo bajo tu propio riesgo!",
"matureWarning": "🔞 CONTENIDO PARA ADULTOS (18+): Contiene violencia / lenguaje fuerte / contenido gráfico.",
"sponsorCredit": "🎁 Gracias a {{sponsor}} por proporcionar la clave de {{platform}} de este juego.",
"music": "🎵 MÚSICA / SONIDO",
"donate": "☕ APOYA EL CANAL",
"social": "🔗 SÍGUEME",
+6 -1
View File
@@ -58,6 +58,10 @@
"contactEmailPlaceholder": "negocios@ejemplo.com",
"musicAttribution": "Crédito Musical / Sonidos",
"musicAttributionPlaceholder": "Música: Karl Casey @ White Bat Audio\nEfectos: Freesound.org",
"sponsorName": "Patrocinador (editor / desarrollador)",
"sponsorNamePlaceholder": "ej. Ubisoft, Capcom, Devolver Digital",
"sponsorPlatform": "Plataforma de la clave",
"sponsorPlatformPlaceholder": "ej. Steam, Epic Games, GOG",
"thumbnailText": "Texto de Miniatura",
"thumbnailTextPlaceholder": "ej. JEFE SECRETO SIN GOLPES",
"pinnedComment": "Plantilla de Comentario Fijado",
@@ -275,7 +279,8 @@
"hashtagCount": "Cantidad de Hashtags",
"showQualityBadge": "Mostrar insignia de calidad en el título (ej. [2K 60FPS])",
"showCopyright": "Agregar línea de © copyright a la descripción",
"showUsagePolicy": "Agregar bloque de política de uso a la descripción"
"showUsagePolicy": "Agregar bloque de política de uso a la descripción",
"showSponsorCredit": "Mostrar línea de agradecimiento al patrocinador (clave) en la descripción"
},
"batch": {
"title": "Generación por Lote",
+1
View File
@@ -57,6 +57,7 @@
"rig": "💻 PC構成",
"spoilerWarning": "⚠️ ネタバレ注意:この動画にはネタバレが含まれている可能性があります。自己責任でご視聴ください!",
"matureWarning": "🔞 成人向けコンテンツ (18+):暴力 / 強い言葉 / グラフィックコンテンツを含みます。",
"sponsorCredit": "🎁 本作の {{platform}} キーをご提供いただいた {{sponsor}} 様、ありがとうございます。",
"music": "🎵 音楽・サウンド",
"donate": "☕ チャンネルを応援",
"social": "🔗 フォローする",
+6 -1
View File
@@ -58,6 +58,10 @@
"contactEmailPlaceholder": "business@example.com",
"musicAttribution": "音楽・サウンドクレジット",
"musicAttributionPlaceholder": "音楽: Karl Casey @ White Bat Audio\n効果音: Freesound.org",
"sponsorName": "スポンサー (パブリッシャー / デベロッパー)",
"sponsorNamePlaceholder": "例: Ubisoft、カプコン、Devolver Digital",
"sponsorPlatform": "キーのプラットフォーム",
"sponsorPlatformPlaceholder": "例: Steam、Epic Games、GOG",
"thumbnailText": "サムネイルテキスト",
"thumbnailTextPlaceholder": "例: 隠しボス ノーヒット",
"pinnedComment": "固定コメントのテンプレート",
@@ -275,7 +279,8 @@
"hashtagCount": "ハッシュタグ数",
"showQualityBadge": "タイトルに画質バッジを表示 (例: [2K 60FPS])",
"showCopyright": "説明欄に © 著作権行を追加",
"showUsagePolicy": "説明欄に動画利用ポリシーを追加"
"showUsagePolicy": "説明欄に動画利用ポリシーを追加",
"showSponsorCredit": "説明欄にスポンサーへの感謝行を追加 (キー提供)"
},
"batch": {
"title": "一括モード",
+1
View File
@@ -57,6 +57,7 @@
"rig": "💻 내 장비",
"spoilerWarning": "⚠️ 스포일러 경고: 이 영상에는 스포일러가 포함될 수 있습니다. 주의하여 시청하세요!",
"matureWarning": "🔞 성인 콘텐츠 (18+): 폭력 / 강한 언어 / 선정적 콘텐츠를 포함합니다.",
"sponsorCredit": "🎁 이 게임의 {{platform}} 키를 제공해 주신 {{sponsor}}님께 감사드립니다.",
"music": "🎵 음악 / 사운드",
"donate": "☕ 채널 후원",
"social": "🔗 팔로우",
+6 -1
View File
@@ -58,6 +58,10 @@
"contactEmailPlaceholder": "business@example.com",
"musicAttribution": "음악 / 사운드 크레딧",
"musicAttributionPlaceholder": "음악: Karl Casey @ White Bat Audio\n효과음: Freesound.org",
"sponsorName": "스폰서 (퍼블리셔 / 개발사)",
"sponsorNamePlaceholder": "예: Ubisoft, 캡콤, Devolver Digital",
"sponsorPlatform": "키 플랫폼",
"sponsorPlatformPlaceholder": "예: Steam, Epic Games, GOG",
"thumbnailText": "썸네일 텍스트",
"thumbnailTextPlaceholder": "예: 시크릿 보스 노히트",
"pinnedComment": "고정 댓글 템플릿",
@@ -275,7 +279,8 @@
"hashtagCount": "해시태그 수",
"showQualityBadge": "제목에 화질 배지 표시 (예: [2K 60FPS])",
"showCopyright": "설명란에 © 저작권 줄 추가",
"showUsagePolicy": "설명란에 영상 사용 정책 블록 추가"
"showUsagePolicy": "설명란에 영상 사용 정책 블록 추가",
"showSponsorCredit": "설명란에 스폰서 감사 문구 추가 (키 제공)"
},
"batch": {
"title": "일괄 생성",
+1
View File
@@ -57,6 +57,7 @@
"rig": "💻 CẤU HÌNH MÁY",
"spoilerWarning": "⚠️ CẢNH BÁO SPOILER: Video này có thể chứa nội dung spoiler. Xem theo ý muốn của bạn!",
"matureWarning": "🔞 NỘI DUNG NGƯỜI LỚN (18+): Chứa bạo lực / ngôn ngữ mạnh / nội dung nhạy cảm.",
"sponsorCredit": "🎁 Cảm ơn {{sponsor}} đã tặng key {{platform}} của game này.",
"music": "🎵 NHẠC / ÂM THANH",
"donate": "☕ ỦNG HỘ KÊNH",
"social": "🔗 THEO DÕI MÌNH",
+6 -1
View File
@@ -58,6 +58,10 @@
"contactEmailPlaceholder": "business@example.com",
"musicAttribution": "Credit nhạc / âm thanh",
"musicAttributionPlaceholder": "Nhạc: Karl Casey @ White Bat Audio\nSFX: Freesound.org",
"sponsorName": "Sponsor (publisher / developer)",
"sponsorNamePlaceholder": "Ví dụ: Ubisoft, Capcom, Devolver Digital",
"sponsorPlatform": "Platform của key",
"sponsorPlatformPlaceholder": "Ví dụ: Steam, Epic Games, GOG",
"thumbnailText": "Text thumbnail",
"thumbnailTextPlaceholder": "vd: SECRET BOSS NO HIT",
"pinnedComment": "Bình luận ghim",
@@ -275,7 +279,8 @@
"hashtagCount": "Số hashtag",
"showQualityBadge": "Hiện badge chất lượng trong tiêu đề (vd: [2K 60FPS])",
"showCopyright": "Gắn dòng © copyright vào description",
"showUsagePolicy": "Gắn khối quy định sử dụng video vào description"
"showUsagePolicy": "Gắn khối quy định sử dụng video vào description",
"showSponsorCredit": "Hiện dòng cảm ơn sponsor (tặng key) trong description"
},
"batch": {
"title": "Chế độ hàng loạt",
+1
View File
@@ -57,6 +57,7 @@
"rig": "💻 我的配置",
"spoilerWarning": "⚠️ 剧透警告:本视频可能包含剧透内容,请自行斟酌观看!",
"matureWarning": "🔞 成人内容 (18+):包含暴力 / 强烈语言 / 血腥内容。",
"sponsorCredit": "🎁 感谢 {{sponsor}} 提供本游戏的 {{platform}} 激活码。",
"music": "🎵 音乐 / 音效",
"donate": "☕ 支持频道",
"social": "🔗 关注我",
+6 -1
View File
@@ -58,6 +58,10 @@
"contactEmailPlaceholder": "business@example.com",
"musicAttribution": "音乐 / 音效署名",
"musicAttributionPlaceholder": "音乐:Karl Casey @ White Bat Audio\n音效:Freesound.org",
"sponsorName": "赞助商 (发行商 / 开发商)",
"sponsorNamePlaceholder": "例如:Ubisoft、卡普空、Devolver Digital",
"sponsorPlatform": "激活码平台",
"sponsorPlatformPlaceholder": "例如:Steam、Epic Games、GOG",
"thumbnailText": "缩略图文字",
"thumbnailTextPlaceholder": "如:隐藏Boss无伤",
"pinnedComment": "置顶评论模板",
@@ -275,7 +279,8 @@
"hashtagCount": "话题标签数量",
"showQualityBadge": "在标题中显示画质标签 (如:[2K 60FPS])",
"showCopyright": "在描述中添加 © 版权行",
"showUsagePolicy": "在描述中添加视频使用规则块"
"showUsagePolicy": "在描述中添加视频使用规则块",
"showSponsorCredit": "在描述中添加赞助商感谢行(提供激活码)"
},
"batch": {
"title": "批量生成",
+2
View File
@@ -12,6 +12,7 @@ import { WarningToggles } from "@components/editor/WarningToggles";
import { ThumbnailHelper } from "@components/editor/ThumbnailHelper";
import { PinnedCommentEditor } from "@components/editor/PinnedCommentEditor";
import { MusicAttributionEditor } from "@components/editor/MusicAttributionEditor";
import { SponsorCreditEditor } from "@components/editor/SponsorCreditEditor";
import { QuickPreview } from "@components/editor/QuickPreview";
import { DraftIndicator } from "@components/editor/DraftIndicator";
import { PresetSelector } from "@components/presets/PresetSelector";
@@ -117,6 +118,7 @@ export function EditorPage() {
onToggle={() => toggleAccordion("attribution")}
>
<MusicAttributionEditor />
<SponsorCreditEditor />
<ThumbnailHelper />
<PinnedCommentEditor />
</Accordion>
+5
View File
@@ -161,6 +161,11 @@ export function SettingsPage() {
checked={settings.showUsagePolicy}
onChange={(v) => settings.setSetting("showUsagePolicy", v)}
/>
<Toggle
label={t("settings.showSponsorCredit")}
checked={settings.showSponsorCredit}
onChange={(v) => settings.setSetting("showSponsorCredit", v)}
/>
<Select
label={t("settings.hashtagCount")}
options={hashtagOptions}
+27 -10
View File
@@ -23,6 +23,8 @@ interface EditorData {
playlistLink: string;
contactEmail: string;
musicAttribution: string;
sponsorName: string;
sponsorPlatform: string;
thumbnailText: string;
pinnedComment: string;
spoilerWarning: boolean;
@@ -68,6 +70,8 @@ const initialState: EditorData = {
playlistLink: DEFAULTS.editor.playlistLink,
contactEmail: DEFAULTS.editor.contactEmail,
musicAttribution: DEFAULTS.editor.musicAttribution,
sponsorName: DEFAULTS.editor.sponsorName,
sponsorPlatform: DEFAULTS.editor.sponsorPlatform,
thumbnailText: DEFAULTS.editor.thumbnailText,
pinnedComment: DEFAULTS.editor.pinnedComment,
spoilerWarning: DEFAULTS.editor.spoilerWarning,
@@ -104,18 +108,29 @@ export const useEditorStore = create<EditorState>()(
{
name: "ytdescgen-editor-draft",
storage: createJSONStorage(() => localStorage),
// v1 → v2 upgrade: `genre: Genre` became `genres: Genre[]` in v0.5.
// Old drafts still round-trip by wrapping the single value.
version: 2,
// v1 → v2: `genre: Genre` became `genres: Genre[]` in v0.5.
// v2 → v3: sponsor credit fields added in v0.6. Missing entries fall
// back to the spread of `initialState` at store creation, but we
// still normalise the blob here so legacy drafts round-trip cleanly.
version: 3,
migrate: (persistedState: unknown, version: number): EditorData => {
if (version < 2 && persistedState && typeof persistedState === "object") {
const state = persistedState as Record<string, unknown> & { genre?: unknown };
if (typeof state.genre === "string" && !Array.isArray(state.genres)) {
state.genres = [state.genre];
delete state.genre;
}
if (!persistedState || typeof persistedState !== "object") {
return { ...initialState };
}
return persistedState as EditorData;
const state = persistedState as Record<string, unknown> & {
genre?: unknown;
sponsorName?: unknown;
sponsorPlatform?: unknown;
};
if (version < 2 && typeof state.genre === "string" && !Array.isArray(state.genres)) {
state.genres = [state.genre];
delete state.genre;
}
if (version < 3) {
if (typeof state.sponsorName !== "string") state.sponsorName = "";
if (typeof state.sponsorPlatform !== "string") state.sponsorPlatform = "";
}
return { ...initialState, ...state } as EditorData;
},
partialize: (state) => ({
videoType: state.videoType,
@@ -137,6 +152,8 @@ export const useEditorStore = create<EditorState>()(
playlistLink: state.playlistLink,
contactEmail: state.contactEmail,
musicAttribution: state.musicAttribution,
sponsorName: state.sponsorName,
sponsorPlatform: state.sponsorPlatform,
thumbnailText: state.thumbnailText,
pinnedComment: state.pinnedComment,
spoilerWarning: state.spoilerWarning,
+2
View File
@@ -22,6 +22,7 @@ export interface SettingsData {
showQualityBadge: boolean;
showCopyright: boolean;
showUsagePolicy: boolean;
showSponsorCredit: boolean;
editorAccordionState: Record<string, boolean>;
}
@@ -50,6 +51,7 @@ export const initialSettings: SettingsData = {
showQualityBadge: true,
showCopyright: true,
showUsagePolicy: false,
showSponsorCredit: false,
editorAccordionState: {
gameInfo: true,
videoSettings: true,
+2 -1
View File
@@ -49,7 +49,7 @@ export const useSettingsStore = create<SettingsState>()(
{
name: STORE_KEY,
storage: createJSONStorage(() => localStorage),
version: 3,
version: 4,
migrate: (persistedState: unknown): SettingsData => healSettings(persistedState),
partialize: (state) => extractData(state),
onRehydrateStorage: () => {
@@ -83,6 +83,7 @@ function extractData(state: SettingsData): SettingsData {
showQualityBadge: state.showQualityBadge,
showCopyright: state.showCopyright,
showUsagePolicy: state.showUsagePolicy,
showSponsorCredit: state.showSponsorCredit,
editorAccordionState: state.editorAccordionState,
};
}
+87
View File
@@ -226,6 +226,93 @@ describe("buildDescription", () => {
expect(musicIdx).toBeLessThan(donateIdx);
});
it("renders the sponsor credit line when toggle is on and both sponsor fields are filled", () => {
const t = createMockT("en");
const result = buildDescription(
makeInput({ sponsorName: "Ubisoft", sponsorPlatform: "Steam" }),
t,
{ showSponsorCredit: true },
);
expect(result).toContain("🎁 Thanks to Ubisoft for providing the Steam key of this game.");
});
it("skips the sponsor credit when the toggle is off", () => {
const t = createMockT("en");
const result = buildDescription(
makeInput({ sponsorName: "Ubisoft", sponsorPlatform: "Steam" }),
t,
{ showSponsorCredit: false },
);
expect(result).not.toContain("🎁 Thanks to Ubisoft");
});
it("skips the sponsor credit when sponsorName is blank even if toggle is on", () => {
const t = createMockT("en");
const result = buildDescription(
makeInput({ sponsorName: "", sponsorPlatform: "Steam" }),
t,
{ showSponsorCredit: true },
);
expect(result).not.toContain("🎁");
expect(result).not.toContain("Steam key of this game");
});
it("skips the sponsor credit when sponsorPlatform is blank even if toggle is on", () => {
const t = createMockT("en");
const result = buildDescription(
makeInput({ sponsorName: "Ubisoft", sponsorPlatform: "" }),
t,
{ showSponsorCredit: true },
);
expect(result).not.toContain("🎁");
expect(result).not.toContain("Thanks to Ubisoft");
});
it("trims whitespace around sponsor fields before rendering", () => {
const t = createMockT("en");
const result = buildDescription(
makeInput({ sponsorName: " Ubisoft ", sponsorPlatform: " Steam " }),
t,
{ showSponsorCredit: true },
);
expect(result).toContain("Thanks to Ubisoft for providing the Steam key");
expect(result).not.toContain(" Ubisoft ");
});
it("places the sponsor credit above the music section and donate block", () => {
const t = createMockT("en");
const result = buildDescription(
makeInput({
sponsorName: "Ubisoft",
sponsorPlatform: "Steam",
musicAttribution: "Music credit",
social: { kofi: "https://ko-fi.com/me" },
}),
t,
{ showSponsorCredit: true },
);
const sponsorIdx = result.indexOf("🎁");
const musicIdx = result.indexOf("🎵 MUSIC / SOUND");
const donateIdx = result.indexOf("SUPPORT THE CHANNEL");
expect(sponsorIdx).toBeGreaterThan(-1);
expect(musicIdx).toBeGreaterThan(sponsorIdx);
expect(donateIdx).toBeGreaterThan(musicIdx);
});
it("renders sponsor credit in Vietnamese with the localized template", () => {
const t = createMockT("vi");
const result = buildDescription(
makeInput({
language: "vi",
sponsorName: "Ubisoft",
sponsorPlatform: "Steam",
}),
t,
{ showSponsorCredit: true },
);
expect(result).toContain("🎁 Cảm ơn Ubisoft đã tặng key Steam của game này.");
});
it("omits the music section when attribution is blank or whitespace", () => {
const t = createMockT("en");
const blank = buildDescription(makeInput({ musicAttribution: "" }), t);
+11
View File
@@ -77,9 +77,20 @@ describe("healSettings", () => {
showQualityBadge: false,
showCopyright: false,
showUsagePolicy: true,
showSponsorCredit: true,
editorAccordionState: { gameInfo: false, videoSettings: true },
};
const healed = healSettings(complete);
expect(healed).toEqual(complete);
});
it("back-fills showSponsorCredit default when the key is absent (v3 → v4 payload)", () => {
// Simulates a settings file written in v0.6 phase 1 where the new
// sponsor toggle hadn't been introduced yet.
const healed = healSettings({
theme: "dark" as const,
showCopyright: true,
});
expect(healed.showSponsorCredit).toBe(false);
});
});