Fix: --rm-files does not work with --route-prefix #1524#1531
Conversation
|
Hey @Jianchi-Chen, thanks for the MR! I would prefer if this fixes the problem at the source rather than trying to fix the wrongly generated URL after the fact. Since the UI already knows when it's getting a prefix, how about you try to make it generate the correct links instead? |
… changed it to check and modify before sending by the front end.
|
Hi @svenstaro, thanks for the feedback! I understand your point about fixing the issue at the source — in this case, the UI. However, when testing manually via curl, for example: So it seems the UI fix resolves the issue for normal users, but direct API calls (that include the prefix in the path) still fail. |
|
Right, but how would users arrive at an incorrect curl command in the first place? I mean, I think people would handwrite the curl command so there should not be anything to fix here, I reckon. |
|
@Jianchi-Chen so you wanna finish this up? |
|
Got it, I’ll close this then. Thanks for the feedback! |
|
Do you want to have a second attempt and try to do it the way I suggested? |
I think this the code in this PR already does this, I've been using this patch for a week, this is the HTML generated for the delete button <form class="rm_form" action="/files/rm?path=/downloads" method="POST">
<button type="submit" title="Delete">✗</button>
</form>You can see that the path for the API is under the prefix
I think this issue is impossible to solve, the only way to make it work would be to accept both the paths with and without the prefix, but that would cause bigger issues, if the user had a file in the path I think accepting the rm command without the prefix is the better option, that is what this PR already does |
|
Thanks @svenstaro and @samu698 for the feedback! I'm happy to try again. I’ll reopen the RP. Please feel free to share any specific suggestions you’d like me to follow — I’d really appreciate the guidance. |
svenstaro
left a comment
There was a problem hiding this comment.
The current approach seems to not be proper to me. You're getting the prefix from the generated path but you could just get it from the conf in page().
You could pass that to entry_row() and then you don't really have to do any string manipulation to get the prefix out of this again.
src/renderer.rs
Outdated
| fn rm_form(rm_route: &str, encoded_path: &str, prefix: Option<String>) -> Markup { | ||
| let mut striped_path = encoded_path; | ||
| if let Some(p) = prefix { | ||
| striped_path = encoded_path.strip_prefix(&p).unwrap_or(rm_route); |
There was a problem hiding this comment.
| striped_path = encoded_path.strip_prefix(&p).unwrap_or(rm_route); | |
| stripped_path = encoded_path.strip_prefix(&p).unwrap_or(rm_route); |
src/renderer.rs
Outdated
| show_exact_bytes: bool, | ||
| actions_conf: Option<ActionsConf>, | ||
| ) -> Markup { | ||
| // If there is a prefix, the variable "prefix" will include it. |
There was a problem hiding this comment.
It's a bit odd to mention the very variable name you're commenting on in the same comment, no?
|
I've updated the PR according to your suggestions. Thanks for the review! |
|
Ok great! Do you want to add a test for this to make sure the behavior doesn't regress? |
|
sure! I've added a test for the prefix stripping behavior. |
|
The Windows CI runner fails this test because creating symlinks requires admin privileges. Locally, when running with administrator rights, all tests pass. This issue also exists on master. |
try to fix bug #1524
Limited level, Welcome feedback.