(
State(state): State<AppState>,
Extension(session): Extension<LoggedInSession>,
Json(body): Json<CreatePluginBody>,
)
| 125 | } |
| 126 | |
| 127 | pub async fn create_plugin( |
| 128 | State(state): State<AppState>, |
| 129 | Extension(session): Extension<LoggedInSession>, |
| 130 | Json(body): Json<CreatePluginBody>, |
| 131 | ) -> ApiResult<impl IntoResponse> { |
| 132 | let create = CreatePlugin { |
| 133 | author_id: session.session.user.id.get(), |
| 134 | name: body.name, |
| 135 | short_description: body.short_description, |
| 136 | long_description: body.long_description, |
| 137 | is_official: false, |
| 138 | is_public: false, |
| 139 | kind: common::plugin::PluginType::Script, |
| 140 | }; |
| 141 | |
| 142 | if let Err(err) = validate(&create, &()) { |
| 143 | return Err(ApiErrorResponse::ValidationFailed(err)); |
| 144 | } |
| 145 | |
| 146 | let plugins = state |
| 147 | .db |
| 148 | .get_user_plugins(session.session.user.id.get()) |
| 149 | .await |
| 150 | .map_err(|err| { |
| 151 | error!(?err, "failed fetching plugins"); |
| 152 | ApiErrorResponse::InternalError |
| 153 | })?; |
| 154 | |
| 155 | if plugins.len() > 50 { |
| 156 | return Err(ApiErrorResponse::UserPluginLimitReached); |
| 157 | } |
| 158 | |
| 159 | let plugin = state.db.create_plugin(create).await.map_err(|err| { |
| 160 | error!(?err, "failed creating plugin"); |
| 161 | ApiErrorResponse::InternalError |
| 162 | })?; |
| 163 | |
| 164 | Ok(Json(plugin)) |
| 165 | } |
| 166 | |
| 167 | #[derive(Deserialize)] |
| 168 | pub struct UpdatePluginMetaRequest { |
nothing calls this directly
no test coverage detected