@@ -55,12 +55,17 @@ interface UserCacheStore {
5555}
5656
5757// ---- 常量 ----
58- const PLAY_RECORDS_KEY = 'moontv_play_records' ;
59- const FAVORITES_KEY = 'moontv_favorites' ;
60- const SEARCH_HISTORY_KEY = 'moontv_search_history' ;
58+ // 新的键名(KatelyaTV)与旧键名(MoonTV)保持向后兼容
59+ const PLAY_RECORDS_KEY = 'katelyatv_play_records' ;
60+ const FAVORITES_KEY = 'katelyatv_favorites' ;
61+ const SEARCH_HISTORY_KEY = 'katelyatv_search_history' ;
62+ const LEGACY_PLAY_RECORDS_KEY = 'moontv_play_records' ;
63+ const LEGACY_FAVORITES_KEY = 'moontv_favorites' ;
64+ const LEGACY_SEARCH_HISTORY_KEY = 'moontv_search_history' ;
6165
6266// 缓存相关常量
63- const CACHE_PREFIX = 'moontv_cache_' ;
67+ const CACHE_PREFIX = 'katelyatv_cache_' ;
68+ const LEGACY_CACHE_PREFIX = 'moontv_cache_' ;
6469const CACHE_VERSION = '1.0.0' ;
6570const CACHE_EXPIRE_TIME = 60 * 60 * 1000 ; // 一小时缓存过期
6671
@@ -426,7 +431,9 @@ export async function getAllPlayRecords(): Promise<Record<string, PlayRecord>> {
426431
427432 // localstorage 模式
428433 try {
429- const raw = localStorage . getItem ( PLAY_RECORDS_KEY ) ;
434+ const primary = localStorage . getItem ( PLAY_RECORDS_KEY ) ;
435+ const fallback = localStorage . getItem ( LEGACY_PLAY_RECORDS_KEY ) ;
436+ const raw = primary ?? fallback ;
430437 if ( ! raw ) return { } ;
431438 return JSON . parse ( raw ) as Record < string , PlayRecord > ;
432439 } catch ( err ) {
@@ -614,7 +621,9 @@ export async function getSearchHistory(): Promise<string[]> {
614621
615622 // localStorage 模式
616623 try {
617- const raw = localStorage . getItem ( SEARCH_HISTORY_KEY ) ;
624+ const primary = localStorage . getItem ( SEARCH_HISTORY_KEY ) ;
625+ const fallback = localStorage . getItem ( LEGACY_SEARCH_HISTORY_KEY ) ;
626+ const raw = primary ?? fallback ;
618627 if ( ! raw ) return [ ] ;
619628 const arr = JSON . parse ( raw ) as string [ ] ;
620629 // 仅返回字符串数组
@@ -835,7 +844,9 @@ export async function getAllFavorites(): Promise<Record<string, Favorite>> {
835844
836845 // localStorage 模式
837846 try {
838- const raw = localStorage . getItem ( FAVORITES_KEY ) ;
847+ const primary = localStorage . getItem ( FAVORITES_KEY ) ;
848+ const fallback = localStorage . getItem ( LEGACY_FAVORITES_KEY ) ;
849+ const raw = primary ?? fallback ;
839850 if ( ! raw ) return { } ;
840851 return JSON . parse ( raw ) as Record < string , Favorite > ;
841852 } catch ( err ) {
@@ -1053,6 +1064,7 @@ export async function clearAllPlayRecords(): Promise<void> {
10531064 // localStorage 模式
10541065 if ( typeof window === 'undefined' ) return ;
10551066 localStorage . removeItem ( PLAY_RECORDS_KEY ) ;
1067+ localStorage . removeItem ( LEGACY_PLAY_RECORDS_KEY ) ;
10561068 window . dispatchEvent (
10571069 new CustomEvent ( 'playRecordsUpdated' , {
10581070 detail : { } ,
@@ -1094,6 +1106,7 @@ export async function clearAllFavorites(): Promise<void> {
10941106 // localStorage 模式
10951107 if ( typeof window === 'undefined' ) return ;
10961108 localStorage . removeItem ( FAVORITES_KEY ) ;
1109+ localStorage . removeItem ( LEGACY_FAVORITES_KEY ) ;
10971110 window . dispatchEvent (
10981111 new CustomEvent ( 'favoritesUpdated' , {
10991112 detail : { } ,
0 commit comments