Skip to main content

systemprompt_files/models/
file.rs

1//! Persisted file row model.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8use sqlx::FromRow;
9use sqlx::types::Json;
10use systemprompt_identifiers::{ContextId, FileId, SessionId, TraceId, UserId};
11
12use super::metadata::FileMetadata;
13
14#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
15pub struct File {
16    pub id: uuid::Uuid,
17    pub path: String,
18    pub public_url: String,
19    pub mime_type: String,
20    pub size_bytes: Option<i64>,
21    pub ai_content: bool,
22    pub metadata: Json<FileMetadata>,
23    pub user_id: Option<UserId>,
24    pub session_id: Option<SessionId>,
25    pub trace_id: Option<TraceId>,
26    pub context_id: Option<ContextId>,
27    pub created_at: DateTime<Utc>,
28    pub updated_at: DateTime<Utc>,
29    pub deleted_at: Option<DateTime<Utc>>,
30}
31
32impl File {
33    pub fn id(&self) -> FileId {
34        FileId::new(self.id.to_string())
35    }
36}