Skip to content
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
Binary file modified .claude/private/CLAUDE.md
Binary file not shown.
19 changes: 14 additions & 5 deletions server/crates/publish/src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ pub struct SiteLimits {
pub media: usize,
pub media_bytes: u64,
pub media_file: u64,
/// Files and bytes for a site with a cookbook: recipes are mostly
/// photographs.
/// Pages, files and bytes for a site with a cookbook: a cookbook is
/// many recipes, mostly photographs.
pub cookbook_pages: usize,
pub cookbook_media: usize,
pub cookbook_bytes: u64,
}
Expand All @@ -51,8 +52,9 @@ impl Default for SiteLimits {
media: 377,
media_bytes: 144 << 20,
media_file: 21 << 20,
cookbook_media: 987,
cookbook_bytes: 610 << 20,
cookbook_pages: 1597,
cookbook_media: 2584,
cookbook_bytes: 1597 << 20,
}
}
}
Expand Down Expand Up @@ -240,7 +242,14 @@ impl<S: Store, C: SignatureCheck> Site<S, C> {
}
let key = format!("{PAGES}{slug}");
let new = self.store.get(&key)?.is_none();
if new && self.store.list(PAGES, None, usize::MAX)?.len() >= self.limits.pages {
// A recipe for the cookbook, or any page of a site that has one,
// counts against the cookbook's room.
let pages = if (page.listed && page.recipe.is_some()) || self.has_cookbook()? {
self.limits.pages.max(self.limits.cookbook_pages)
} else {
self.limits.pages
};
if new && self.store.list(PAGES, None, usize::MAX)?.len() >= pages {
return Err(SiteError::Full);
}
let listed = match &page.recipe {
Expand Down
15 changes: 15 additions & 0 deletions server/crates/publish/tests/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ fn the_cookbook_address_is_not_a_page() {
assert_eq!(put(&mut site, &owner(), "ricette", &page("Ricette", "x")), Err(SiteError::NotFound));
}

#[test]
fn a_site_with_a_cookbook_holds_more_pages() {
let mut site = claimed().with_limits(SiteLimits { pages: 1, cookbook_pages: 3, ..SiteLimits::default() });
put(&mut site, &owner(), "diario", &page("Diario", "x")).unwrap();
assert_eq!(put(&mut site, &owner(), "altro", &page("Altro", "x")), Err(SiteError::Full));
// Recipes for the cookbook have its room, and so has the site then.
put(&mut site, &owner(), "pane", &recipe("Pane", "Lievitati", true)).unwrap();
put(&mut site, &owner(), "altro", &page("Altro", "x")).unwrap();
assert_eq!(put(&mut site, &owner(), "seadas", &recipe("Seadas", "Dolci", true)), Err(SiteError::Full));
// A draft recipe is not the cookbook's.
let mut plain = claimed().with_limits(SiteLimits { pages: 1, cookbook_pages: 3, ..SiteLimits::default() });
put(&mut plain, &owner(), "diario", &page("Diario", "x")).unwrap();
assert_eq!(put(&mut plain, &owner(), "bozza", &recipe("Bozza", "Dolci", false)), Err(SiteError::Full));
}

#[test]
fn a_site_with_a_cookbook_holds_more_files() {
let mut site = claimed().with_limits(SiteLimits {
Expand Down
Loading