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

Method upsert_plugin_image

components/stores/src/config.rs:869–896  ·  view source on GitHub ↗
(
        &self,
        plugin_id: u64,
        image: CreateUpdatePluginImage,
    )

Source from the content-addressed store, hash-verified

867 }
868
869 pub async fn upsert_plugin_image(
870 &self,
871 plugin_id: u64,
872 image: CreateUpdatePluginImage,
873 ) -> ConfigStoreResult<()> {
874 if matches!(&image.kind, PluginImageKind::Icon | PluginImageKind::Banner) {
875 // There can only be 1 of type icon and banner
876 // Possibly delete existing one if it doesn't match
877 // TODO: use a transaction here to avoid race conditions
878 let res = sqlx::query!(
879 "SELECT image_id from plugin_images WHERE plugin_id = $1 AND kind = $2",
880 plugin_id as i64,
881 i32::from(image.kind)
882 )
883 .fetch_all(&self.pool)
884 .await?;
885
886 for item in res {
887 if item.image_id != image.image_id {
888 self.delete_plugin_image(plugin_id, item.image_id).await?;
889 }
890 }
891 }
892
893 self.inner_upsert_plugin_image(plugin_id, image).await?;
894
895 Ok(())
896 }
897
898 pub async fn delete_plugin_image(
899 &self,

Callers 1

add_plugin_imageFunction · 0.80

Calls 2

delete_plugin_imageMethod · 0.80

Tested by

no test coverage detected