wow_sharedmedia/data.rs
1//! AddonData — the single source of truth, persisted as data.lua.
2
3use crate::MediaEntry;
4
5/// Current data.lua schema version.
6pub const SCHEMA_VERSION: u32 = 1;
7
8/// Top-level data structure persisted in data.lua.
9///
10/// This replaces the old Manifest. It contains everything the addon needs:
11/// version tracking, generation timestamp, and all media entries.
12#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
13pub struct AddonData {
14 /// Schema version of the `data.lua` format.
15 pub schema_version: u32,
16 /// Version of the tool that last wrote this file.
17 pub version: String,
18 #[serde(with = "chrono::serde::ts_milliseconds")]
19 /// Timestamp of the last successful write, in UTC.
20 pub generated_at: chrono::DateTime<chrono::Utc>,
21 /// All registered media entries.
22 pub entries: Vec<MediaEntry>,
23}
24
25impl AddonData {
26 /// Create a new empty AddonData with the given tool version.
27 ///
28 /// This is typically used by [`crate::ensure_addon_dir`] when bootstrapping
29 /// a fresh addon directory.
30 pub fn empty(tool_version: &str) -> Self {
31 Self {
32 schema_version: SCHEMA_VERSION,
33 version: tool_version.to_string(),
34 generated_at: chrono::Utc::now(),
35 entries: Vec::new(),
36 }
37 }
38}