summaryrefslogtreecommitdiffstats
path: root/templates/repo/diff
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2023-10-11 14:34:21 +0200
committerGitHub <noreply@github.com>2023-10-11 12:34:21 +0000
commit73b63d93117db36feda11e53099baa8995a38df0 (patch)
treea31c2ef53292219f9389f592f53aacaf7d678ba9 /templates/repo/diff
parentdc04044716088e3786497e200abe1fdfb3a943b6 (diff)
downloadgitea-73b63d93117db36feda11e53099baa8995a38df0.tar.gz
gitea-73b63d93117db36feda11e53099baa8995a38df0.zip
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>
Diffstat (limited to 'templates/repo/diff')
-rw-r--r--templates/repo/diff/box.tmpl8
-rw-r--r--templates/repo/diff/image_diff.tmpl7
2 files changed, 11 insertions, 4 deletions
diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl
index 94a5a9a295..289ed90d3f 100644
--- a/templates/repo/diff/box.tmpl
+++ b/templates/repo/diff/box.tmpl
@@ -97,7 +97,9 @@
{{/*notice: the index of Diff.Files should not be used for element ID, because the index will be restarted from 0 when doing load-more for PRs with a lot of files*/}}
{{$blobBase := call $.GetBlobByPathForCommit $.BeforeCommit $file.OldName}}
{{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}}
- {{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}}
+ {{$sniffedTypeBase := call $.GetSniffedTypeForBlob $blobBase}}
+ {{$sniffedTypeHead := call $.GetSniffedTypeForBlob $blobHead}}
+ {{$isImage:= or (call $.IsSniffedTypeAnImage $sniffedTypeBase) (call $.IsSniffedTypeAnImage $sniffedTypeHead)}}
{{$isCsv := (call $.IsCsvFile $file)}}
{{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}}
{{$isExpandable := or (gt $file.Addition 0) (gt $file.Deletion 0) $file.IsBin}}
@@ -198,9 +200,9 @@
<div id="diff-rendered-{{$file.NameHash}}" class="file-body file-code {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}} gt-overflow-x-scroll">
<table class="chroma gt-w-100">
{{if $isImage}}
- {{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}}
+ {{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}}
{{else}}
- {{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}}
+ {{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}}
{{end}}
</table>
</div>
diff --git a/templates/repo/diff/image_diff.tmpl b/templates/repo/diff/image_diff.tmpl
index 8abce9479e..02cca784f6 100644
--- a/templates/repo/diff/image_diff.tmpl
+++ b/templates/repo/diff/image_diff.tmpl
@@ -1,7 +1,12 @@
{{if or .blobBase .blobHead}}
<tr>
<td colspan="2">
- <div class="image-diff" data-path-before="{{.root.BeforeRawPath}}/{{PathEscapeSegments .file.OldName}}" data-path-after="{{.root.RawPath}}/{{PathEscapeSegments .file.Name}}">
+ <div class="image-diff"
+ data-path-before="{{.root.BeforeRawPath}}/{{PathEscapeSegments .file.OldName}}"
+ data-path-after="{{.root.RawPath}}/{{PathEscapeSegments .file.Name}}"
+ data-mime-before="{{.sniffedTypeBase.GetMimeType}}"
+ data-mime-after="{{.sniffedTypeHead.GetMimeType}}"
+ >
<div class="ui secondary pointing tabular top attached borderless menu new-menu">
<div class="new-menu-inner">
<a class="item active" data-tab="diff-side-by-side-{{.file.Index}}">{{ctx.Locale.Tr "repo.diff.image.side_by_side"}}</a>