From 654dad449954dfe0cd23ecacae9a2f382454b415 Mon Sep 17 00:00:00 2001 From: rhigman <73792779+rhigman@users.noreply.github.com> Date: Mon, 12 Aug 2024 13:28:29 +0100 Subject: [PATCH] Add new audiobook publication types WAV and MP3 (including migrations) --- CHANGELOG.md | 1 + thoth-api/migrations/v0.12.7/down.sql | 33 ++++++++++++++++++++++ thoth-api/migrations/v0.12.7/up.sql | 2 ++ thoth-api/src/model/publication/mod.rs | 17 +++++++++++ thoth-client/src/queries.rs | 2 ++ thoth-export-server/src/xml/onix3_thoth.rs | 17 +++++++++++ 6 files changed, 72 insertions(+) create mode 100644 thoth-api/migrations/v0.12.7/down.sql create mode 100644 thoth-api/migrations/v0.12.7/up.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 48008741..a7327947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [616](https://github.com/thoth-pub/thoth/pull/616) - Upgrade `time` to v0.3.36 - [616](https://github.com/thoth-pub/thoth/pull/616) - Upgrade `actix-web` to v4.8 - [616](https://github.com/thoth-pub/thoth/pull/616) - Upgrade `openssl` to v0.10.66 + - [617](https://github.com/thoth-pub/thoth/issues/617) - Update publication types to include audiobook formats (MP3 and WAV) ### Fixed - [610](https://github.com/thoth-pub/thoth/issues/610) - Update code for Work Landing Page in all ONIX exports from "01" (Publisher’s corporate website) to "02" (Publisher’s website for a specified work). diff --git a/thoth-api/migrations/v0.12.7/down.sql b/thoth-api/migrations/v0.12.7/down.sql new file mode 100644 index 00000000..49c63186 --- /dev/null +++ b/thoth-api/migrations/v0.12.7/down.sql @@ -0,0 +1,33 @@ +-- We cannot drop individual enum values - we must drop the type and recreate it + +-- Drop constraints, otherwise it won't be able to cast to text +ALTER TABLE publication + DROP CONSTRAINT IF EXISTS publication_publication_type_work_id_uniq, + DROP CONSTRAINT IF EXISTS publication_non_physical_no_dimensions; + +-- Delete publications with about-to-be-dropped types +DELETE FROM publication WHERE publication_type IN ('MP3', 'WAV'); +ALTER TABLE publication ALTER COLUMN publication_type TYPE text; +DROP TYPE publication_type; +CREATE TYPE publication_type AS ENUM ( + 'Paperback', + 'Hardback', + 'PDF', + 'HTML', + 'XML', + 'Epub', + 'Mobi', + 'AZW3', + 'DOCX', + 'FictionBook' +); +ALTER TABLE publication ALTER COLUMN publication_type TYPE publication_type USING publication_type::publication_type; + +ALTER TABLE publication + ADD CONSTRAINT publication_publication_type_work_id_uniq UNIQUE (publication_type, work_id), + ADD CONSTRAINT publication_non_physical_no_dimensions CHECK + ((width_mm IS NULL AND width_in IS NULL + AND height_mm IS NULL AND height_in IS NULL + AND depth_mm IS NULL AND depth_in IS NULL + AND weight_g IS NULL AND weight_oz IS NULL) + OR publication_type = 'Paperback' OR publication_type = 'Hardback'); diff --git a/thoth-api/migrations/v0.12.7/up.sql b/thoth-api/migrations/v0.12.7/up.sql new file mode 100644 index 00000000..47dc3682 --- /dev/null +++ b/thoth-api/migrations/v0.12.7/up.sql @@ -0,0 +1,2 @@ +ALTER TYPE publication_type ADD VALUE IF NOT EXISTS 'MP3'; +ALTER TYPE publication_type ADD VALUE IF NOT EXISTS 'WAV'; diff --git a/thoth-api/src/model/publication/mod.rs b/thoth-api/src/model/publication/mod.rs index f987e683..75c2b5c4 100644 --- a/thoth-api/src/model/publication/mod.rs +++ b/thoth-api/src/model/publication/mod.rs @@ -49,6 +49,12 @@ pub enum PublicationType { Docx, #[cfg_attr(feature = "backend", db_rename = "FictionBook")] FictionBook, + #[cfg_attr(feature = "backend", db_rename = "MP3")] + #[strum(serialize = "MP3")] + Mp3, + #[cfg_attr(feature = "backend", db_rename = "WAV")] + #[strum(serialize = "WAV")] + Wav, } #[cfg_attr( @@ -636,6 +642,8 @@ fn test_publicationtype_display() { assert_eq!(format!("{}", PublicationType::Azw3), "AZW3"); assert_eq!(format!("{}", PublicationType::Docx), "DOCX"); assert_eq!(format!("{}", PublicationType::FictionBook), "FictionBook"); + assert_eq!(format!("{}", PublicationType::Mp3), "MP3"); + assert_eq!(format!("{}", PublicationType::Wav), "WAV"); } #[test] @@ -700,6 +708,15 @@ fn test_publicationtype_fromstr() { PublicationType::FictionBook ); + assert_eq!( + PublicationType::from_str("MP3").unwrap(), + PublicationType::Mp3 + ); + assert_eq!( + PublicationType::from_str("WAV").unwrap(), + PublicationType::Wav + ); + assert!(PublicationType::from_str("PNG").is_err()); assert!(PublicationType::from_str("Latex").is_err()); assert!(PublicationType::from_str("azw3").is_err()); diff --git a/thoth-client/src/queries.rs b/thoth-client/src/queries.rs index b99c25b6..f5dbe196 100644 --- a/thoth-client/src/queries.rs +++ b/thoth-client/src/queries.rs @@ -121,6 +121,8 @@ impl From for PublicationType { work_query::PublicationType::AZW3 => PublicationType::Azw3, work_query::PublicationType::DOCX => PublicationType::Docx, work_query::PublicationType::FICTION_BOOK => PublicationType::FictionBook, + work_query::PublicationType::MP3 => PublicationType::Mp3, + work_query::PublicationType::WAV => PublicationType::Wav, work_query::PublicationType::Other(_) => unreachable!(), } } diff --git a/thoth-export-server/src/xml/onix3_thoth.rs b/thoth-export-server/src/xml/onix3_thoth.rs index 3061de7b..992cc5f8 100644 --- a/thoth-export-server/src/xml/onix3_thoth.rs +++ b/thoth-export-server/src/xml/onix3_thoth.rs @@ -990,6 +990,9 @@ fn get_product_form_codes(publication_type: &PublicationType) -> (&str, Option<& PublicationType::DOCX => ("EB", Some("E104")), // E100 "not yet allocated" - no codelist entry for .fb2, .fb3, .fbz PublicationType::FICTION_BOOK => ("EB", Some("E100")), + // AN Downloadable and online audio file + PublicationType::MP3 => ("AN", Some("A103")), + PublicationType::WAV => ("AN", Some("A104")), PublicationType::Other(_) => unreachable!(), } } @@ -2950,6 +2953,20 @@ mod tests { r#" EB E100"# + )); + test_work.publications[0].publication_type = PublicationType::MP3; + let output = generate_test_output(true, &test_work); + assert!(output.contains( + r#" + AN + A103"# + )); + test_work.publications[0].publication_type = PublicationType::WAV; + let output = generate_test_output(true, &test_work); + assert!(output.contains( + r#" + AN + A104"# )); test_work.publications[0].publication_type = PublicationType::PAPERBACK;