forge
Explore
Log in

Don't you dare go Hollow

services gain a storage limit the family carries: im's admin panel already owns the roster, so the byte cap a storing sibling answers to belongs on the same row — a nullable storage_limit_bytes behind the guarded ALTER (an old-shaped table grows the column on open), edited as an amount plus a MiB/GiB pair on the per-row form the panel already had, and served to every registered app over /family as limit_bytes beside key, name and url (null when unstated, the sibling's own default standing in its place). A register refresh never touches the cap, the way it never touches the name; owner and client_id stay unserialized; and the family shape test now pins the four public keys with null and stated cases instead of the three it grew out of.

Browse files at this commit

355890cd828d1b29e312544d888e422dae4e41eeAhmet Kaan GümüşParent: 509d0e7
crates/im-core/src/services.rsmodified+128 -23
@@ -26,7 +26,7 @@ pub struct Service {
2626 /// The app that keeps this row — `SELF_OWNER` for im's own entry, a
2727 /// client id for a sibling that registered itself, `None` for a row the
2828 /// seed or the panel made. Never serialized: `/family`'s shape is the
29- /// three public fields the siblings mirror, and nothing more.
29+ /// public fields below, and the ownership stays im's business.
3030 #[serde(skip)]
3131 pub owner: Option<String>,
3232 /// The relying-party credential this row answers for — the client id
@@ -37,6 +37,13 @@ pub struct Service {
3737 /// carries `None` until its app registers.
3838 #[serde(skip)]
3939 pub client_id: Option<String>,
40+ /// The storage cap the panel holds this service to, in bytes — im's
41+ /// field alone, never the keeping app's. Served to the family as
42+ /// `limit_bytes` (JSON `null` when unstated, the sibling's own default
43+ /// standing in its place); a register's refresh never touches it, the
44+ /// way it never touches the name.
45+ #[serde(rename = "limit_bytes")]
46+ pub storage_limit_bytes: Option<u64>,
4047 }
4148
4249 /// The owner im writes on its own row, registered from `issuer` on every
@@ -92,7 +99,8 @@ pub async fn list(store: &Store) -> Result<Vec<Service>> {
9299 let conn = store.conn.lock().await;
93100 let mut rows = conn
94101 .query(
95- "SELECT key, name, url, owner, client_id FROM services ORDER BY position, key",
102+ "SELECT key, name, url, owner, client_id, storage_limit_bytes \
103+ FROM services ORDER BY position, key",
96104 (),
97105 )
98106 .await
@@ -105,6 +113,7 @@ pub async fn list(store: &Store) -> Result<Vec<Service>> {
105113 url: store::text(&row, 2)?,
106114 owner: store::opt_text(&row, 3)?,
107115 client_id: store::opt_text(&row, 4)?,
116+ storage_limit_bytes: store::opt_int(&row, 5)?.map(|bytes| bytes.max(0) as u64),
108117 });
109118 }
110119 Ok(services)
@@ -132,22 +141,34 @@ pub async fn add(store: &Store, service: &Service) -> Result<()> {
132141 )));
133142 }
134143 conn.execute(
135- "INSERT INTO services (key, name, url, position) \
136- VALUES (?1, ?2, ?3, (SELECT COALESCE(MAX(position), -1) + 1 FROM services))",
137- turso::params![service.key.as_str(), service.name.trim(), url.as_str()],
144+ "INSERT INTO services (key, name, url, position, storage_limit_bytes) \
145+ VALUES (?1, ?2, ?3, (SELECT COALESCE(MAX(position), -1) + 1 FROM services), ?4)",
146+ turso::params![
147+ service.key.as_str(),
148+ service.name.trim(),
149+ url.as_str(),
150+ service.storage_limit_bytes.map(|bytes| bytes as i64)
151+ ],
138152 )
139153 .await
140154 .map_err(backend)?;
141155 Ok(())
142156 }
143157
144-/// Rewrites a service's name and address. The key travels in the form's
145-/// hidden field and is not editable; a key not on the list is refused, so a
146-/// form posted against a since-removed row cannot resurrect it.
147-/// A row an app keeps only takes its new name here: the address is the
158+/// Rewrites a service's name, address, and storage limit. The key travels
159+/// in the form's hidden field and is not editable; a key not on the list is
160+/// refused, so a form posted against a since-removed row cannot resurrect
161+/// it. A row an app keeps only takes its new name here: the address is the
148162 /// app's own, rewritten on its every boot, so accepting one from the panel
149-/// would show an edit the next boot silently undoes.
150-pub async fn edit(store: &Store, key: &str, name: &str, url: &str) -> Result<()> {
163+/// would show an edit the next boot silently undoes. The limit is im's on
164+/// every row — kept or not, an empty field clears it to no limit stated.
165+pub async fn edit(
166+ store: &Store,
167+ key: &str,
168+ name: &str,
169+ url: &str,
170+ storage_limit_bytes: Option<u64>,
171+) -> Result<()> {
151172 validate(key, name, url).map_err(StoreError::Invalid)?;
152173 let url = url.trim_end_matches('/');
153174 if let Some(row) = owned_row(store, key).await?
@@ -161,11 +182,16 @@ pub async fn edit(store: &Store, key: &str, name: &str, url: &str) -> Result<()>
161182 let conn = store.conn.lock().await;
162183 let updated = conn
163184 .execute(
164- "UPDATE services SET name = ?2, url = ?3 WHERE key = ?1",
165- turso::params![key, name.trim(), url],
185+ "UPDATE services SET name = ?2, url = ?3, storage_limit_bytes = ?4 WHERE key = ?1",
186+ turso::params![
187+ key,
188+ name.trim(),
189+ url,
190+ storage_limit_bytes.map(|bytes| bytes as i64)
191+ ],
166192 )
167- .await
168- .map_err(backend)?;
193+ .await
194+ .map_err(backend)?;
169195 if updated == 0 {
170196 return Err(StoreError::Invalid(format!("no service keyed {key:?}")));
171197 }
@@ -376,6 +402,7 @@ mod tests {
376402 url: url.to_string(),
377403 owner: None,
378404 client_id: None,
405+ storage_limit_bytes: None,
379406 }
380407 }
381408
@@ -401,7 +428,7 @@ mod tests {
401428 assert_eq!(list(&store).await.unwrap()[0].url, "http://127.0.0.1:7655");
402429 // The panel renamed the first entry; a re-boot with the same config
403430 // must not bring the old name back.
404- edit(&store, "in", "Renamed", "http://127.0.0.1:7655")
431+ edit(&store, "in", "Renamed", "http://127.0.0.1:7655", None)
405432 .await
406433 .unwrap();
407434 assert!(!seed_from(&store, &seed).await.unwrap());
@@ -423,7 +450,7 @@ mod tests {
423450 .unwrap_or_else(|| panic!("a taken key must be refused"));
424451 // The refused add changed nothing.
425452 assert_eq!(keys(&store).await, vec!["im".to_string(), "in".to_string()]);
426- edit(&store, "in", "Dosyalar", "https://in.example")
453+ edit(&store, "in", "Dosyalar", "https://in.example", None)
427454 .await
428455 .unwrap();
429456 let services = list(&store).await.unwrap();
@@ -432,7 +459,7 @@ mod tests {
432459 // A form posted against a since-removed key cannot resurrect it.
433460 remove(&store, "in").await.unwrap();
434461 assert!(matches!(
435- edit(&store, "in", "Zombie", "https://in.example").await,
462+ edit(&store, "in", "Zombie", "https://in.example", None).await,
436463 Err(StoreError::Invalid(_))
437464 ));
438465 assert_eq!(keys(&store).await, vec!["im".to_string()]);
@@ -598,11 +625,11 @@ mod tests {
598625 Err(StoreError::Invalid(_))
599626 ));
600627 assert!(matches!(
601- edit(&store, "in", "Dosyalar", "https://elsewhere.example").await,
628+ edit(&store, "in", "Dosyalar", "https://elsewhere.example", None).await,
602629 Err(StoreError::Invalid(_))
603630 ));
604631 // The name is still the admin's, and a name-only edit lands.
605- edit(&store, "in", "Dosyalar", "https://in.example")
632+ edit(&store, "in", "Dosyalar", "https://in.example", None)
606633 .await
607634 .unwrap();
608635 let row = &list(&store).await.unwrap()[0];
@@ -617,17 +644,95 @@ mod tests {
617644 }
618645
619646 #[tokio::test]
620- async fn the_family_json_never_carries_the_owner() {
647+ async fn the_family_json_carries_the_limit_and_never_the_owner() {
621648 let store = store().await;
622649 register(&store, "im", "Account", "http://127.0.0.1:7650", SELF_OWNER, None)
623650 .await
624651 .unwrap();
625652 let json = serde_json::to_value(list(&store).await.unwrap()).unwrap();
626653 let row = &json.as_array().unwrap()[0];
654+ let mut keys: Vec<String> = row.as_object().unwrap().keys().cloned().collect();
655+ keys.sort();
627656 assert_eq!(
628- row.as_object().unwrap().keys().collect::<Vec<_>>(),
629- vec!["key", "name", "url"],
657+ keys,
658+ vec!["key", "limit_bytes", "name", "url"],
630659 "the sibling mirrors deserialize this shape: {json}"
631660 );
661+ assert!(
662+ row["limit_bytes"].is_null(),
663+ "no stated limit reads null, not absence"
664+ );
665+ // A stated limit rides as plain bytes; the owner never travels.
666+ edit(
667+ &store,
668+ "im",
669+ "Account",
670+ "http://127.0.0.1:7650",
671+ Some(512 * 1024 * 1024),
672+ )
673+ .await
674+ .unwrap();
675+ let json = serde_json::to_value(list(&store).await.unwrap()).unwrap();
676+ assert_eq!(
677+ json[0]["limit_bytes"],
678+ serde_json::json!(512 * 1024 * 1024)
679+ );
680+ assert!(json[0].get("owner").is_none());
681+ assert!(json[0].get("client_id").is_none());
682+ }
683+
684+ #[tokio::test]
685+ async fn the_storage_limit_round_trips_and_survives_a_register() {
686+ let store = store().await;
687+ add(
688+ &store,
689+ &Service {
690+ storage_limit_bytes: Some(512 * 1024 * 1024),
691+ ..service("in", "Files", "http://127.0.0.1:7655")
692+ },
693+ )
694+ .await
695+ .unwrap();
696+ assert_eq!(
697+ list(&store).await.unwrap()[0].storage_limit_bytes,
698+ Some(512 * 1024 * 1024),
699+ "add carries the stated limit in"
700+ );
701+ // The edit rewrites the limit; the row holds plain bytes.
702+ edit(
703+ &store,
704+ "in",
705+ "Files",
706+ "http://127.0.0.1:7655",
707+ Some(2 * 1024 * 1024 * 1024),
708+ )
709+ .await
710+ .unwrap();
711+ assert_eq!(
712+ list(&store).await.unwrap()[0].storage_limit_bytes,
713+ Some(2 * 1024 * 1024 * 1024)
714+ );
715+ // A kept row: the app re-registers, the limit stays im's — the
716+ // refresh rewrites the address and credential, never the cap.
717+ register(
718+ &store,
719+ "in",
720+ "Files",
721+ "http://127.0.0.1:7655",
722+ "in-client",
723+ Some("in-client"),
724+ )
725+ .await
726+ .unwrap();
727+ assert_eq!(
728+ list(&store).await.unwrap()[0].storage_limit_bytes,
729+ Some(2 * 1024 * 1024 * 1024),
730+ "the app's register never touches the limit"
731+ );
732+ // The field empties to cleared: NULL is no limit stated.
733+ edit(&store, "in", "Files", "http://127.0.0.1:7655", None)
734+ .await
735+ .unwrap();
736+ assert_eq!(list(&store).await.unwrap()[0].storage_limit_bytes, None);
632737 }
633738 }
crates/im-core/src/store.rsmodified+71 -1
@@ -155,7 +155,8 @@ CREATE TABLE IF NOT EXISTS services (
155155 url TEXT NOT NULL,
156156 position INTEGER NOT NULL,
157157 owner TEXT,
158- client_id TEXT
158+ client_id TEXT,
159+ storage_limit_bytes INTEGER
159160 );
160161 ";
161162
@@ -285,6 +286,18 @@ impl Store {
285286 .await
286287 .map_err(backend)?;
287288 }
289+ // The per-service storage cap: the panel's limit on how many
290+ // bytes a sibling that stores (in's Files) may hold. Served to
291+ // the family over `/family` as `limit_bytes`; NULL states no
292+ // limit, and the sibling's own default stands.
293+ if !has_column(&conn, "services", "storage_limit_bytes").await? {
294+ conn.execute(
295+ "ALTER TABLE services ADD COLUMN storage_limit_bytes INTEGER",
296+ (),
297+ )
298+ .await
299+ .map_err(backend)?;
300+ }
288301 if !has_column(&conn, "sessions", "ip").await? {
289302 conn.execute("ALTER TABLE sessions ADD COLUMN ip TEXT", ())
290303 .await
@@ -403,6 +416,9 @@ pub(crate) fn opt_text(row: &Row, idx: usize) -> Result<Option<String>> {
403416 pub(crate) fn int(row: &Row, idx: usize) -> Result<i64> {
404417 row.get::<i64>(idx).map_err(backend)
405418 }
419+pub(crate) fn opt_int(row: &Row, idx: usize) -> Result<Option<i64>> {
420+ row.get::<Option<i64>>(idx).map_err(backend)
421+}
406422
407423 #[cfg(test)]
408424 mod tests {
@@ -447,4 +463,58 @@ mod tests {
447463 let _store = Store::open(&path).await.unwrap();
448464 assert!(dir.path().join("im.key").exists());
449465 }
466+
467+ #[tokio::test]
468+ async fn an_old_shaped_services_table_grows_the_limit_column() {
469+ let dir = tempfile::tempdir().unwrap();
470+ let path = dir.path().join("im.db");
471+ // The previous generation's services table, before the storage
472+ // limit was a thing. `Store::open` creates the rest of the schema
473+ // around it and ALTERs the column in without touching the row.
474+ {
475+ let db = turso::Builder::new_local(path.to_str().unwrap())
476+ .build()
477+ .await
478+ .unwrap();
479+ let conn = db.connect().unwrap();
480+ conn.execute_batch(
481+ "CREATE TABLE services (
482+ key TEXT PRIMARY KEY,
483+ name TEXT NOT NULL,
484+ url TEXT NOT NULL,
485+ position INTEGER NOT NULL,
486+ owner TEXT
487+ );
488+ INSERT INTO services (key, name, url, position, owner)
489+ VALUES ('in', 'Files', 'http://127.0.0.1:7655', 0, NULL);",
490+ )
491+ .await
492+ .unwrap();
493+ drop(conn);
494+ drop(db);
495+ }
496+ let store = Store::open(&path).await.unwrap();
497+ let rows = crate::services::list(&store).await.unwrap();
498+ assert_eq!(rows.len(), 1);
499+ assert_eq!(
500+ rows[0].storage_limit_bytes, None,
501+ "a pre-limit row reads no limit"
502+ );
503+ crate::services::edit(
504+ &store,
505+ "in",
506+ "Files",
507+ "http://127.0.0.1:7655",
508+ Some(512 * 1024 * 1024),
509+ )
510+ .await
511+ .unwrap();
512+ // A re-boot on the already-migrated table is the guarded no-op,
513+ // and the stored value survives it.
514+ let store = Store::open(&path).await.unwrap();
515+ assert_eq!(
516+ crate::services::list(&store).await.unwrap()[0].storage_limit_bytes,
517+ Some(512 * 1024 * 1024)
518+ );
519+ }
450520 }
crates/im-web/src/admin.rsmodified+208 -5
@@ -473,6 +473,9 @@ async fn services_section(
473473 // A kept row posts the stored address back in a hidden field: the
474474 // form's name change is accepted, and the store refuses only a
475475 // *changed* address.
476+ // The storage limit: the panel's field on every row — a kept
477+ // row's cap is im's to set, like its name. An empty amount posts
478+ // no limit; the unit pairs with the amount it edits.
476479 let address_field = if kept {
477480 format!(
478481 r#"<input type="hidden" name="url" value="{url}">"#,
@@ -485,8 +488,19 @@ async fn services_section(
485488 url = url,
486489 )
487490 };
491+ let (limit_amount, limit_unit) = service
492+ .storage_limit_bytes
493+ .map(bytes_as_unit)
494+ .unwrap_or_default();
495+ let limit_field = format!(
496+ r#"<label class="auth-field"><span class="auth-label">{limit_label}</span><input class="auth-input auth-input-mono" type="number" name="limit_amount" min="0" step="any" value="{limit_amount}"></label><select class="auth-input admin-role" name="limit_unit" aria-label="{limit_label}"><option value="MiB"{mib}>MiB</option><option value="GiB"{gib}>GiB</option></select>"#,
497+ limit_label = t(lang, Key::ServicesStorageLimit),
498+ limit_amount = limit_amount,
499+ mib = if limit_unit == "MiB" { " selected" } else { "" },
500+ gib = if limit_unit == "GiB" { " selected" } else { "" },
501+ );
488502 let edit = format!(
489- r#"<details class="admin-confirm"><summary class="admin-action">{edit_word}</summary><div class="admin-confirm-pop"><div class="admin-confirm-title">{edit_title}</div><form method="post" action="/admin/services_edit" class="admin-form"><input type="hidden" name="key" value="{key}"><label class="auth-field"><span class="auth-label">{name_label}</span><input class="auth-input auth-input-mono" type="text" name="name" value="{name}" required></label>{address_field}<button class="admin-action" type="submit">{save}</button></form></div></details>"#,
503+ r#"<details class="admin-confirm"><summary class="admin-action">{edit_word}</summary><div class="admin-confirm-pop"><div class="admin-confirm-title">{edit_title}</div><form method="post" action="/admin/services_edit" class="admin-form"><input type="hidden" name="key" value="{key}"><label class="auth-field"><span class="auth-label">{name_label}</span><input class="auth-input auth-input-mono" type="text" name="name" value="{name}" required></label>{address_field}{limit_field}<button class="admin-action" type="submit">{save}</button></form></div></details>"#,
490504 edit_word = t(lang, Key::EditWord),
491505 edit_title = i18n::edit_service_title(lang, &name),
492506 key = key,
@@ -656,13 +670,79 @@ fn client_controls(client_id: &str, name_html: &str, lang: i18n::Lang) -> String
656670 format!("{rotate}{revoke_action}")
657671 }
658672
659-/// One user of the services forms: key, name, address. The add form fills
660-/// all three; the edit form carries the key in its hidden field.
673+/// One mebibyte / gibibyte in bytes: the only two units the limit field
674+/// speaks. Raw bytes never reach the browser — the form posts a decimal
675+/// amount plus one of these units, converted back here.
676+const MIB_BYTES: f64 = 1_048_576.0;
677+const GIB_BYTES: f64 = 1_073_741_824.0;
678+
679+/// The `(amount, unit)` pair a stored limit edits as: gibibytes once the
680+/// value reaches one, mebibytes below it, so `2 GiB` edits as `2` GiB
681+/// rather than `2048` MiB, while a small `512 MiB` cap stays addressable.
682+fn bytes_as_unit(bytes: u64) -> (String, &'static str) {
683+ if bytes >= GIB_BYTES as u64 {
684+ (trim_amount(bytes as f64 / GIB_BYTES), "GiB")
685+ } else {
686+ (trim_amount(bytes as f64 / MIB_BYTES), "MiB")
687+ }
688+}
689+
690+/// A form amount for a number input: two decimals at most, trailing zeros
691+/// (and a bare point) trimmed, so the field reads `2` and `2.5`, never
692+/// `2.00` or `2.5000000001`.
693+fn trim_amount(value: f64) -> String {
694+ let rounded = (value * 100.0).round() / 100.0;
695+ let text = format!("{rounded:.2}");
696+ text.trim_end_matches('0').trim_end_matches('.').to_string()
697+}
698+
699+/// The bytes an `(amount, unit)` pair names, or `None` when the pair is
700+/// not a usable limit: an unknown unit, or an amount that is not a finite
701+/// non-negative number.
702+fn unit_bytes(amount: &str, unit: &str) -> Option<u64> {
703+ let per = match unit {
704+ "MiB" => MIB_BYTES,
705+ "GiB" => GIB_BYTES,
706+ _ => return None,
707+ };
708+ let value: f64 = amount.trim().parse().ok()?;
709+ if !value.is_finite() || value < 0.0 {
710+ return None;
711+ }
712+ Some((value * per).round() as u64)
713+}
714+
715+/// The limit a services form posts, in bytes: `Ok(None)` when the amount
716+/// is blank — the field empties to clear the limit — `Ok(Some(bytes))`
717+/// when it parses, and `Err` when a non-blank amount is not a usable
718+/// number against its unit, which is the panel's refusal.
719+fn posted_limit(
720+ amount: &Option<String>,
721+ unit: &Option<String>,
722+) -> Result<Option<u64>, ()> {
723+ let Some(amount) = amount
724+ .as_deref()
725+ .map(str::trim)
726+ .filter(|amount| !amount.is_empty())
727+ else {
728+ return Ok(None);
729+ };
730+ match unit_bytes(amount, unit.as_deref().unwrap_or_default()) {
731+ Some(bytes) => Ok(Some(bytes)),
732+ None => Err(()),
733+ }
734+}
735+
736+/// One user of the services forms: key, name, address — and, on the edit
737+/// form, the storage limit as an amount plus its unit. The add form posts
738+/// neither limit field; the empty amount clears.
661739 #[derive(Deserialize)]
662740 struct ServiceForm {
663741 key: String,
664742 name: String,
665743 url: String,
744+ limit_amount: Option<String>,
745+ limit_unit: Option<String>,
666746 }
667747
668748 #[route(POST "/admin/services_add")]
@@ -671,6 +751,10 @@ async fn services_add(cx: &Cx, Form(input): Form<ServiceForm>) -> Result<Respons
671751 Ok(me) => me,
672752 Err(redirect) => return Ok(redirect),
673753 };
754+ let limit = match posted_limit(&input.limit_amount, &input.limit_unit) {
755+ Ok(limit) => limit,
756+ Err(()) => return back(cx, "services", "&error=bad_service"),
757+ };
674758 let outcome = im_core::services::add(
675759 &app(cx).store,
676760 &im_core::services::Service {
@@ -679,6 +763,7 @@ async fn services_add(cx: &Cx, Form(input): Form<ServiceForm>) -> Result<Respons
679763 url: input.url,
680764 owner: None,
681765 client_id: None,
766+ storage_limit_bytes: limit,
682767 },
683768 )
684769 .await;
@@ -691,8 +776,18 @@ async fn services_edit(cx: &Cx, Form(input): Form<ServiceForm>) -> Result<Respon
691776 Ok(me) => me,
692777 Err(redirect) => return Ok(redirect),
693778 };
694- let outcome =
695- im_core::services::edit(&app(cx).store, &input.key, &input.name, &input.url).await;
779+ let limit = match posted_limit(&input.limit_amount, &input.limit_unit) {
780+ Ok(limit) => limit,
781+ Err(()) => return back(cx, "services", "&error=bad_service"),
782+ };
783+ let outcome = im_core::services::edit(
784+ &app(cx).store,
785+ &input.key,
786+ &input.name,
787+ &input.url,
788+ limit,
789+ )
790+ .await;
696791 service_outcome(cx, &me, outcome).await
697792 }
698793
@@ -2243,6 +2338,7 @@ mod tests {
22432338 url: "https://wiki.dizey.sh".into(),
22442339 owner: None,
22452340 client_id: None,
2341+ storage_limit_bytes: None,
22462342 },
22472343 )
22482344 .await
@@ -2285,4 +2381,111 @@ mod tests {
22852381 assert_eq!(status, StatusCode::OK);
22862382 assert_eq!(alias.contains(">Drive</td>"), body.contains(">Drive</td>"));
22872383 }
2384+
2385+ #[tokio::test]
2386+ async fn services_edit_saves_the_limit_and_the_rest_is_refused() {
2387+ let setup = setup().await;
2388+ im_core::services::add(
2389+ &setup.store,
2390+ &im_core::services::Service {
2391+ key: "in".into(),
2392+ name: "Files".into(),
2393+ url: "https://in.dizey.sh".into(),
2394+ owner: None,
2395+ client_id: None,
2396+ storage_limit_bytes: None,
2397+ },
2398+ )
2399+ .await
2400+ .unwrap();
2401+
2402+ // The edit posts an amount plus its unit; the row stores bytes.
2403+ let (status, location, _) = post_form(
2404+ &setup.router,
2405+ "/admin/services_edit",
2406+ "key=in&name=Files&url=https://in.dizey.sh&limit_amount=2&limit_unit=GiB",
2407+ Some(&setup.admin_cookie),
2408+ )
2409+ .await;
2410+ assert_eq!(status, StatusCode::SEE_OTHER);
2411+ assert_eq!(
2412+ location.as_deref(),
2413+ Some("/admin?section=services&ok=services")
2414+ );
2415+ assert_eq!(
2416+ im_core::services::list(&setup.store).await.unwrap()[0].storage_limit_bytes,
2417+ Some(2 * 1024 * 1024 * 1024)
2418+ );
2419+
2420+ // An empty amount clears the limit — no limit stated.
2421+ let (status, location, _) = post_form(
2422+ &setup.router,
2423+ "/admin/services_edit",
2424+ "key=in&name=Files&url=https://in.dizey.sh&limit_amount=&limit_unit=GiB",
2425+ Some(&setup.admin_cookie),
2426+ )
2427+ .await;
2428+ assert_eq!(status, StatusCode::SEE_OTHER);
2429+ assert_eq!(
2430+ location.as_deref(),
2431+ Some("/admin?section=services&ok=services")
2432+ );
2433+ assert_eq!(
2434+ im_core::services::list(&setup.store).await.unwrap()[0].storage_limit_bytes,
2435+ None
2436+ );
2437+
2438+ // A non-blank amount that is not a usable number is the section's
2439+ // refusal, and the stored limit is left alone.
2440+ let (status, location, _) = post_form(
2441+ &setup.router,
2442+ "/admin/services_edit",
2443+ "key=in&name=Files&url=https://in.dizey.sh&limit_amount=abc&limit_unit=GiB",
2444+ Some(&setup.admin_cookie),
2445+ )
2446+ .await;
2447+ assert_eq!(status, StatusCode::SEE_OTHER);
2448+ assert_eq!(
2449+ location.as_deref(),
2450+ Some("/admin?section=services&error=bad_service")
2451+ );
2452+ assert_eq!(
2453+ im_core::services::list(&setup.store).await.unwrap()[0].storage_limit_bytes,
2454+ None
2455+ );
2456+
2457+ // A non-admin gets the panel's plain redirect; the row never moves.
2458+ let (status, location, _) = post_form(
2459+ &setup.router,
2460+ "/admin/services_edit",
2461+ "key=in&name=Files&url=https://in.dizey.sh&limit_amount=2&limit_unit=GiB",
2462+ Some(&setup.plain_cookie),
2463+ )
2464+ .await;
2465+ assert_eq!(status, StatusCode::SEE_OTHER);
2466+ assert_eq!(location.as_deref(), Some("/"));
2467+ assert_eq!(
2468+ im_core::services::list(&setup.store).await.unwrap()[0].storage_limit_bytes,
2469+ None
2470+ );
2471+
2472+ // The section renders the amount and its unit pair, empty on a
2473+ // row with no limit (bundle permitting).
2474+ if setup.assets {
2475+ let (status, _, body) = get_full(
2476+ &setup.router,
2477+ "/admin?section=services",
2478+ Some(&setup.admin_cookie),
2479+ )
2480+ .await;
2481+ assert_eq!(status, StatusCode::OK);
2482+ assert!(body.contains("name=\"limit_amount\""), "{body}");
2483+ assert!(body.contains("name=\"limit_unit\""), "{body}");
2484+ assert!(body.contains(">GiB</option>"), "{body}");
2485+ assert!(
2486+ body.contains("name=\"limit_amount\" min=\"0\" step=\"any\" value=\"\""),
2487+ "a no-limit row edits empty: {body}"
2488+ );
2489+ }
2490+ }
22882491 }
crates/im-web/src/directory.rsmodified+52 -1
@@ -413,6 +413,7 @@ mod tests {
413413 url: service.url.clone(),
414414 owner: None,
415415 client_id: None,
416+ storage_limit_bytes: None,
416417 })
417418 .collect()
418419 }
@@ -675,6 +676,55 @@ mod tests {
675676 assert_eq!(family, vec!["in", "im", "iz"], "{body}");
676677 }
677678
679+ #[tokio::test]
680+ async fn family_carries_the_limit_bytes_null_and_stated() {
681+ let Setup {
682+ router,
683+ client_id,
684+ secret,
685+ store,
686+ ..
687+ } = setup().await;
688+ let pair = basic(&client_id, &secret);
689+ // No limit stated anywhere yet: every row's `limit_bytes` is null,
690+ // the shape an unconfigured sibling still parses.
691+ let (status, body) = get_family(&router, Some(pair.clone())).await;
692+ assert_eq!(status, StatusCode::OK);
693+ let family = serde_json::from_str::<serde_json::Value>(&body).unwrap();
694+ for row in family.as_array().unwrap() {
695+ assert!(
696+ row.get("limit_bytes").unwrap().is_null(),
697+ "no limit yet: {row}"
698+ );
699+ }
700+
701+ // The panel sets iz's cap; the next read carries plain bytes.
702+ im_core::services::edit(
703+ &store,
704+ "iz",
705+ "Board",
706+ "http://127.0.0.1:7654",
707+ Some(512 * 1024 * 1024),
708+ )
709+ .await
710+ .unwrap();
711+ let (status, body) = get_family(&router, Some(pair)).await;
712+ assert_eq!(status, StatusCode::OK);
713+ let family = serde_json::from_str::<serde_json::Value>(&body).unwrap();
714+ let iz = family
715+ .as_array()
716+ .unwrap()
717+ .iter()
718+ .find(|row| row["key"] == "iz")
719+ .unwrap();
720+ assert_eq!(
721+ iz["limit_bytes"],
722+ serde_json::json!(512 * 1024 * 1024),
723+ "{body}"
724+ );
725+ }
726+
727+
678728 #[tokio::test]
679729 async fn the_panel_edits_the_family_and_every_reader_follows_the_table() {
680730 let Setup {
@@ -874,6 +924,7 @@ mod tests {
874924 url: "http://127.0.0.1:7655".into(),
875925 owner: None,
876926 client_id: None,
927+ storage_limit_bytes: None,
877928 }];
878929 assert!(!im_core::services::seed_from(&store, &reseed).await.unwrap());
879930 let (_, body) = get_family(&router, Some(basic(&client_id, &secret))).await;
@@ -946,7 +997,7 @@ mod tests {
946997 assert_eq!(body["error"], "owned");
947998
948999 // The keeper's next boot moves the address; the name is the panel's.
949- im_core::services::edit(&store, "wiki", "Vikipedi", "http://wiki.example")
1000+ im_core::services::edit(&store, "wiki", "Vikipedi", "http://wiki.example", None)
9501001 .await
9511002 .unwrap();
9521003 let (status, body) = post_register(
crates/im-web/src/i18n.rsmodified+3 -0
@@ -147,6 +147,7 @@ pub enum Key {
147147 ServiceKept,
148148 ServiceMoveUp,
149149 ServiceMoveDown,
150+ ServicesStorageLimit,
150151 SignOutEverywhere,
151152 AdminPanelLink,
152153 ViewPhotoAria,
@@ -525,6 +526,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
525526 (ServiceMoveUp, Tr) => "Yukarı taşı",
526527 (ServiceMoveDown, En) => "Move down",
527528 (ServiceMoveDown, Tr) => "Aşağı taşı",
529+ (ServicesStorageLimit, En) => "Storage limit",
530+ (ServicesStorageLimit, Tr) => "Depolama limiti",
528531 (SignOutEverywhere, En) => "Sign out everywhere",
529532 (SignOutEverywhere, Tr) => "Her yerde oturumu kapat",
530533 (AdminPanelLink, En) => "Admin panel",
crates/im-web/src/main.rsmodified+1 -0
@@ -174,6 +174,7 @@ async fn seed_services(store: &Store, config: &Config) {
174174 url: service.url.clone(),
175175 owner: None,
176176 client_id: None,
177+ storage_limit_bytes: None,
177178 })
178179 .collect();
179180 match im_core::services::seed_from(store, &seed).await {