-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fileserver: Browse symlink display shows the target #5973
fileserver: Browse symlink display shows the target #5973
Conversation
bbd4558
to
11b4986
Compare
Just ran |
Thanks for the PR! My only thought is that maybe dereferencing a symlink should be optional. Some people may not want to show the linked path information. How would you feel about implementing a simple config setting for this? |
@mholt sure thing! One question to make sure I understand this correctly. The config setting will be part of the browse sub-directive syntax? If not, Is there another place in the codebase where we are doing something similar that I can take inspiration from? Thank you for taking the time to review this! |
Yeah, it'd likely have to be a subdirective of the |
Sounds good. Thanks for the clarification. |
Thank you for making this an opt-in. I use the browse template to show certain users/clients what files they can download and some of them are sym-linked to a central location and I would not like to reveal this internal thing. |
e91dbeb
to
a815cff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! I'm looking forward to merging this, I just had a few last-minute thoughts before we do.
|
||
symLinkTarget, err := filepath.EvalSymlinks(path) | ||
if err == nil { | ||
symLinkRepresentation = name + " -> " + symLinkTarget |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, how about if we use a Tabler SVG icon for this arrow?
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-arrow-narrow-right" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l14 0" /><path d="M15 16l4 -4" /><path d="M15 8l4 4" /></svg>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, do we just add the svg tag mentioned above to the symLinkRepresentation
string or is there another/better way of doing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, just replace the " -> "
string with the " <svg ...> "
string.
You could move that into a separate variable for readability though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying this and the " <svg ...> "
gets displayed as it is inside the html. I believe the value passed to the go template needs to be of type template.HTML in order for it to parse it as html rather than the raw string. If so, how do you suggest we treat this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's probably true. In that case, the correct way to handle this would be to create a new field in the fileInfo
struct, maybe called Symlink
or SymlinkName
or SymlinkPath
or something. Then the UI will render the arrow SVG icon and the symlink info. Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mholt I think I got what you mean. As you can see now, I added a field called SymlinkPath
to the fileInfo
struct. This new field is a slice of strings that can either be empty or containing two elements (first one being the name of the symlink and the second one being the target of the symlink). This slice gets filled in only when the file is a symlink and the reveal_symlinks
directive is enabled. Therefore, in the browse.html
file we can check if this slice is empty and in that case display the name otherwise display the first element of the slice followed by theS SVG icon followed by the second element of the slice. Is this a valid approach?
be8648d
to
d04bdd9
Compare
@mholt All the feedback items should be addressed now. The only one not resolved yet is the "" vs "->" and as mentioned in the comment above, I was getting the raw "..." string when inserting it directly into the symlink representation as recommended. Thanks again for your continuous help with this! |
Thanks! Just had a sit at my desk and was able to comprehend what you meant, I just replied above. |
d04bdd9
to
6604ba3
Compare
6604ba3
to
3ecc69f
Compare
3ecc69f
to
ae9b605
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM now. Thanks so much for iterating on this with us, @armadi1809 -- hopefully people will find it useful!
Resolves #5810
I tested this change with both the
file_server
directive as well as thecaddy file-server
command and it's working for both. Please let me know if I missed something.