mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +08:00
refactor: 拆分 gateway 单体为独立 crate,新增 systemd 部署方案
将 gateway 内部的 model-fetch、provider-transport、scheduler-core、 usage-runtime、video-tasks-core 模块提取为独立 crate;重构 gateway 内部模块结构(state/router/cache/data/query 等);移除大量遗留模块 文件;新增 systemd 二进制部署骨架及相关文档;更新前端 usage 相关 API 和组件。
This commit is contained in:
100
crates/aether-video-tasks-core/src/store_registry.rs
Normal file
100
crates/aether-video-tasks-core/src/store_registry.rs
Normal file
@@ -0,0 +1,100 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::{
|
||||
GeminiVideoTaskSeed, LocalVideoTaskReadResponse, LocalVideoTaskRegistryMutation,
|
||||
LocalVideoTaskSnapshot, LocalVideoTaskStatus, OpenAiVideoTaskSeed,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct VideoTaskRegistry {
|
||||
openai: BTreeMap<String, LocalVideoTaskSnapshot>,
|
||||
gemini: BTreeMap<String, LocalVideoTaskSnapshot>,
|
||||
}
|
||||
|
||||
impl VideoTaskRegistry {
|
||||
pub fn insert(&mut self, snapshot: LocalVideoTaskSnapshot) {
|
||||
match &snapshot {
|
||||
LocalVideoTaskSnapshot::OpenAi(seed) => {
|
||||
self.openai.insert(seed.local_task_id.clone(), snapshot);
|
||||
}
|
||||
LocalVideoTaskSnapshot::Gemini(seed) => {
|
||||
self.gemini.insert(seed.local_short_id.clone(), snapshot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_openai(&self, task_id: &str) -> Option<LocalVideoTaskReadResponse> {
|
||||
self.openai
|
||||
.get(task_id)
|
||||
.map(LocalVideoTaskSnapshot::read_response)
|
||||
}
|
||||
|
||||
pub fn read_gemini(&self, short_id: &str) -> Option<LocalVideoTaskReadResponse> {
|
||||
self.gemini
|
||||
.get(short_id)
|
||||
.map(LocalVideoTaskSnapshot::read_response)
|
||||
}
|
||||
|
||||
pub fn clone_openai(&self, task_id: &str) -> Option<OpenAiVideoTaskSeed> {
|
||||
let LocalVideoTaskSnapshot::OpenAi(seed) = self.openai.get(task_id)?.clone() else {
|
||||
return None;
|
||||
};
|
||||
Some(seed)
|
||||
}
|
||||
|
||||
pub fn clone_gemini(&self, short_id: &str) -> Option<GeminiVideoTaskSeed> {
|
||||
let LocalVideoTaskSnapshot::Gemini(seed) = self.gemini.get(short_id)?.clone() else {
|
||||
return None;
|
||||
};
|
||||
Some(seed)
|
||||
}
|
||||
|
||||
pub fn list_active_snapshots(&self, limit: usize) -> Vec<LocalVideoTaskSnapshot> {
|
||||
self.openai
|
||||
.values()
|
||||
.chain(self.gemini.values())
|
||||
.filter(|snapshot| snapshot.is_active_for_refresh())
|
||||
.take(limit)
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn apply_mutation(&mut self, mutation: LocalVideoTaskRegistryMutation) {
|
||||
match mutation {
|
||||
LocalVideoTaskRegistryMutation::OpenAiCancelled { task_id } => {
|
||||
if let Some(LocalVideoTaskSnapshot::OpenAi(seed)) = self.openai.get_mut(&task_id) {
|
||||
seed.status = LocalVideoTaskStatus::Cancelled;
|
||||
}
|
||||
}
|
||||
LocalVideoTaskRegistryMutation::OpenAiDeleted { task_id } => {
|
||||
if let Some(LocalVideoTaskSnapshot::OpenAi(seed)) = self.openai.get_mut(&task_id) {
|
||||
seed.status = LocalVideoTaskStatus::Deleted;
|
||||
}
|
||||
}
|
||||
LocalVideoTaskRegistryMutation::GeminiCancelled { short_id } => {
|
||||
if let Some(LocalVideoTaskSnapshot::Gemini(seed)) = self.gemini.get_mut(&short_id) {
|
||||
seed.status = LocalVideoTaskStatus::Cancelled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn project_openai(&mut self, task_id: &str, provider_body: &Map<String, Value>) -> bool {
|
||||
let Some(LocalVideoTaskSnapshot::OpenAi(seed)) = self.openai.get_mut(task_id) else {
|
||||
return false;
|
||||
};
|
||||
seed.apply_provider_body(provider_body);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn project_gemini(&mut self, short_id: &str, provider_body: &Map<String, Value>) -> bool {
|
||||
let Some(LocalVideoTaskSnapshot::Gemini(seed)) = self.gemini.get_mut(short_id) else {
|
||||
return false;
|
||||
};
|
||||
seed.apply_provider_body(provider_body);
|
||||
true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user