From 590d69cfba73ec757a6408aa052e992a35b61aa2 Mon Sep 17 00:00:00 2001 From: icarus Date: Sun, 12 Oct 2025 01:50:33 +0800 Subject: [PATCH] feat(video): add video store module and migration - Initialize video store module with state management for video operations - Add video state to root reducer - Extend video types with id field and specific OpenAIVideo types - Include video store in migration to initialize videoMap --- src/renderer/src/store/index.ts | 4 ++- src/renderer/src/store/migrate.ts | 1 + src/renderer/src/store/video.ts | 60 +++++++++++++++++++++++++++++++ src/renderer/src/types/video.ts | 8 +++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/renderer/src/store/video.ts diff --git a/src/renderer/src/store/index.ts b/src/renderer/src/store/index.ts index d38c0a23ed..896107e731 100644 --- a/src/renderer/src/store/index.ts +++ b/src/renderer/src/store/index.ts @@ -30,6 +30,7 @@ import settings from './settings' import shortcuts from './shortcuts' import tabs from './tabs' import translate from './translate' +import video from './video' import websearch from './websearch' const logger = loggerService.withContext('Store') @@ -58,7 +59,8 @@ const rootReducer = combineReducers({ inputTools: inputToolsReducer, translate, ocr, - note + note, + video }) const persistedReducer = persistReducer( diff --git a/src/renderer/src/store/migrate.ts b/src/renderer/src/store/migrate.ts index 5cffb58054..ed81ea6afc 100644 --- a/src/renderer/src/store/migrate.ts +++ b/src/renderer/src/store/migrate.ts @@ -2662,6 +2662,7 @@ const migrateConfig = { state.settings.sidebarIcons.visible = [...state.settings.sidebarIcons.visible, 'video'] } } + state.video.videoMap = {} return state } catch (error) { logger.error('migrate 161 error', error as Error) diff --git a/src/renderer/src/store/video.ts b/src/renderer/src/store/video.ts new file mode 100644 index 0000000000..58b2b414d3 --- /dev/null +++ b/src/renderer/src/store/video.ts @@ -0,0 +1,60 @@ +import { loggerService } from '@logger' +import { createSlice, PayloadAction } from '@reduxjs/toolkit' +import { Video } from '@renderer/types/video' + +const logger = loggerService.withContext('Store:paintings') + +export interface VideoState { + /** Provider ID to videos */ + videoMap: Record +} + +const initialState: VideoState = { + videoMap: {} +} + +const videoSlice = createSlice({ + name: 'video', + initialState, + reducers: { + addVideo: (state: VideoState, action: PayloadAction<{ providerId: string; video: Video }>) => { + const { providerId, video } = action.payload + if (state[providerId]) { + state.videoMap[providerId].unshift(video) + } else { + state.videoMap[providerId] = [video] + } + }, + removeVideo: (state: VideoState, action: PayloadAction<{ providerId: string; videoId: string }>) => { + const { providerId, videoId } = action.payload + const videos = state.videoMap[providerId] + state.videoMap[providerId] = videos?.filter((c) => c.id !== videoId) + }, + updateVideo: ( + state: VideoState, + action: PayloadAction<{ providerId: string; update: Partial