Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hint suffix from mime and size fields #2237

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions deepwell/migrations/20220906103252_deepwell.sql
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,16 @@ 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,
hidden TEXT[] NOT NULL DEFAULT '{}', -- List of fields to be hidden/suppressed

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
Expand Down
4 changes: 2 additions & 2 deletions deepwell/src/endpoints/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions deepwell/src/endpoints/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions deepwell/src/models/file_revision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct Model {
#[sea_orm(column_type = "VarBinary(StringLen::None)")]
pub s3_hash: Vec<u8>,
#[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<String>,
#[sea_orm(column_type = "Text")]
Expand Down
24 changes: 12 additions & 12 deletions deepwell/src/services/file/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -120,8 +120,8 @@ impl FileService {
user_id,
name,
s3_hash,
size_hint,
mime_hint,
size,
mime,
blob_created,
licensing,
revision_comments,
Expand Down Expand Up @@ -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 => {
Expand All @@ -201,8 +201,8 @@ impl FileService {

Maybe::Set(FileBlob {
s3_hash,
mime_hint,
size_hint,
mime,
size,
blob_created,
})
}
Expand Down Expand Up @@ -528,8 +528,8 @@ impl FileService {
let FileRevisionModel {
name,
s3_hash,
mime_hint,
size_hint,
mime,
size,
licensing,
..
} = target_revision;
Expand All @@ -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,
};
Expand Down
44 changes: 22 additions & 22 deletions deepwell/src/services/file_revision/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand All @@ -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);
}

Expand All @@ -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),
Expand Down Expand Up @@ -194,8 +194,8 @@ impl FileRevisionService {
user_id,
name,
s3_hash,
size_hint,
mime_hint,
size,
mime,
blob_created,
licensing,
revision_comments,
Expand All @@ -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),
Expand Down Expand Up @@ -263,8 +263,8 @@ impl FileRevisionService {
let FileRevisionModel {
name,
mut s3_hash,
mime_hint,
size_hint,
mime,
size,
licensing,
..
} = previous;
Expand All @@ -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),
Expand Down Expand Up @@ -344,8 +344,8 @@ impl FileRevisionService {
let FileRevisionModel {
name: old_name,
s3_hash,
mime_hint,
size_hint,
mime,
size,
licensing,
..
} = previous;
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions deepwell/src/services/file_revision/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions framerail/src/routes/[slug]/[...extra]/page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,10 @@
{revisionItem.name}
</div>
<div class="revision-attribute mime">
{revisionItem.mime_hint}
{revisionItem.mime}
</div>
<div class="revision-attribute size">
{revisionItem.size_hint}
{revisionItem.size}
</div>
<div class="revision-attribute comments">
{revisionItem.comments}
Expand Down
Loading