Upgrade JS and Go deps versions (#517)

هذا الالتزام موجود في:
Thomas Miceli
2025-10-07 16:59:37 +02:00
ملتزم من قبل GitHub
الأصل f0a596aed0
التزام f653179cbf
81 ملفات معدلة مع 2487 إضافات و6227 حذوفات

عرض الملف

@@ -69,7 +69,7 @@ func (ctx *Context) ErrorRes(code int, message string, err error) error {
}
func (ctx *Context) RedirectTo(location string) error {
return ctx.Context.Redirect(302, config.C.ExternalUrl+location)
return ctx.Redirect(302, config.C.ExternalUrl+location)
}
func (ctx *Context) Html(template string) error {
@@ -145,5 +145,6 @@ func (ctx *Context) Tr(key string, args ...any) string {
var ManifestEntries map[string]Asset
type Asset struct {
File string `json:"file"`
File string `json:"file"`
Css []string `json:"css"`
}

عرض الملف

@@ -1,10 +1,11 @@
package auth
import (
"net/url"
"github.com/thomiceli/opengist/internal/auth/totp"
"github.com/thomiceli/opengist/internal/db"
"github.com/thomiceli/opengist/internal/web/context"
"net/url"
)
func BeginTotp(ctx *context.Context) error {
@@ -25,7 +26,7 @@ func BeginTotp(ctx *context.Context) error {
sess := ctx.GetSession()
generatedSecret, _ := sess.Values["generatedSecret"].([]byte)
totpSecret, qrcode, err, generatedSecret := totp.GenerateQRCode(ctx.User.Username, ogUrl.Hostname(), generatedSecret)
totpSecret, qrcode, generatedSecret, err := totp.GenerateQRCode(ctx.User.Username, ogUrl.Hostname(), generatedSecret)
if err != nil {
return ctx.ErrorRes(500, "Cannot generate TOTP QR code", err)
}

عرض الملف

@@ -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 {

عرض الملف

@@ -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

عرض الملف

@@ -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,

عرض الملف

@@ -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),
)

عرض الملف

@@ -231,7 +231,7 @@ func createGist(user *db.User, url string) (*db.Gist, error) {
if err != nil {
return nil, err
}
gist.Uuid = strings.Replace(uuidGist.String(), "-", "", -1)
gist.Uuid = strings.ReplaceAll(uuidGist.String(), "-", "")
gist.Title = "gist:" + gist.Uuid
if url != "" {

عرض الملف

@@ -92,6 +92,12 @@ func (s *Server) setFuncMap() {
}
return config.C.ExternalUrl + "/" + context.ManifestEntries[file].File
},
"assetCss": func(file string) string {
if s.dev {
return "http://localhost:16157/" + file
}
return config.C.ExternalUrl + "/" + context.ManifestEntries[file].Css[0]
},
"custom": func(file string) string {
assetpath, err := url.JoinPath("/", "assets", file)
if err != nil {
@@ -186,6 +192,17 @@ func (s *Server) setFuncMap() {
"humanDate": func(t int64) string {
return time.Unix(t, 0).Format("02/01/2006 15:04")
},
"mainTheme": func(theme *db.UserStyleDTO) string {
if theme == nil {
return "auto"
}
if theme.Theme == "" {
return "auto"
}
return theme.Theme
},
}
t := template.Must(template.New("t").Funcs(fm).ParseFS(templates.Files, "*/*.html"))
@@ -206,7 +223,7 @@ func (s *Server) setFuncMap() {
}
func (s *Server) parseManifestEntries() {
file, err := public.Files.Open("manifest.json")
file, err := public.Files.Open(".vite/manifest.json")
if err != nil {
log.Fatal().Err(err).Msg("Failed to open manifest.json")
}