diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-09-30 20:08:33 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-09-30 20:08:53 -0600 |
commit | 775c0c1040e6a6622fec39d49b354bfa194a6998 (patch) | |
tree | f46edde7ee0392ae714f4facfd4e64244814c040 /contrib/fs/file.go | |
parent | 09c482d5016cfc7b628058893a1644fdf5fa699f (diff) |
file serving refactor
* do away with fs.FS usage in gemini, like the previous refactor in gopher
* remove spartan code in contrib
* standardize fsroot/urlroot string arguments to file serving handlers
Diffstat (limited to 'contrib/fs/file.go')
-rw-r--r-- | contrib/fs/file.go | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/contrib/fs/file.go b/contrib/fs/file.go index d231466..7690a62 100644 --- a/contrib/fs/file.go +++ b/contrib/fs/file.go @@ -1,47 +1,10 @@ package fs import ( - "io/fs" "mime" "strings" - - sr "tildegit.org/tjp/sliderule" ) -// ResolveFile finds a file from a filesystem based on a request path. -// -// It only returns a non-nil file if a file is found - not a directory. -// If there is any other sort of filesystem access error, it will be -// returned. -func ResolveFile(request *sr.Request, fileSystem fs.FS) (string, fs.File, error) { - filepath := strings.TrimPrefix(request.Path, "/") - - if isPrivate(filepath) { - return "", nil, nil - } - - file, err := fileSystem.Open(filepath) - if isNotFound(err) { - return "", nil, nil - } - if err != nil { - return "", nil, err - } - - isDir, err := fileIsDir(file) - if err != nil { - _ = file.Close() - return "", nil, err - } - - if isDir { - _ = file.Close() - return "", nil, nil - } - - return filepath, file, nil -} - func mediaType(filePath string) string { if strings.HasSuffix(filePath, ".gmi") { // This may not be present in the listings searched by mime.TypeByExtension, |