This commit is contained in:
Felix Ableitner 2024-05-03 12:11:58 +02:00
parent a65ccaf665
commit 303cf00257
2 changed files with 5 additions and 4 deletions

View file

@ -126,7 +126,7 @@ pub async fn create_post(
}
};
plugin_hook("api_create_post", data.clone())?;
plugin_hook("api_before_create_post", data.clone())?;
let post_form = PostInsertForm::builder()
.name(data.name.trim().to_string())
@ -161,6 +161,8 @@ pub async fn create_post(
.await
.with_lemmy_type(LemmyErrorType::CouldntCreatePost)?;
plugin_hook("api_after_create_post", updated_post.clone())?;
generate_post_link_metadata(
updated_post.clone(),
custom_thumbnail,
@ -230,7 +232,6 @@ fn plugin_hook<T: Serialize>(name: &'static str, data: T) -> LemmyResult<()> {
let res = plugin
.call::<extism_convert::Json<T>, &str>(name, data.into())
.map_err(|e| LemmyErrorType::PluginError(e.to_string()));
dbg!(&res);
println!("{}", res?);
}
Ok(())

View file

@ -11,8 +11,8 @@ type CreatePost struct {
// skipping other fields for now
}
//export api_create_post
func api_create_post() int32 {
//export api_before_create_post
func api_before_create_post() int32 {
params := CreatePost{}
// use json input helper, which automatically unmarshals the plugin input into your struct
err := pdk.InputJSON(&params)