Upgrade JS and Go deps versions (#517)

This commit is contained in:
Thomas Miceli
2025-10-07 16:59:37 +02:00
committed by GitHub
parent f0a596aed0
commit f653179cbf
81 changed files with 2487 additions and 6227 deletions

View File

@@ -54,18 +54,19 @@ func AllGists(ctx *context.Context) error {
mode := ctx.GetData("mode")
if fromUserStr == "" {
if mode == "search" {
switch mode {
case "search":
ctx.SetData("htmlTitle", ctx.TrH("gist.list.search-results"))
ctx.SetData("searchQuery", ctx.QueryParam("q"))
pagination.Query = ctx.QueryParam("q")
urlPage = "search"
gists, err = db.GetAllGistsFromSearch(currentUserId, ctx.QueryParam("q"), pageInt-1, sort, order, "")
} else if mode == "topics" {
case "topics":
ctx.SetData("htmlTitle", ctx.TrH("gist.list.topic-results-topic", ctx.Param("topic")))
ctx.SetData("topic", ctx.Param("topic"))
urlPage = "topics/" + ctx.Param("topic")
gists, err = db.GetAllGistsFromSearch(currentUserId, "", pageInt-1, sort, order, ctx.Param("topic"))
} else if mode == "all" {
case "all":
ctx.SetData("htmlTitle", ctx.TrH("gist.list.all"))
urlPage = "all"
gists, err = db.GetAllGistsForCurrentUser(currentUserId, pageInt-1, sort, order)
@@ -101,15 +102,16 @@ func AllGists(ctx *context.Context) error {
ctx.SetData("countForked", countForked)
}
if mode == "liked" {
switch mode {
case "liked":
urlPage = fromUserStr + "/liked"
ctx.SetData("htmlTitle", ctx.TrH("gist.list.all-liked-by", fromUserStr))
gists, err = db.GetAllGistsLikedByUser(fromUser.ID, currentUserId, pageInt-1, sort, order)
} else if mode == "forked" {
case "forked":
urlPage = fromUserStr + "/forked"
ctx.SetData("htmlTitle", ctx.TrH("gist.list.all-forked-by", fromUserStr))
gists, err = db.GetAllGistsForkedByUser(fromUser.ID, currentUserId, pageInt-1, sort, order)
} else if mode == "fromUser" {
case "fromUser":
urlPage = fromUserStr
if languages, err := db.GetGistLanguagesForUser(fromUser.ID, currentUserId); err != nil {

View File

@@ -22,10 +22,7 @@ func Create(ctx *context.Context) error {
}
func ProcessCreate(ctx *context.Context) error {
isCreate := false
if ctx.Request().URL.Path == "/" {
isCreate = true
}
isCreate := ctx.Request().URL.Path == "/"
err := ctx.Request().ParseForm()
if err != nil {
@@ -151,7 +148,7 @@ func ProcessCreate(ctx *context.Context) error {
if err != nil {
return ctx.ErrorRes(500, "Error creating an UUID", err)
}
gist.Uuid = strings.Replace(uuidGist.String(), "-", "", -1)
gist.Uuid = strings.ReplaceAll(uuidGist.String(), "-", "")
gist.UserID = user.ID
gist.User = *user

View File

@@ -2,12 +2,13 @@ package gist
import (
"errors"
"strings"
"github.com/google/uuid"
"github.com/thomiceli/opengist/internal/db"
"github.com/thomiceli/opengist/internal/web/context"
"github.com/thomiceli/opengist/internal/web/handlers"
"gorm.io/gorm"
"strings"
)
func Fork(ctx *context.Context) error {
@@ -34,7 +35,7 @@ func Fork(ctx *context.Context) error {
}
newGist := &db.Gist{
Uuid: strings.Replace(uuidGist.String(), "-", "", -1),
Uuid: strings.ReplaceAll(uuidGist.String(), "-", ""),
Title: gist.Title,
Preview: gist.Preview,
PreviewFilename: gist.PreviewFilename,

View File

@@ -97,8 +97,10 @@ func GistJson(ctx *context.Context) error {
}
func GistJs(ctx *context.Context) error {
theme := "light"
if _, exists := ctx.QueryParams()["dark"]; exists {
ctx.SetData("dark", "dark")
theme = "dark"
}
gist := ctx.GetData("gist").(*db.Gist)
@@ -117,16 +119,21 @@ func GistJs(ctx *context.Context) error {
}
_ = w.Flush()
cssUrl, err := url.JoinPath(ctx.GetData("baseHttpUrl").(string), context.ManifestEntries["embed.css"].File)
cssUrl, err := url.JoinPath(ctx.GetData("baseHttpUrl").(string), context.ManifestEntries["ts/embed.ts"].Css[0])
if err != nil {
return ctx.ErrorRes(500, "Error joining css url", err)
}
js, err := escapeJavaScriptContent(htmlbuf.String(), cssUrl)
themeUrl, err := url.JoinPath(ctx.GetData("baseHttpUrl").(string), context.ManifestEntries["ts/"+theme+".ts"].Css[0])
if err != nil {
return ctx.ErrorRes(500, "Error joining theme url", err)
}
js, err := escapeJavaScriptContent(htmlbuf.String(), cssUrl, themeUrl)
if err != nil {
return ctx.ErrorRes(500, "Error escaping JavaScript content", err)
}
ctx.Response().Header().Set("Content-Type", "application/javascript")
ctx.Response().Header().Set("Content-Type", "text/javascript")
return ctx.PlainText(200, js)
}
@@ -141,7 +148,7 @@ func Preview(ctx *context.Context) error {
return ctx.PlainText(200, previewStr)
}
func escapeJavaScriptContent(htmlContent, cssUrl string) (string, error) {
func escapeJavaScriptContent(htmlContent, cssUrl, themeUrl string) (string, error) {
jsonContent, err := gojson.Marshal(htmlContent)
if err != nil {
return "", fmt.Errorf("failed to encode content: %w", err)
@@ -152,11 +159,18 @@ func escapeJavaScriptContent(htmlContent, cssUrl string) (string, error) {
return "", fmt.Errorf("failed to encode CSS URL: %w", err)
}
jsonThemeUrl, err := gojson.Marshal(themeUrl)
if err != nil {
return "", fmt.Errorf("failed to encode Theme URL: %w", err)
}
js := fmt.Sprintf(`
document.write('<link rel="stylesheet" href=%s>');
document.write('<link rel="stylesheet" href=%s>');
document.write(%s);
`,
string(jsonCssUrl),
string(jsonThemeUrl),
string(jsonContent),
)