Skip to content

Fix: --rm-files does not work with --route-prefix #1524#1531

Merged
svenstaro merged 6 commits intosvenstaro:masterfrom
Jianchi-Chen:fix----rm-files-does-not-work-with---route-prefix
Jan 7, 2026
Merged

Fix: --rm-files does not work with --route-prefix #1524#1531
svenstaro merged 6 commits intosvenstaro:masterfrom
Jianchi-Chen:fix----rm-files-does-not-work-with---route-prefix

Conversation

@Jianchi-Chen
Copy link
Copy Markdown
Contributor

try to fix bug #1524
Limited level, Welcome feedback.

@svenstaro
Copy link
Copy Markdown
Owner

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.
@Jianchi-Chen
Copy link
Copy Markdown
Contributor Author

Hi @svenstaro, thanks for the feedback!

I understand your point about fixing the issue at the source — in this case, the UI.
After updating the frontend generation logic, the delete button in the WebUI now works correctly, since the generated URL no longer duplicates the prefix.

However, when testing manually via curl, for example:
curl -X POST http://127.0.0.1:9999/prefix/rm?path=/prefix/testfile
still results in a 400 error, while
curl -X POST http://127.0.0.1:9999/prefix/rm?path=/testfile
works as expected.

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.
Would you prefer we leave it as-is , or also handle such cases in the backend for consistency?

@svenstaro
Copy link
Copy Markdown
Owner

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.

@svenstaro
Copy link
Copy Markdown
Owner

@Jianchi-Chen so you wanna finish this up?

@Jianchi-Chen
Copy link
Copy Markdown
Contributor Author

Got it, I’ll close this then. Thanks for the feedback!

@svenstaro
Copy link
Copy Markdown
Owner

Do you want to have a second attempt and try to do it the way I suggested?

@samu698
Copy link
Copy Markdown

samu698 commented Nov 11, 2025

Since the UI already knows when it's getting a prefix, how about you try to make it generate the correct links instead?

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 /files/ but the path parameter has no prefix

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.
Would you prefer we leave it as-is , or also handle such cases in the backend for consistency?

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 /<prefix>/file.txt the command http://127.0.0.1:9999/<prefix>/rm?path=/<prefix>/file.txt would be ambiguous.

I think accepting the rm command without the prefix is the better option, that is what this PR already does

@Jianchi-Chen
Copy link
Copy Markdown
Contributor Author

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.

@Jianchi-Chen Jianchi-Chen reopened this Nov 13, 2025
Copy link
Copy Markdown
Owner

@svenstaro svenstaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit odd to mention the very variable name you're commenting on in the same comment, no?

@Jianchi-Chen
Copy link
Copy Markdown
Contributor Author

I've updated the PR according to your suggestions. Thanks for the review!

@svenstaro
Copy link
Copy Markdown
Owner

Ok great! Do you want to add a test for this to make sure the behavior doesn't regress?

@Jianchi-Chen
Copy link
Copy Markdown
Contributor Author

sure! I've added a test for the prefix stripping behavior.
Please let me know if anything else should be improved.

@Jianchi-Chen
Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Owner

@svenstaro svenstaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@svenstaro svenstaro merged commit 1361b81 into svenstaro:master Jan 7, 2026
18 of 20 checks passed
svenstaro added a commit that referenced this pull request Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants