diff options
author | Giteabot <teabot@gitea.io> | 2023-10-11 22:12:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 16:12:31 +0200 |
commit | 7ec7c733c7f961b9ac0241fad36a1292124e5106 (patch) | |
tree | 71e345df67fc54e8e8c70d61dfd99e6f5945d541 /routers/web/repo | |
parent | 4986dc835118d117a07596b4fd3dc5a58a417002 (diff) | |
download | gitea-7ec7c733c7f961b9ac0241fad36a1292124e5106.tar.gz gitea-7ec7c733c7f961b9ac0241fad36a1292124e5106.zip |
Replace ajax with fetch, improve image diff (#27267) (#27583)
Backport #27267 by @silverwind
1. Dropzone attachment removal, pretty simple replacement
2. Image diff: The previous code fetched every image twice, once via
`img[src]` and once via `$.ajax`. Now it's only fetched once and a
second time only when necessary. The image diff code was partially
rewritten.
Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'routers/web/repo')
-rw-r--r-- | routers/web/repo/compare.go | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 9af1d60c29..fc5f82ec06 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -32,6 +32,7 @@ import ( "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/typesniffer" "code.gitea.io/gitea/modules/upload" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/gitdiff" @@ -60,6 +61,21 @@ func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner return blob } + ctx.Data["GetSniffedTypeForBlob"] = func(blob *git.Blob) typesniffer.SniffedType { + st := typesniffer.SniffedType{} + + if blob == nil { + return st + } + + st, err := blob.GuessContentType() + if err != nil { + log.Error("GuessContentType failed: %v", err) + return st + } + return st + } + setPathsCompareContext(ctx, before, head, headOwner, headName) setImageCompareContext(ctx) setCsvCompareContext(ctx) @@ -87,16 +103,7 @@ func setPathsCompareContext(ctx *context.Context, base, head *git.Commit, headOw // setImageCompareContext sets context data that is required by image compare template func setImageCompareContext(ctx *context.Context) { - ctx.Data["IsBlobAnImage"] = func(blob *git.Blob) bool { - if blob == nil { - return false - } - - st, err := blob.GuessContentType() - if err != nil { - log.Error("GuessContentType failed: %v", err) - return false - } + ctx.Data["IsSniffedTypeAnImage"] = func(st typesniffer.SniffedType) bool { return st.IsImage() && (setting.UI.SVG.Enabled || !st.IsSvgImage()) } } |