From f468f9263e0b3bcb586ce8b75965fbe259f85158 Mon Sep 17 00:00:00 2001 From: Emmie Maeda Date: Mon, 30 Dec 2024 22:37:22 -0500 Subject: [PATCH] Remove hint suffix from mime and size fields. --- .../migrations/20220906103252_deepwell.sql | 6 +-- deepwell/src/endpoints/file.rs | 4 +- deepwell/src/endpoints/page.rs | 4 +- deepwell/src/models/file_revision.rs | 4 +- deepwell/src/services/file/service.rs | 24 +++++----- .../src/services/file_revision/service.rs | 44 +++++++++---------- .../src/services/file_revision/structs.rs | 8 ++-- .../src/routes/[slug]/[...extra]/page.svelte | 4 +- 8 files changed, 49 insertions(+), 49 deletions(-) diff --git a/deepwell/migrations/20220906103252_deepwell.sql b/deepwell/migrations/20220906103252_deepwell.sql index 442896795f..f4629e15b6 100644 --- a/deepwell/migrations/20220906103252_deepwell.sql +++ b/deepwell/migrations/20220906103252_deepwell.sql @@ -492,8 +492,8 @@ CREATE TABLE file_revision ( user_id BIGINT NOT NULL REFERENCES "user"(user_id), name TEXT NOT NULL, s3_hash BYTEA NOT NULL, - mime_hint TEXT NOT NULL, - size_hint BIGINT NOT NULL, + mime TEXT NOT NULL, + size BIGINT NOT NULL, licensing JSON NOT NULL, changes TEXT[] NOT NULL DEFAULT '{}', -- List of changes in this revision comments TEXT NOT NULL, @@ -501,7 +501,7 @@ CREATE TABLE file_revision ( CHECK (length(name) > 0 AND length(name) < 256), -- Constrain filename length CHECK (length(s3_hash) = 64), -- SHA-512 hash size - CHECK (mime_hint != ''), -- Should have a MIME hint + CHECK (mime != ''), -- Should have a MIME hint -- Ensure array only contains valid values -- Change this to use the 'page_revision_change' type later diff --git a/deepwell/src/endpoints/file.rs b/deepwell/src/endpoints/file.rs index a082091fa1..82e1cf1666 100644 --- a/deepwell/src/endpoints/file.rs +++ b/deepwell/src/endpoints/file.rs @@ -163,8 +163,8 @@ async fn build_file_response( revision_user_id: revision.user_id, name: file.name, data: data.map(Bytes::from), - mime: revision.mime_hint, - size: revision.size_hint, + mime: revision.mime, + size: revision.size, licensing: revision.licensing, revision_comments: revision.comments, hidden_fields: revision.hidden, diff --git a/deepwell/src/endpoints/page.rs b/deepwell/src/endpoints/page.rs index 5aa30dfa57..7ee28d65c4 100644 --- a/deepwell/src/endpoints/page.rs +++ b/deepwell/src/endpoints/page.rs @@ -343,8 +343,8 @@ async fn build_page_file_output( revision_user_id: revision.user_id, name: file.name, data: None, - mime: revision.mime_hint, - size: revision.size_hint, + mime: revision.mime, + size: revision.size, licensing: revision.licensing, revision_comments: revision.comments, hidden_fields: revision.hidden, diff --git a/deepwell/src/models/file_revision.rs b/deepwell/src/models/file_revision.rs index 876e726671..9d8aae0772 100644 --- a/deepwell/src/models/file_revision.rs +++ b/deepwell/src/models/file_revision.rs @@ -22,8 +22,8 @@ pub struct Model { #[sea_orm(column_type = "VarBinary(StringLen::None)")] pub s3_hash: Vec, #[sea_orm(column_type = "Text")] - pub mime_hint: String, - pub size_hint: i64, + pub mime: String, + pub size: i64, pub licensing: Json, pub changes: Vec, #[sea_orm(column_type = "Text")] diff --git a/deepwell/src/services/file/service.rs b/deepwell/src/services/file/service.rs index 705d0fd58e..cc1d1890fa 100644 --- a/deepwell/src/services/file/service.rs +++ b/deepwell/src/services/file/service.rs @@ -85,8 +85,8 @@ impl FileService { // Finish blob upload let FinalizeBlobUploadOutput { s3_hash, - mime: mime_hint, - size: size_hint, + mime, + size, created: blob_created, } = match direct_upload { None => { @@ -120,8 +120,8 @@ impl FileService { user_id, name, s3_hash, - size_hint, - mime_hint, + size, + mime, blob_created, licensing, revision_comments, @@ -184,8 +184,8 @@ impl FileService { Maybe::Set(ref id) => { let FinalizeBlobUploadOutput { s3_hash, - mime: mime_hint, - size: size_hint, + mime, + size, created: blob_created, } = match direct_upload { Maybe::Unset => { @@ -201,8 +201,8 @@ impl FileService { Maybe::Set(FileBlob { s3_hash, - mime_hint, - size_hint, + mime, + size, blob_created, }) } @@ -528,8 +528,8 @@ impl FileService { let FileRevisionModel { name, s3_hash, - mime_hint, - size_hint, + mime, + size, licensing, .. } = target_revision; @@ -552,8 +552,8 @@ impl FileService { let blob = FileBlob { s3_hash: slice_to_blob_hash(&s3_hash), - mime_hint, - size_hint, + mime, + size, // in a rollback, by definition the blob was already uploaded blob_created: false, }; diff --git a/deepwell/src/services/file_revision/service.rs b/deepwell/src/services/file_revision/service.rs index b652f1775b..d0946f479d 100644 --- a/deepwell/src/services/file_revision/service.rs +++ b/deepwell/src/services/file_revision/service.rs @@ -89,8 +89,8 @@ impl FileRevisionService { let FileRevisionModel { mut name, mut s3_hash, - mut mime_hint, - mut size_hint, + mut mime, + mut size, mut licensing, .. } = previous; @@ -116,13 +116,13 @@ impl FileRevisionService { if let Maybe::Set(new_blob) = body.blob { if s3_hash != new_blob.s3_hash - || size_hint != new_blob.size_hint - || mime_hint != new_blob.mime_hint + || size != new_blob.size + || mime != new_blob.mime { changes.push(str!("blob")); s3_hash = new_blob.s3_hash.to_vec(); - size_hint = new_blob.size_hint; - mime_hint = new_blob.mime_hint; + size = new_blob.size; + mime = new_blob.mime; blob_created = Maybe::Set(new_blob.blob_created); } } @@ -144,8 +144,8 @@ impl FileRevisionService { // Validate inputs // (Note that filename checks are done in FileService) - if mime_hint.is_empty() { - error!("MIME type hint is empty"); + if mime.is_empty() { + error!("MIME type is empty"); return Err(Error::FileMimeEmpty); } @@ -165,8 +165,8 @@ impl FileRevisionService { user_id: Set(user_id), name: Set(name), s3_hash: Set(s3_hash.to_vec()), - size_hint: Set(size_hint), - mime_hint: Set(mime_hint), + size: Set(size), + mime: Set(mime), licensing: Set(licensing), changes: Set(changes), comments: Set(revision_comments), @@ -194,8 +194,8 @@ impl FileRevisionService { user_id, name, s3_hash, - size_hint, - mime_hint, + size, + mime, blob_created, licensing, revision_comments, @@ -218,8 +218,8 @@ impl FileRevisionService { user_id: Set(user_id), name: Set(name), s3_hash: Set(s3_hash.to_vec()), - mime_hint: Set(mime_hint), - size_hint: Set(size_hint), + mime: Set(mime), + size: Set(size), licensing: Set(licensing), changes: Set(ALL_CHANGES.clone()), comments: Set(revision_comments), @@ -263,8 +263,8 @@ impl FileRevisionService { let FileRevisionModel { name, mut s3_hash, - mime_hint, - size_hint, + mime, + size, licensing, .. } = previous; @@ -291,8 +291,8 @@ impl FileRevisionService { user_id: Set(user_id), name: Set(name), s3_hash: Set(s3_hash), - mime_hint: Set(mime_hint), - size_hint: Set(size_hint), + mime: Set(mime), + size: Set(size), licensing: Set(licensing), changes: Set(vec![]), comments: Set(revision_comments), @@ -344,8 +344,8 @@ impl FileRevisionService { let FileRevisionModel { name: old_name, s3_hash, - mime_hint, - size_hint, + mime, + size, licensing, .. } = previous; @@ -379,8 +379,8 @@ impl FileRevisionService { user_id: Set(user_id), name: Set(new_name), s3_hash: Set(s3_hash), - mime_hint: Set(mime_hint), - size_hint: Set(size_hint), + mime: Set(mime), + size: Set(size), licensing: Set(licensing), changes: Set(changes), comments: Set(revision_comments), diff --git a/deepwell/src/services/file_revision/structs.rs b/deepwell/src/services/file_revision/structs.rs index 7fb1934182..bf32a239f3 100644 --- a/deepwell/src/services/file_revision/structs.rs +++ b/deepwell/src/services/file_revision/structs.rs @@ -45,8 +45,8 @@ pub struct CreateFileRevisionBody { #[derive(Debug, Clone, PartialEq, Eq)] pub struct FileBlob { pub s3_hash: BlobHash, - pub size_hint: i64, - pub mime_hint: String, + pub size: i64, + pub mime: String, pub blob_created: bool, } @@ -67,8 +67,8 @@ pub struct CreateFirstFileRevision { pub user_id: i64, pub name: String, pub s3_hash: BlobHash, - pub size_hint: i64, - pub mime_hint: String, + pub size: i64, + pub mime: String, pub blob_created: bool, pub licensing: serde_json::Value, pub revision_comments: String, diff --git a/framerail/src/routes/[slug]/[...extra]/page.svelte b/framerail/src/routes/[slug]/[...extra]/page.svelte index 2ad9672677..a395076035 100644 --- a/framerail/src/routes/[slug]/[...extra]/page.svelte +++ b/framerail/src/routes/[slug]/[...extra]/page.svelte @@ -1413,10 +1413,10 @@ {revisionItem.name}
- {revisionItem.mime_hint} + {revisionItem.mime}
- {revisionItem.size_hint} + {revisionItem.size}
{revisionItem.comments}