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

Function create_plugin

components/webapi/src/routes/plugins.rs:127–165  ·  view source on GitHub ↗
(
    State(state): State<AppState>,
    Extension(session): Extension<LoggedInSession>,
    Json(body): Json<CreatePluginBody>,
)

Source from the content-addressed store, hash-verified

125}
126
127pub 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)]
168pub struct UpdatePluginMetaRequest {

Callers

nothing calls this directly

Calls 4

validateFunction · 0.85
get_user_pluginsMethod · 0.80
create_pluginMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected