diff --git a/deepwell/src/endpoints/file.rs b/deepwell/src/endpoints/file.rs index 9fcb7a10149..18021119f74 100644 --- a/deepwell/src/endpoints/file.rs +++ b/deepwell/src/endpoints/file.rs @@ -25,7 +25,7 @@ use crate::services::blob::BlobService; use crate::services::file::{ DeleteFile, DeleteFileOutput, EditFile, EditFileOutput, GetBlobOutput, GetFileDetails, GetFileOutput, MoveFile, MoveFileOutput, RestoreFile, - RestoreFileOutput, UploadFile, UploadFileOutput, + RestoreFileOutput, }; use crate::services::Result; use crate::web::{Bytes, FileDetails}; diff --git a/deepwell/src/services/blob/structs.rs b/deepwell/src/services/blob/structs.rs index 4a800818aa5..d931ac264a4 100644 --- a/deepwell/src/services/blob/structs.rs +++ b/deepwell/src/services/blob/structs.rs @@ -26,6 +26,7 @@ pub struct FinalizeBlobUploadOutput { pub hash: BlobHash, pub mime: String, pub size: i64, + pub created: bool, } #[derive(Debug)] diff --git a/deepwell/src/services/file/service.rs b/deepwell/src/services/file/service.rs index 84b709a77b3..9799d6d89f2 100644 --- a/deepwell/src/services/file/service.rs +++ b/deepwell/src/services/file/service.rs @@ -27,7 +27,8 @@ use crate::models::sea_orm_active_enums::FileRevisionType; use crate::services::blob::{FinalizeBlobUploadOutput, EMPTY_BLOB_HASH, EMPTY_BLOB_MIME}; use crate::services::file_revision::{ CreateFileRevision, CreateFileRevisionBody, CreateFirstFileRevision, - CreateResurrectionFileRevision, CreateTombstoneFileRevision, FileBlob, + CreatePendingFileRevision, CreateResurrectionFileRevision, + CreateTombstoneFileRevision, FileBlob, }; use crate::services::filter::{FilterClass, FilterType}; use crate::services::{BlobService, FileRevisionService, FilterService}; @@ -146,7 +147,7 @@ impl FileService { // This gets the data from BlobService and then deletes the row. FileRevisionService::finish_upload( ctx, - FinishUploadFile { + FinishUpload { site_id, page_id, file_id, @@ -166,7 +167,7 @@ impl FileService { user_id, revision_comments, }: UploadFileEdit, - ) -> Result<_UploadFileEditOutput> { + ) -> Result { info!("Uploading new version to file ID {file_id}"); let txn = ctx.transaction(); diff --git a/deepwell/src/services/file/structs.rs b/deepwell/src/services/file/structs.rs index 4cf87c520b9..185ed80f247 100644 --- a/deepwell/src/services/file/structs.rs +++ b/deepwell/src/services/file/structs.rs @@ -20,7 +20,7 @@ use crate::models::sea_orm_active_enums::FileRevisionType; use crate::services::file_revision::{ - CreateFileRevisionOutput, CreateFirstFileRevisionOutput, + CreateFileRevisionOutput, CreateFirstFileRevisionOutput, FinishUploadOutput, }; use crate::web::{Bytes, FileDetails, ProvidedValue, Reference}; use serde_json::Value as JsonValue; @@ -54,10 +54,7 @@ pub struct FinishUploadFile { pub pending_blob_id: i64, } -#[derive(Serialize, Debug, Copy, Clone)] -pub struct FinishUploadFileOutput { - pub created: bool, -} +pub type FinishUploadFileOutput = FinishUploadOutput; #[derive(Deserialize, Debug, Clone)] pub struct UploadFileEdit { diff --git a/deepwell/src/services/file_revision/service.rs b/deepwell/src/services/file_revision/service.rs index 9fb70b182f1..184b3ff7289 100644 --- a/deepwell/src/services/file_revision/service.rs +++ b/deepwell/src/services/file_revision/service.rs @@ -22,7 +22,8 @@ use super::prelude::*; use crate::models::file_revision::{ self, Entity as FileRevision, Model as FileRevisionModel, }; -use crate::services::{OutdateService, PageService}; +use crate::services::blob::{FinalizeBlobUploadOutput, EMPTY_BLOB_HASH, EMPTY_BLOB_MIME}; +use crate::services::{BlobService, OutdateService, PageService}; use crate::web::FetchDirection; use once_cell::sync::Lazy; use std::num::NonZeroI32; @@ -452,7 +453,7 @@ impl FileRevisionService { file_id, pending_blob_id, }: FinishUpload, - ) -> Result { + ) -> Result { let txn = ctx.transaction(); // Move upload to final location, get its metadata @@ -472,9 +473,16 @@ impl FileRevisionService { model.s3_hash = Set(hash.to_vec()); model.mime_hint = Set(mime); model.size_hint = Set(size); - let file_revision = model.update(txn).await?; - Ok(file_revision) + + Ok(FinishUploadOutput { + file_id, + file_revision_id: file_revision.revision_id, + s3_hash: Bytes::from(file_revision.s3_hash), + mime_hint: file_revision.mime_hint, + size_hint: file_revision.size_hint, + created, + }) } /// Get the first revision for this file. @@ -484,6 +492,7 @@ impl FileRevisionService { page_id: i64, file_id: i64, ) -> Result { + let txn = ctx.transaction(); let model = FileRevision::find() .filter( Condition::all() diff --git a/deepwell/src/services/file_revision/structs.rs b/deepwell/src/services/file_revision/structs.rs index d5d2f1869ce..1be072ec515 100644 --- a/deepwell/src/services/file_revision/structs.rs +++ b/deepwell/src/services/file_revision/structs.rs @@ -123,7 +123,7 @@ pub struct UpdateFileRevision { pub hidden: Vec, } -#[derive(Serialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone)] pub struct FinishUpload { pub site_id: i64, pub page_id: i64, @@ -131,6 +131,16 @@ pub struct FinishUpload { pub pending_blob_id: i64, } +#[derive(Serialize, Debug, Copy, Clone)] +pub struct FinishUploadOutput { + pub file_id: i64, + pub file_revision_id: i64, + pub s3_hash: Bytes, + pub mime_hint: String, + pub size_hint: i64, + pub created: bool, +} + #[derive(Deserialize, Debug, Clone)] pub struct GetFileRevisionRange { pub page_id: i64,