(
State(state): State<AppState>,
Extension(session): Extension<LoggedInSession>,
Extension(plugin): Extension<Plugin>,
Json(body): Json<PublishPluginVersionData>,
)
| 270 | } |
| 271 | |
| 272 | pub 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)] |
| 311 | pub struct GuildAddPluginData { |
nothing calls this directly
no test coverage detected