Add binary files support (#503)
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package gist
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/thomiceli/opengist/internal/db"
|
||||
"github.com/thomiceli/opengist/internal/i18n"
|
||||
"github.com/thomiceli/opengist/internal/validator"
|
||||
"github.com/thomiceli/opengist/internal/web/context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Create(ctx *context.Context) error {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/thomiceli/opengist/internal/db"
|
||||
"github.com/thomiceli/opengist/internal/web/context"
|
||||
"github.com/thomiceli/opengist/internal/web/handlers"
|
||||
)
|
||||
|
||||
func RawFile(ctx *context.Context) error {
|
||||
@@ -20,10 +19,8 @@ func RawFile(ctx *context.Context) error {
|
||||
if file == nil {
|
||||
return ctx.NotFound("File not found")
|
||||
}
|
||||
contentType := handlers.GetContentTypeFromFilename(file.Filename)
|
||||
ContentDisposition := handlers.GetContentDisposition(file.Filename)
|
||||
ctx.Response().Header().Set("Content-Type", contentType)
|
||||
ctx.Response().Header().Set("Content-Disposition", ContentDisposition)
|
||||
ctx.Response().Header().Set("Content-Type", file.MimeType.ContentType)
|
||||
ctx.Response().Header().Set("Content-Disposition", "inline; filename=\""+file.Filename+"\"")
|
||||
return ctx.PlainText(200, file.Content)
|
||||
}
|
||||
|
||||
@@ -38,7 +35,7 @@ func DownloadFile(ctx *context.Context) error {
|
||||
return ctx.NotFound("File not found")
|
||||
}
|
||||
|
||||
ctx.Response().Header().Set("Content-Type", "text/plain")
|
||||
ctx.Response().Header().Set("Content-Type", file.MimeType.ContentType)
|
||||
ctx.Response().Header().Set("Content-Disposition", "attachment; filename="+file.Filename)
|
||||
ctx.Response().Header().Set("Content-Length", strconv.Itoa(len(file.Content)))
|
||||
_, err = ctx.Response().Write([]byte(file.Content))
|
||||
|
||||
@@ -5,12 +5,13 @@ import (
|
||||
"bytes"
|
||||
gojson "encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/thomiceli/opengist/internal/db"
|
||||
"github.com/thomiceli/opengist/internal/git"
|
||||
"github.com/thomiceli/opengist/internal/render"
|
||||
"github.com/thomiceli/opengist/internal/web/context"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GistIndex(ctx *context.Context) error {
|
||||
@@ -34,7 +35,7 @@ func GistIndex(ctx *context.Context) error {
|
||||
return ctx.ErrorRes(500, "Error fetching files", err)
|
||||
}
|
||||
|
||||
renderedFiles := render.HighlightFiles(files)
|
||||
renderedFiles := render.RenderFiles(files)
|
||||
|
||||
ctx.SetData("page", "code")
|
||||
ctx.SetData("commit", revision)
|
||||
@@ -51,7 +52,7 @@ func GistJson(ctx *context.Context) error {
|
||||
return ctx.ErrorRes(500, "Error fetching files", err)
|
||||
}
|
||||
|
||||
renderedFiles := render.HighlightFiles(files)
|
||||
renderedFiles := render.RenderFiles(files)
|
||||
ctx.SetData("files", renderedFiles)
|
||||
|
||||
topics, err := gist.GetTopics()
|
||||
@@ -106,7 +107,7 @@ func GistJs(ctx *context.Context) error {
|
||||
return ctx.ErrorRes(500, "Error fetching files", err)
|
||||
}
|
||||
|
||||
renderedFiles := render.HighlightFiles(files)
|
||||
renderedFiles := render.RenderFiles(files)
|
||||
ctx.SetData("files", renderedFiles)
|
||||
|
||||
htmlbuf := bytes.Buffer{}
|
||||
|
||||
Reference in New Issue
Block a user