Replace ajax with fetch, improve image diff (#27267)
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: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
dc04044716
commit
73b63d9311
9 changed files with 96 additions and 82 deletions
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue