Skip to content

Commit

Permalink
Improve output of finish_new_upload().
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Sep 10, 2024
1 parent 04477f0 commit 794bea9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion deepwell/src/endpoints/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
1 change: 1 addition & 0 deletions deepwell/src/services/blob/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct FinalizeBlobUploadOutput {
pub hash: BlobHash,
pub mime: String,
pub size: i64,
pub created: bool,
}

#[derive(Debug)]
Expand Down
7 changes: 4 additions & 3 deletions deepwell/src/services/file/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand All @@ -166,7 +167,7 @@ impl FileService {
user_id,
revision_comments,
}: UploadFileEdit,
) -> Result<_UploadFileEditOutput> {
) -> Result<UploadFileEditOutput> {
info!("Uploading new version to file ID {file_id}");

let txn = ctx.transaction();
Expand Down
7 changes: 2 additions & 5 deletions deepwell/src/services/file/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 13 additions & 4 deletions deepwell/src/services/file_revision/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -452,7 +453,7 @@ impl FileRevisionService {
file_id,
pending_blob_id,
}: FinishUpload,
) -> Result<FileRevisionModel> {
) -> Result<FinishUploadOutput> {
let txn = ctx.transaction();

// Move upload to final location, get its metadata
Expand All @@ -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.
Expand All @@ -484,6 +492,7 @@ impl FileRevisionService {
page_id: i64,
file_id: i64,
) -> Result<FileRevisionModel> {
let txn = ctx.transaction();
let model = FileRevision::find()
.filter(
Condition::all()
Expand Down
12 changes: 11 additions & 1 deletion deepwell/src/services/file_revision/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,24 @@ pub struct UpdateFileRevision {
pub hidden: Vec<String>,
}

#[derive(Serialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone)]
pub struct FinishUpload {
pub site_id: i64,
pub page_id: i64,
pub file_id: i64,
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,
Expand Down

0 comments on commit 794bea9

Please sign in to comment.