meta: move public crates to packages/
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I928162008cb1ba02e1aa0e7aa971e8326a6a6964
This commit is contained in:
parent
70b0113d8a
commit
00bab69598
308 changed files with 53890 additions and 53889 deletions
197
packages/pinakes-server/src/dto/sync.rs
Normal file
197
packages/pinakes-server/src/dto/sync.rs
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::media::MediaResponse;
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct RegisterDeviceRequest {
|
||||
pub name: String,
|
||||
pub device_type: String,
|
||||
pub client_version: String,
|
||||
pub os_info: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct DeviceResponse {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub device_type: String,
|
||||
pub client_version: String,
|
||||
pub os_info: Option<String>,
|
||||
pub last_sync_at: Option<DateTime<Utc>>,
|
||||
pub last_seen_at: DateTime<Utc>,
|
||||
pub sync_cursor: Option<i64>,
|
||||
pub enabled: bool,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl From<pinakes_core::sync::SyncDevice> for DeviceResponse {
|
||||
fn from(d: pinakes_core::sync::SyncDevice) -> Self {
|
||||
Self {
|
||||
id: d.id.0.to_string(),
|
||||
name: d.name,
|
||||
device_type: d.device_type.to_string(),
|
||||
client_version: d.client_version,
|
||||
os_info: d.os_info,
|
||||
last_sync_at: d.last_sync_at,
|
||||
last_seen_at: d.last_seen_at,
|
||||
sync_cursor: d.sync_cursor,
|
||||
enabled: d.enabled,
|
||||
created_at: d.created_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct DeviceRegistrationResponse {
|
||||
pub device: DeviceResponse,
|
||||
pub device_token: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateDeviceRequest {
|
||||
pub name: Option<String>,
|
||||
pub enabled: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct GetChangesParams {
|
||||
pub cursor: Option<i64>,
|
||||
pub limit: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct SyncChangeResponse {
|
||||
pub id: String,
|
||||
pub sequence: i64,
|
||||
pub change_type: String,
|
||||
pub media_id: Option<String>,
|
||||
pub path: String,
|
||||
pub content_hash: Option<String>,
|
||||
pub file_size: Option<u64>,
|
||||
pub timestamp: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl From<pinakes_core::sync::SyncLogEntry> for SyncChangeResponse {
|
||||
fn from(e: pinakes_core::sync::SyncLogEntry) -> Self {
|
||||
Self {
|
||||
id: e.id.to_string(),
|
||||
sequence: e.sequence,
|
||||
change_type: e.change_type.to_string(),
|
||||
media_id: e.media_id.map(|id| id.0.to_string()),
|
||||
path: e.path,
|
||||
content_hash: e.content_hash.map(|h| h.0),
|
||||
file_size: e.file_size,
|
||||
timestamp: e.timestamp,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct ChangesResponse {
|
||||
pub changes: Vec<SyncChangeResponse>,
|
||||
pub cursor: i64,
|
||||
pub has_more: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct ClientChangeReport {
|
||||
pub path: String,
|
||||
pub change_type: String,
|
||||
pub content_hash: Option<String>,
|
||||
pub file_size: Option<u64>,
|
||||
pub local_mtime: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct ReportChangesRequest {
|
||||
pub changes: Vec<ClientChangeReport>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct ReportChangesResponse {
|
||||
pub accepted: Vec<String>,
|
||||
pub conflicts: Vec<ConflictResponse>,
|
||||
pub upload_required: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct ConflictResponse {
|
||||
pub id: String,
|
||||
pub path: String,
|
||||
pub local_hash: String,
|
||||
pub server_hash: String,
|
||||
pub detected_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl From<pinakes_core::sync::SyncConflict> for ConflictResponse {
|
||||
fn from(c: pinakes_core::sync::SyncConflict) -> Self {
|
||||
Self {
|
||||
id: c.id.to_string(),
|
||||
path: c.path,
|
||||
local_hash: c.local_hash,
|
||||
server_hash: c.server_hash,
|
||||
detected_at: c.detected_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct ResolveConflictRequest {
|
||||
pub resolution: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct CreateUploadSessionRequest {
|
||||
pub target_path: String,
|
||||
pub expected_hash: String,
|
||||
pub expected_size: u64,
|
||||
pub chunk_size: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct UploadSessionResponse {
|
||||
pub id: String,
|
||||
pub target_path: String,
|
||||
pub expected_hash: String,
|
||||
pub expected_size: u64,
|
||||
pub chunk_size: u64,
|
||||
pub chunk_count: u64,
|
||||
pub status: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub expires_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl From<pinakes_core::sync::UploadSession> for UploadSessionResponse {
|
||||
fn from(s: pinakes_core::sync::UploadSession) -> Self {
|
||||
Self {
|
||||
id: s.id.to_string(),
|
||||
target_path: s.target_path,
|
||||
expected_hash: s.expected_hash.0,
|
||||
expected_size: s.expected_size,
|
||||
chunk_size: s.chunk_size,
|
||||
chunk_count: s.chunk_count,
|
||||
status: s.status.to_string(),
|
||||
created_at: s.created_at,
|
||||
expires_at: s.expires_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct ChunkUploadedResponse {
|
||||
pub chunk_index: u64,
|
||||
pub received: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct AcknowledgeChangesRequest {
|
||||
pub cursor: i64,
|
||||
}
|
||||
|
||||
// Most viewed (uses MediaResponse)
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct MostViewedResponse {
|
||||
pub media: MediaResponse,
|
||||
pub view_count: u64,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue