fix(triggers): support POST with query params for autoscan compatibility#522
Open
jkristoph wants to merge 1 commit into
Open
fix(triggers): support POST with query params for autoscan compatibility#522jkristoph wants to merge 1 commit into
jkristoph wants to merge 1 commit into
Conversation
The original autoscan (github.com/cloudbox/autoscan) sends scan requests between instances as POST /triggers/manual?dir=/path with an empty body. The current POST handler requires a JSON body and rejects Manual/Autoscan trigger types, making it incompatible with autoscan-to-autoscan forwarding. This change makes the POST handler fall back to query parameter parsing (the same logic used by the GET handler) when the request body is empty or not valid JSON. This enables seamless interop with legacy autoscan instances without breaking existing JSON-body-based triggers (Sonarr, Radarr, etc.). Closes dan-online#307 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dan-online
reviewed
Apr 9, 2026
Comment on lines
+55
to
+72
| let parsed_body: Option<serde_json::Value> = if body.is_empty() { | ||
| None | ||
| } else { | ||
| serde_json::from_slice(&body).ok() | ||
| }; | ||
|
|
||
| let has_body = parsed_body | ||
| .as_ref() | ||
| .map(|b| !b.is_null()) | ||
| .unwrap_or(false); | ||
|
|
||
| if !has_body { | ||
| if let Ok(query) = | ||
| Query::<TriggerQueryParams>::from_query(req.query_string()) | ||
| { | ||
| return trigger_get_inner(&trigger, query.into_inner(), &manager, trigger_settings) | ||
| .await; | ||
| } |
Owner
There was a problem hiding this comment.
Nice direction here. I think the cleanest fix is to parse the query string based on trigger_settings instead of going through the untagged enum first. That lets manual normalize the legacy dir shape explicitly, and it keeps invalid non-empty JSON failing fast instead of silently falling back.
Something like:
Suggested change
| let parsed_body: Option<serde_json::Value> = if body.is_empty() { | |
| None | |
| } else { | |
| serde_json::from_slice(&body).ok() | |
| }; | |
| let has_body = parsed_body | |
| .as_ref() | |
| .map(|b| !b.is_null()) | |
| .unwrap_or(false); | |
| if !has_body { | |
| if let Ok(query) = | |
| Query::<TriggerQueryParams>::from_query(req.query_string()) | |
| { | |
| return trigger_get_inner(&trigger, query.into_inner(), &manager, trigger_settings) | |
| .await; | |
| } | |
| let query_fallback = if body.is_empty() { | |
| match trigger_settings { | |
| Trigger::Manual(_) | Trigger::Bazarr(_) => Query::<ManualQueryParams>::from_query(req.query_string()) | |
| .map(|q| TriggerQueryParams::Manual(q.into_inner())) | |
| .or_else(|_| { | |
| Query::<AutoscanQueryParams>::from_query(req.query_string()).map(|q| { | |
| TriggerQueryParams::Manual(ManualQueryParams { | |
| path: q.into_inner().dir, | |
| hash: None, | |
| }) | |
| }) | |
| }) | |
| .ok(), | |
| Trigger::Autoscan(_) => Query::<AutoscanQueryParams>::from_query(req.query_string()) | |
| .map(|q| TriggerQueryParams::Autoscan(q.into_inner())) | |
| .ok(), | |
| _ => None, | |
| } | |
| } else { | |
| None | |
| }; | |
| if let Some(query) = query_fallback { | |
| return trigger_get_inner(&trigger, query, &manager, trigger_settings).await; | |
| } | |
| let parsed_body: Option<serde_json::Value> = if body.is_empty() { | |
| None | |
| } else { | |
| Some( | |
| serde_json::from_slice(&body) | |
| .map_err(|_| actix_web::error::ErrorBadRequest("Invalid JSON body"))?, | |
| ) | |
| }; |
dan-online
reviewed
Apr 9, 2026
Owner
There was a problem hiding this comment.
Not implemented feels a little odd here. I think 400 Invalid request would be a safer response for unsupported combinations.
Something like:
Suggested change
| _ => Ok(HttpResponse::BadRequest().body("Invalid request")), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /triggers/manual?dir=/pathwith an empty body (seetargets/autoscan/api.go)Changes
trigger_postto accept rawBytesinstead ofJson<Value>, allowing empty bodiestrigger_get_inner()to avoid code duplicationHow autoscan sends requests
From
targets/autoscan/api.goin the autoscan repo:Test plan
POST /triggers/<autoscan-type>?dir=/pathwith no body → should succeed (was failing)POST /triggers/<manual-type>?path=/filewith no body → should succeed (was failing)GET /triggers/<autoscan-type>?dir=/path→ should still work (unchanged)GET /triggers/<manual-type>?path=/file→ should still work (unchanged)POST /triggers/sonarrwith JSON body → should still work (unchanged)HEAD /triggers/manualhealth check → should still work (unchanged)🤖 Generated with Claude Code