chadtmiller.com/group-host
atmosphere group host
0
0
A group's profile takes the proposal's pictures and description
crates/group-host/src/blobs.rs+4−1
| @@ -146,7 +146,7 @@ fn collect(value: &Value, found: &mut Vec<Cid>) { | ||
} | ||
} | ||
| ||
/// The kinds of image a page may be given, and a group's profile holds. | ||
/// The kinds of image a page may be given. | ||
pub(crate) const IMAGES: [&str; 5] = [ | ||
"image/png", | ||
"image/jpeg", | ||
| @@ -155,6 +155,9 @@ pub(crate) const IMAGES: [&str; 5] = [ | ||
"image/avif", | ||
]; | ||
| ||
/// The kinds of image a group's avatar and banner may be. | ||
pub(crate) const PROFILE_IMAGES: [&str; 3] = ["image/png", "image/jpeg", "image/webp"]; | ||
| ||
impl Store { | ||
/// Whether a record in `did`'s public repo holds the blob `cid`. | ||
pub fn held_publicly(&self, did: &str, cid: &Cid) -> anyhow::Result<bool> { | ||
crates/group-host/src/group_config.rs+7−4
| @@ -4,7 +4,7 @@ | ||
| ||
use crate::Host; | ||
use crate::api::{Params, invalid, param}; | ||
use crate::blobs::IMAGES; | ||
use crate::blobs::PROFILE_IMAGES; | ||
use crate::group::{join_policy, members_space, meta_space}; | ||
use crate::group_api::{group_of, signed_in}; | ||
use crate::rbac::{NS, actions_for, grants, listed}; | ||
| @@ -168,7 +168,7 @@ fn image(host: &Host, group: &str, key: &str, asked: &Value) -> Result<Value, Xr | ||
return Err(not_one); | ||
}; | ||
let kept = host.store.blob(group, &cid).map_err(XrpcError::internal)?; | ||
let kept = kept.filter(|b| IMAGES.contains(&b.mime_type.as_str())); | ||
let kept = kept.filter(|b| PROFILE_IMAGES.contains(&b.mime_type.as_str())); | ||
let kept = kept.ok_or(not_one)?; | ||
let (mime, size) = (kept.mime_type, kept.size); | ||
Ok(json!({"$type": "blob", "ref": {"$link": link}, "mimeType": mime, "size": size})) | ||
| @@ -273,8 +273,11 @@ pub async fn upload_image( | ||
.get(header::CONTENT_TYPE) | ||
.and_then(|v| v.to_str().ok()) | ||
.unwrap_or_default(); | ||
if !IMAGES.contains(&mime) { | ||
return Err(invalid(format!("an image is one of {}", IMAGES.join(", ")))); | ||
if !PROFILE_IMAGES.contains(&mime) { | ||
return Err(invalid(format!( | ||
"an image is one of {}", | ||
PROFILE_IMAGES.join(", ") | ||
))); | ||
} | ||
let blob = host.upload_blob(&group, &bytes, mime)?; | ||
Ok(Json(json!({ "blob": blob }))) | ||
crates/group-host/src/import.rs+1−1
| @@ -56,7 +56,7 @@ const CREATE_ACCOUNT: &str = "com.atproto.server.createAccount"; | ||
/// characters: no more graphemes than its lexicon lets it have, and so no | ||
/// more bytes. | ||
const NAME_MAX: usize = 64; | ||
const DESCRIPTION_MAX: usize = 300; | ||
const DESCRIPTION_MAX: usize = 2000; | ||
| ||
fn refused(error: &'static str, message: impl Into<String>) -> XrpcError { | ||
XrpcError::new(StatusCode::BAD_REQUEST, error, message) | ||
crates/group-host/tests/group_config.rs+8−1
| @@ -228,7 +228,7 @@ async fn refuses_a_profile_it_should_not_keep() { | ||
), | ||
( | ||
&alice, | ||
json!({"group": did, "displayName": "Riders", "description": "x".repeat(301)}), | ||
json!({"group": did, "displayName": "Riders", "description": "x".repeat(2001)}), | ||
(400, "InvalidRequest"), | ||
), | ||
// An image that is not the group's. | ||
| @@ -252,6 +252,13 @@ async fn refuses_a_profile_it_should_not_keep() { | ||
for (who, bytes, mime, refused) in [ | ||
(&bob, b"face".to_vec(), "image/png", (403, "Forbidden")), | ||
(&alice, vec![], "image/png", (400, "InvalidRequest")), | ||
// A picture of a kind a profile does not take. | ||
( | ||
&alice, | ||
b"GIF89a".to_vec(), | ||
"image/gif", | ||
(400, "InvalidRequest"), | ||
), | ||
( | ||
&alice, | ||
vec![0; 1_000_001], | ||
crates/group-host/tests/groups.rs+1−1
| @@ -467,7 +467,7 @@ async fn refuses_a_group_it_should_not_start() { | ||
(400, "InvalidRequest"), | ||
), | ||
( | ||
body(json!({"description": "x".repeat(301)})), | ||
body(json!({"description": "x".repeat(2001)})), | ||
me.to_vec(), | ||
(400, "InvalidRequest"), | ||
), | ||
docs/design/groups.md+3−5
| @@ -54,9 +54,7 @@ Details: | ||
- A membership's record key is the member's DID. | ||
- Text is held to its lexicon's length, here and in every method that | ||
writes it, and refused with `InvalidRequest` past it: a group's display | ||
name 64 characters, its description 300. The host counts characters, | ||
so a text of combined characters may be refused a little short of the | ||
lexicon's grapheme limit. | ||
name 64 graphemes, its description 2,000. | ||
| ||
## Its address | ||
| ||
| @@ -161,8 +159,8 @@ its URI, which no longer resolves ([moderation](moderation.md)). | ||
| ||
Details: | ||
| ||
- `uploadImage` takes at most 1,000,000 bytes, of a PNG, JPEG, WebP, GIF | ||
or AVIF image as its `Content-Type` says, and refuses any other type. | ||
- `uploadImage` takes at most 1,000,000 bytes, of a PNG, JPEG or WebP | ||
image as its `Content-Type` says, and refuses any other type. | ||
- `updateProfile` takes a picture's type and size from the upload the | ||
host kept, not from what the caller writes, and refuses a blob that is | ||
not one of the group's images. | ||
lexicons/fyi/opensocial/createGroup.json+2−2
| @@ -33,8 +33,8 @@ | ||
}, | ||
"description": { | ||
"type": "string", | ||
"maxGraphemes": 300, | ||
"maxLength": 3000 | ||
"maxGraphemes": 2000, | ||
"maxLength": 20000 | ||
}, | ||
"joinPolicy": { | ||
"type": "string", | ||
lexicons/fyi/opensocial/profile.json+4−8
| @@ -20,17 +20,15 @@ | ||
}, | ||
"description": { | ||
"type": "string", | ||
"maxGraphemes": 300, | ||
"maxLength": 3000 | ||
"maxGraphemes": 2000, | ||
"maxLength": 20000 | ||
}, | ||
"avatar": { | ||
"type": "blob", | ||
"accept": [ | ||
"image/png", | ||
"image/jpeg", | ||
"image/webp", | ||
"image/gif", | ||
"image/avif" | ||
"image/webp" | ||
], | ||
"maxSize": 1000000 | ||
}, | ||
| @@ -39,9 +37,7 @@ | ||
"accept": [ | ||
"image/png", | ||
"image/jpeg", | ||
"image/webp", | ||
"image/gif", | ||
"image/avif" | ||
"image/webp" | ||
], | ||
"maxSize": 1000000 | ||
}, | ||
lexicons/fyi/opensocial/updateProfile.json+4−8
| @@ -26,8 +26,8 @@ | ||
}, | ||
"description": { | ||
"type": "string", | ||
"maxGraphemes": 300, | ||
"maxLength": 3000 | ||
"maxGraphemes": 2000, | ||
"maxLength": 20000 | ||
}, | ||
"joinPolicy": { | ||
"type": "string", | ||
| @@ -79,9 +79,7 @@ | ||
"accept": [ | ||
"image/png", | ||
"image/jpeg", | ||
"image/webp", | ||
"image/gif", | ||
"image/avif" | ||
"image/webp" | ||
], | ||
"maxSize": 1000000, | ||
"description": "The group's avatar, as returned by uploadImage. Omit to keep the current one; removeAvatar clears it." | ||
| @@ -95,9 +93,7 @@ | ||
"accept": [ | ||
"image/png", | ||
"image/jpeg", | ||
"image/webp", | ||
"image/gif", | ||
"image/avif" | ||
"image/webp" | ||
], | ||
"maxSize": 1000000, | ||
"description": "The group's banner, as returned by uploadImage. Omit to keep the current one; removeBanner clears it." | ||
web/src/lib/organisms/NewGroupForm.svelte+1−1
| @@ -56,7 +56,7 @@ | ||
{:else} | ||
<p class="mute small">Made from its name; change it if you like. It is the group's handle, and where its pages are.</p> | ||
{/if} | ||
<label class="field">What it is for <textarea name="description" maxlength="300"></textarea></label> | ||
<label class="field">What it is for <textarea name="description" maxlength="2000"></textarea></label> | ||
<label class="field"> | ||
How people join | ||
<select name="joinPolicy"> | ||