Skip to content

Commit

Permalink
Add new audiobook publication types WAV and MP3 (including migrations)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhigman committed Aug 12, 2024
1 parent d19751d commit 654dad4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <WebsiteRole> code for Work Landing Page in all ONIX exports from "01" (Publisher’s corporate website) to "02" (Publisher’s website for a specified work).
Expand Down
33 changes: 33 additions & 0 deletions thoth-api/migrations/v0.12.7/down.sql
Original file line number Diff line number Diff line change
@@ -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');
2 changes: 2 additions & 0 deletions thoth-api/migrations/v0.12.7/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TYPE publication_type ADD VALUE IF NOT EXISTS 'MP3';
ALTER TYPE publication_type ADD VALUE IF NOT EXISTS 'WAV';
17 changes: 17 additions & 0 deletions thoth-api/src/model/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions thoth-client/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ impl From<work_query::PublicationType> 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!(),
}
}
Expand Down
17 changes: 17 additions & 0 deletions thoth-export-server/src/xml/onix3_thoth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
}
}
Expand Down Expand Up @@ -2950,6 +2953,20 @@ mod tests {
r#"
<ProductForm>EB</ProductForm>
<ProductFormDetail>E100</ProductFormDetail>"#
));
test_work.publications[0].publication_type = PublicationType::MP3;
let output = generate_test_output(true, &test_work);
assert!(output.contains(
r#"
<ProductForm>AN</ProductForm>
<ProductFormDetail>A103</ProductFormDetail>"#
));
test_work.publications[0].publication_type = PublicationType::WAV;
let output = generate_test_output(true, &test_work);
assert!(output.contains(
r#"
<ProductForm>AN</ProductForm>
<ProductFormDetail>A104</ProductFormDetail>"#
));
test_work.publications[0].publication_type = PublicationType::PAPERBACK;

Expand Down

0 comments on commit 654dad4

Please sign in to comment.