MCPcopy Create free account
hub / github.com/Botloader/botloader / add_plugin_image

Function add_plugin_image

components/webapi/src/routes/plugins.rs:471–592  ·  view source on GitHub ↗
(
    Extension(plugin): Extension<Plugin>,
    State(state): State<AppState>,
    Extension(session): Extension<LoggedInSession>,
    mut multipart: Multipart,
)

Source from the content-addressed store, hash-verified

469}
470
471pub async fn add_plugin_image(
472 Extension(plugin): Extension<Plugin>,
473 State(state): State<AppState>,
474 Extension(session): Extension<LoggedInSession>,
475 mut multipart: Multipart,
476) -> ApiResult<EmptyResponse> {
477 if plugin.author_id != session.session.user.id {
478 return Err(ApiErrorResponse::NoAccessToPlugin);
479 }
480
481 // let mut kind: Option<PluginImageKind> = None;
482 // let mut description: String = String::new();
483 let mut data: Option<Vec<u8>> = None;
484 let mut form: Option<AddPluginImageFormData> = None;
485
486 while let Some(field) = multipart.next_field().await? {
487 let Some(name) = field.name() else {
488 continue;
489 };
490
491 if name == "form" {
492 let text = field.text().await?;
493 let deserialized: AddPluginImageFormData =
494 serde_json::from_str(&text).map_err(ApiErrorResponse::MultipartFormJson)?;
495 form = Some(deserialized);
496 } else {
497 let field_data = field.bytes().await?;
498 data = Some(field_data.to_vec());
499 }
500 }
501
502 let Some(data) = data else {
503 return Err(ApiErrorResponse::MissingMultiPartFormField(
504 "image".to_string(),
505 ));
506 };
507
508 let Some(form) = form else {
509 return Err(ApiErrorResponse::MissingMultiPartFormField(
510 "form".to_string(),
511 ));
512 };
513
514 match form.kind {
515 PluginImageKind::Icon | PluginImageKind::Banner => {}
516 PluginImageKind::Showcase => {
517 let current_count = plugin
518 .images
519 .iter()
520 .filter(|v| matches!(v.kind, PluginImageKind::Showcase))
521 .count();
522
523 if current_count >= 5 {
524 return Err(ApiErrorResponse::MaxImagesReached);
525 }
526 }
527 }
528

Callers

nothing calls this directly

Calls 6

textMethod · 0.80
countMethod · 0.80
create_imageMethod · 0.80
upsert_plugin_imageMethod · 0.80
nameMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected