[GH-ISSUE #202] Allow overriding specific builtin assets #100

Closed
opened 2026-04-08 16:50:21 +03:00 by zhus · 2 comments
Owner

Originally created by @luaneko on GitHub (Mar 30, 2023).
Original GitHub issue: https://github.com/sigoden/dufs/issues/202

Specific Demand

It would be useful to be able to override a specific asset file without having to override all assets. Oftentimes overriding index.html and index.js is not necessary and only favicon.ico and index.css need to be overridden for theme customization. Unchanged asset files on disk need to be updated manually from new commits in the repository, which is inconvenient and error-prone.

Implement Suggestion

We could modify the asset handler to use builtin assets as a fallback if an asset directory was specified and the corresponding asset file does not exist on disk.

e43554b795/src/server.rs (L557-L562)

Something like this:

let path = assets_path.join(name); 
if /* path exists */ {
    self.handle_send_file(&path, headers, false, res).await?;
} else {
    // fall back to builtin asset handler for name
}

A CLI option could be introduced to opt into this behavior if backwards compatibility is desired.

Originally created by @luaneko on GitHub (Mar 30, 2023). Original GitHub issue: https://github.com/sigoden/dufs/issues/202 ## Specific Demand It would be useful to be able to override a specific asset file without having to override all assets. Oftentimes overriding `index.html` and `index.js` is not necessary and only `favicon.ico` and `index.css` need to be overridden for theme customization. Unchanged asset files on disk need to be updated manually from new commits in the repository, which is inconvenient and error-prone. ## Implement Suggestion We could modify the asset handler to use builtin assets as a fallback if an asset directory was specified and the corresponding asset file does not exist on disk. https://github.com/sigoden/dufs/blob/e43554b7952453463d894097f443b3387f5ebb9d/src/server.rs#L557-L562 Something like this: ```rust let path = assets_path.join(name); if /* path exists */ { self.handle_send_file(&path, headers, false, res).await?; } else { // fall back to builtin asset handler for name } ``` A CLI option could be introduced to opt into this behavior if backwards compatibility is desired.
zhus closed this issue 2026-04-08 16:50:21 +03:00
Author
Owner

@sigoden commented on GitHub (Apr 1, 2023):

I am not in favor of this proposal.

index.html, index.js and index.css are a whole. They need to be upgraded together, or stay in the old version together.

This PR may lead to a situation:
You created an index.css based on v0.33.
dufs v0.34 added a feature that causes index.css to add .foo class.
You upgraded to v0.34, but you forgot to update index.css, so .foo class is missing and the UI is broken.

But if you have a complete copy of the UI in assets folder, there will be no problem upgrading dufs, you just won't be able to use the new features.

<!-- gh-comment-id:1492800806 --> @sigoden commented on GitHub (Apr 1, 2023): I am not in favor of this proposal. `index.html`, `index.js` and `index.css` are a whole. They need to be upgraded together, or stay in the old version together. This PR may lead to a situation: You created an index.css based on v0.33. dufs v0.34 added a feature that causes index.css to add `.foo` class. You upgraded to v0.34, but you forgot to update `index.css`, so `.foo` class is missing and the UI is broken. But if you have a complete copy of the UI in assets folder, there will be no problem upgrading dufs, you just won't be able to use the new features.
Author
Owner

@0xF4CED commented on GitHub (May 24, 2023):

How about a --favicon=/path/to/favicon.ico option?
Currently one has to maintain the whole assets directory just to customize the favicon.
@sigoden

<!-- gh-comment-id:1561067271 --> @0xF4CED commented on GitHub (May 24, 2023): How about a --favicon=/path/to/favicon.ico option? Currently one has to maintain the whole assets directory just to customize the favicon. @sigoden
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sigoden/dufs#100