mirror of
https://github.com/thomiceli/opengist.git
synced 2025-05-13 15:52:11 +02:00
feat: add MIME type support for raw file serving (#417)
This commit is contained in:
parent
f5b8881d35
commit
0609b64cff
@ -3,9 +3,11 @@ package gist
|
|||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/thomiceli/opengist/internal/db"
|
"github.com/thomiceli/opengist/internal/db"
|
||||||
"github.com/thomiceli/opengist/internal/web/context"
|
"github.com/thomiceli/opengist/internal/web/context"
|
||||||
"strconv"
|
"github.com/thomiceli/opengist/internal/web/handlers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RawFile(ctx *context.Context) error {
|
func RawFile(ctx *context.Context) error {
|
||||||
@ -18,7 +20,8 @@ func RawFile(ctx *context.Context) error {
|
|||||||
if file == nil {
|
if file == nil {
|
||||||
return ctx.NotFound("File not found")
|
return ctx.NotFound("File not found")
|
||||||
}
|
}
|
||||||
|
contentType := handlers.GetContentTypeFromFilename(file.Filename)
|
||||||
|
ctx.Response().Header().Set("Content-Type", contentType)
|
||||||
return ctx.PlainText(200, file.Content)
|
return ctx.PlainText(200, file.Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,12 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/thomiceli/opengist/internal/web/context"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/thomiceli/opengist/internal/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetPage(ctx *context.Context) int {
|
func GetPage(ctx *context.Context) int {
|
||||||
@ -77,3 +79,13 @@ func ParseSearchQueryStr(query string) (string, map[string]string) {
|
|||||||
content := strings.TrimSpace(contentBuilder.String())
|
content := strings.TrimSpace(contentBuilder.String())
|
||||||
return content, metadata
|
return content, metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetContentTypeFromFilename(filename string) string {
|
||||||
|
ext := strings.ToLower(filepath.Ext(filename))
|
||||||
|
switch ext {
|
||||||
|
case ".css":
|
||||||
|
return "text/css"
|
||||||
|
default:
|
||||||
|
return "text/plain"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user