Skip to content
Open
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
1,032 changes: 960 additions & 72 deletions Cargo.lock

Large diffs are not rendered by default.

Binary file added lol-test.pdf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this can go

Binary file not shown.
Binary file added test_cv.pdf
Binary file not shown.
12 changes: 11 additions & 1 deletion thoth-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ backend = [
"jsonwebtoken",
"deadpool-redis",
"rand",
"argon2rs"
"argon2rs",
"aws-sdk-s3",
"aws-sdk-cloudfront",
"aws-config",
"base64",
"hex"
]

[dependencies]
Expand All @@ -48,6 +53,11 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
strum = { version = "0.27.1", features = ["derive"] }
uuid = { version = "1.16.0", features = ["serde", "v4"] }
aws-sdk-s3 = { version = "1", optional = true }
aws-sdk-cloudfront = { version = "1", optional = true }
aws-config = { version = "1", optional = true }
base64 = { version = "0.22", optional = true }
hex = { version = "0.4", optional = true }

[dev-dependencies]
tokio = { version = "1.44", features = ["macros"] }
17 changes: 17 additions & 0 deletions thoth-api/migrations/v0.15.0/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Drop file_upload table
DROP TABLE IF EXISTS file_upload;

-- Drop file table
DROP TABLE IF EXISTS file;

-- Drop file_type enum
DROP TYPE IF EXISTS file_type;

-- Remove storage configuration columns from imprint table
ALTER TABLE imprint
DROP CONSTRAINT IF EXISTS imprint_storage_cfg_all_or_none,
DROP COLUMN IF EXISTS s3_bucket,
DROP COLUMN IF EXISTS s3_region,
DROP COLUMN IF EXISTS cdn_domain,
DROP COLUMN IF EXISTS cloudfront_dist_id;

111 changes: 111 additions & 0 deletions thoth-api/migrations/v0.15.0/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
-- Add storage configuration columns to imprint table
ALTER TABLE imprint
ADD COLUMN s3_bucket TEXT,
ADD COLUMN s3_region TEXT,
ADD COLUMN cdn_domain TEXT,
ADD COLUMN cloudfront_dist_id TEXT;

-- All or nothing constraint: either all storage config fields are NULL or all are NOT NULL
ALTER TABLE imprint
ADD CONSTRAINT imprint_storage_cfg_all_or_none
CHECK (
(
s3_bucket IS NULL AND
s3_region IS NULL AND
cdn_domain IS NULL AND
cloudfront_dist_id IS NULL
)
OR
(
s3_bucket IS NOT NULL AND
s3_region IS NOT NULL AND
cdn_domain IS NOT NULL AND
cloudfront_dist_id IS NOT NULL
)
);

-- Create file_type enum
CREATE TYPE file_type AS ENUM ('publication', 'frontcover');

-- Create file table (final stored files)
CREATE TABLE file (
file_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),

file_type file_type NOT NULL, -- 'publication' | 'frontcover'

work_id UUID REFERENCES work (work_id),
publication_id UUID REFERENCES publication (publication_id),

object_key TEXT NOT NULL, -- lowercase DOI-based canonical path
cdn_url TEXT NOT NULL, -- full public URL

mime_type TEXT NOT NULL,
bytes BIGINT NOT NULL,
sha256 TEXT NOT NULL,

created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

-- Enforce file type constraints
ALTER TABLE file
ADD CONSTRAINT file_type_check
CHECK (
(file_type = 'frontcover' AND work_id IS NOT NULL AND publication_id IS NULL) OR
(file_type = 'publication' AND publication_id IS NOT NULL AND work_id IS NULL)
);

-- One frontcover per work
CREATE UNIQUE INDEX file_frontcover_work_unique_idx
ON file (work_id)
WHERE file_type = 'frontcover';

-- One publication file per publication
CREATE UNIQUE INDEX file_publication_unique_idx
ON file (publication_id)
WHERE file_type = 'publication';

-- Never reuse the same object key
CREATE UNIQUE INDEX file_object_key_unique_idx
ON file (object_key);

-- Enable automatic updated_at management
SELECT diesel_manage_updated_at('file');

-- Create file_upload table (temporary uploads)
CREATE TABLE file_upload (
file_upload_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),

file_type file_type NOT NULL, -- same enum as final file table

work_id UUID REFERENCES work (work_id),
publication_id UUID REFERENCES publication (publication_id),

declared_mime_type TEXT NOT NULL,
declared_extension TEXT NOT NULL,
declared_sha256 TEXT NOT NULL,

created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

-- Enforce file_upload type constraints
ALTER TABLE file_upload
ADD CONSTRAINT file_upload_type_check
CHECK (
(file_type = 'frontcover' AND work_id IS NOT NULL AND publication_id IS NULL) OR
(file_type = 'publication' AND publication_id IS NOT NULL AND work_id IS NULL)
);

-- Indexes for file_upload lookups
CREATE INDEX file_upload_work_idx
ON file_upload (work_id)
WHERE file_type = 'frontcover';

CREATE INDEX file_upload_publication_idx
ON file_upload (publication_id)
WHERE file_type = 'publication';

-- Enable automatic updated_at management
SELECT diesel_manage_updated_at('file_upload');

Loading
Loading