Store content in the vault. Creates a `VaultEntry` from the given parameters, stores it in the database, and updates the manifest atomically. Returns the content hash (Blake3) of the stored entry. If an entry already exists at this path, it is replaced and the manifest is updated accordingly.
(
&self,
path: &str,
entry_type: VaultEntryType,
content: Vec<u8>,
frontmatter_json: String,
)
| 154 | /// If an entry already exists at this path, it is replaced and the |
| 155 | /// manifest is updated accordingly. |
| 156 | pub fn vault_store( |
| 157 | &self, |
| 158 | path: &str, |
| 159 | entry_type: VaultEntryType, |
| 160 | content: Vec<u8>, |
| 161 | frontmatter_json: String, |
| 162 | ) -> Result<Hash, RepositoryError> { |
| 163 | let now = chrono::Utc::now().to_rfc3339(); |
| 164 | let entry = VaultEntry::new(entry_type, content, frontmatter_json, now.clone()); |
| 165 | let content_hash = Hash::from_bytes(entry.content_hash); |
| 166 | |
| 167 | let mut txn = self |
| 168 | .pristine |
| 169 | .write_txn() |
| 170 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 171 | use atomic_core::pristine::{VaultMutTxnT, VaultTxnT}; |
| 172 | |
| 173 | txn.put_vault_entry(path, &entry) |
| 174 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 175 | |
| 176 | // Update manifest |
| 177 | let mut manifest = txn |
| 178 | .get_vault_manifest() |
| 179 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 180 | update_manifest_for_store(&mut manifest, path, &entry, &now); |
| 181 | txn.put_vault_manifest(&manifest) |
| 182 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 183 | |
| 184 | txn.commit() |
| 185 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 186 | |
| 187 | self.vault_auto_index(path); |
| 188 | |
| 189 | Ok(content_hash) |
| 190 | } |
| 191 | |
| 192 | /// Store a pre-built vault entry. Also updates the manifest. |
| 193 | /// |