Skip to content

Commit af47f2e

Browse files
committed
refactor(audio): 抽出音频存储配置模块
1 parent ae3bba3 commit af47f2e

2 files changed

Lines changed: 45 additions & 25 deletions

File tree

‎app/src-tauri/src/audio_store.rs‎

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,20 @@ use std::path::{Path, PathBuf};
2828
#[path = "audio_align.rs"]
2929
pub(crate) mod audio_align;
3030

31-
/// 默认保留期(天)。
32-
pub const DEFAULT_RETENTION_DAYS: u64 = 30;
33-
/// 默认磁盘预算(字节;1 小时 ≈ 115MB,预算 4GB ≈ 35 小时会话)。
34-
pub const DEFAULT_DISK_BUDGET_BYTES: u64 = 4 * 1024 * 1024 * 1024;
31+
/// 落盘策略配置的持久化通道(T27 抽件;`#[path]` 由父模块自己声明 ⇒ `lib.rs` 一行未动)。
32+
#[path = "audio_store_config.rs"]
33+
pub(crate) mod audio_store_config;
34+
35+
/// 配置面的公共 API 仍从本模块再导出(既有调用点 `crate::audio_store::AudioStoreConfig` 零改动)。
36+
pub use audio_store_config::{AudioStoreConfig, DEFAULT_DISK_BUDGET_BYTES, DEFAULT_RETENTION_DAYS};
37+
3538
/// WAV 头长度(RIFF 12 + fmt 24 + data 8)。
3639
const WAV_HEADER_LEN: usize = 44;
3740
/// 采样率(与捕获链路契约一致:16kHz)。
3841
const SAMPLE_RATE: u32 = 16_000;
3942
/// 声道数(单声道)。
4043
const CHANNELS: u16 = 1;
4144

42-
/// 落盘策略配置。
43-
#[derive(Debug, Clone, Copy, PartialEq)]
44-
pub struct AudioStoreConfig {
45-
/// 总开关(默认开;关闭=现状行为零开销)
46-
pub enabled: bool,
47-
/// 保留期(天;超期文件清理)
48-
pub retention_days: u64,
49-
/// 磁盘预算(字节;总大小超限删最旧)
50-
pub disk_budget_bytes: u64,
51-
}
52-
53-
impl Default for AudioStoreConfig {
54-
fn default() -> Self {
55-
Self {
56-
enabled: true,
57-
retention_days: DEFAULT_RETENTION_DAYS,
58-
disk_budget_bytes: DEFAULT_DISK_BUDGET_BYTES,
59-
}
60-
}
61-
}
62-
6345
/// 清理结果摘要(命令层/日志消费)。
6446
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
6547
pub struct CleanupSummary {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! 音频落盘策略配置(REQ-068 / v0.6.0 M4 的**配置面**;批 8 T27 从 `audio_store.rs` 抽出)。
2+
//!
3+
//! @ai-context: 本件只承载**类型与默认值**(结构体 + `Default` + 两个 `DEFAULT_*`)
4+
//! —— 与 WAV 写侧(`audio_store.rs` 的 `SessionAudioWriter` / `cleanup`)
5+
//! 物理分离:配策略与写字节是两件事,混在一处会让"改默认值"与"改写盘逻辑"
6+
//! 在同一文件里互相牵动(AGENTS.md §3「纯逻辑与副作用物理分离」)。
7+
//! @ai-context: 由 `audio_store.rs` 以 `#[path]` 声明(同 `audio_align` 先例)⇒ `lib.rs`
8+
//! 一行未动;`AudioStoreConfig` 与两个 `DEFAULT_*` 仍从 `audio_store` 原路径
9+
//! 再导出 ⇒ 既有调用点零改动。
10+
//! @ai-context: 本步是**行为等价的纯搬家**:一个调用点也不改(配置通道是下一步)。
11+
//! @ai-context: 边界 = 本件不改音频存储格式(WAV 仍 16kHz 单声道 PCM16),也没有任何 IO。
12+
13+
/// 默认保留期(天)。
14+
pub const DEFAULT_RETENTION_DAYS: u64 = 30;
15+
/// 默认磁盘预算(字节;1 小时 ≈ 115MB,预算 4GB ≈ 35 小时会话)。
16+
pub const DEFAULT_DISK_BUDGET_BYTES: u64 = 4 * 1024 * 1024 * 1024;
17+
18+
/// 落盘策略配置。
19+
#[derive(Debug, Clone, Copy, PartialEq)]
20+
pub struct AudioStoreConfig {
21+
/// 总开关(默认开;关闭=现状行为零开销)
22+
pub enabled: bool,
23+
/// 保留期(天;超期文件清理)
24+
pub retention_days: u64,
25+
/// 磁盘预算(字节;总大小超限删最旧)
26+
pub disk_budget_bytes: u64,
27+
}
28+
29+
/// 默认配置:开启(保留 30 天 / 预算 4GB;关闭 = 现状行为零开销)。
30+
impl Default for AudioStoreConfig {
31+
fn default() -> Self {
32+
Self {
33+
enabled: true,
34+
retention_days: DEFAULT_RETENTION_DAYS,
35+
disk_budget_bytes: DEFAULT_DISK_BUDGET_BYTES,
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)