Skip to content

Commit

Permalink
Extract some strings as constants
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Jul 24, 2024
1 parent ad09a66 commit 0e14397
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions engine/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (

contentType = "Content-Type"
htmlUTF8 = "text/html;charset=utf-8"
textUTF8 = "text/plain;charset=utf-8"
)

var oc *ollamaclient.Config
Expand Down Expand Up @@ -404,7 +405,7 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, l
// Text and configuration files (most likely)
case "", ".asciidoc", ".conf", ".config", ".diz", ".example", ".gitignore", ".gitmodules", ".ini", ".log", ".lst", ".me", ".nfo", ".pem", ".readme", ".sub", ".sum", ".tml", ".toml", ".txt", ".yaml", ".yml":
// Set headers for displaying it in the browser.
w.Header().Set(contentType, "text/plain;charset=utf-8")
w.Header().Set(contentType, textUTF8)

// Source files that may be used by web pages
case ".js":
Expand All @@ -417,7 +418,7 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, l
// Source code files for viewing
case ".S", ".ada", ".asm", ".bash", ".bat", ".c", ".c++", ".cc", ".cl", ".clj", ".cpp", ".cs", ".cxx", ".el", ".elm", ".erl", ".fish", ".go", ".h", ".h++", ".hpp", ".hs", ".java", ".kt", ".lisp", ".mk", ".ml", ".pas", ".pl", ".py", ".r", ".rb", ".rs", ".scm", ".sh", ".ts", ".tsx":
// Set headers for displaying it in the browser.
w.Header().Set(contentType, "text/plain;charset=utf-8")
w.Header().Set(contentType, textUTF8)

// Common binary file extensions
case ".7z", ".arj", ".bin", ".com", ".dat", ".db", ".elf", ".exe", ".gz", ".iso", ".lz", ".rar", ".tar.bz", ".tar.bz2", ".tar.gz", ".tar.xz", ".tbz", ".tbz2", ".tgz", ".txz", ".xz", ".zip":
Expand All @@ -427,7 +428,7 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, l
default:
// If the filename starts with a ".", assume it's a plain text configuration file
if strings.HasPrefix(filepath.Base(lowercaseFilename), ".") {
w.Header().Set(contentType, "text/plain;charset=utf-8")
w.Header().Set(contentType, textUTF8)
} else {
// Set the correct Content-Type
if ac.mimereader != nil {
Expand Down

0 comments on commit 0e14397

Please sign in to comment.