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

Function publish_plugin_version

components/webapi/src/routes/plugins.rs:272–308  ·  view source on GitHub ↗
(
    State(state): State<AppState>,
    Extension(session): Extension<LoggedInSession>,
    Extension(plugin): Extension<Plugin>,
    Json(body): Json<PublishPluginVersionData>,
)

Source from the content-addressed store, hash-verified

270}
271
272pub async fn publish_plugin_version(
273 State(state): State<AppState>,
274 Extension(session): Extension<LoggedInSession>,
275 Extension(plugin): Extension<Plugin>,
276 Json(body): Json<PublishPluginVersionData>,
277) -> ApiResult<impl IntoResponse> {
278 if let Err(err) = validate(&body, &()) {
279 return Err(ApiErrorResponse::ValidationFailed(err));
280 }
281
282 if plugin.author_id != session.session.user.id {
283 return Err(ApiErrorResponse::NoAccessToPlugin);
284 }
285
286 let guilds = state
287 .db
288 .publish_script_plugin_version(plugin.id, body.new_source)
289 .await
290 .map_err(|err| {
291 error!(?err, "failed updating plugin");
292 ApiErrorResponse::InternalError
293 })?;
294
295 // restart relevant guild vms
296 // TODO: this should be done as a background task, and potentially throttled to avoid a spike
297 for guild_id in guilds {
298 if let Err(err) = state
299 .bot_rpc_client
300 .reload_vm(botrpc::types::GuildSpecifier { guild_id })
301 .await
302 {
303 error!(%err, "failed reloading guild vm");
304 }
305 }
306
307 Ok(EmptyResponse)
308}
309
310#[derive(Deserialize)]
311pub struct GuildAddPluginData {

Callers

nothing calls this directly

Calls 3

validateFunction · 0.85
reload_vmMethod · 0.80

Tested by

no test coverage detected