From b34bfc2dbf4499b56ce3add4143940c4650160f6 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 11 Feb 2023 19:44:06 +0800 Subject: [PATCH 1/2] fix --- templates/base/head_script.tmpl | 1 + templates/package/content/cargo.tmpl | 2 +- templates/package/content/chef.tmpl | 2 +- templates/package/content/composer.tmpl | 2 +- templates/package/content/conan.tmpl | 2 +- templates/package/content/conda.tmpl | 6 +++--- templates/package/content/generic.tmpl | 7 +++++-- templates/package/content/helm.tmpl | 2 +- templates/package/content/maven.tmpl | 8 ++++---- templates/package/content/npm.tmpl | 2 +- templates/package/content/nuget.tmpl | 2 +- templates/package/content/pub.tmpl | 2 +- templates/package/content/pypi.tmpl | 2 +- templates/package/content/rubygems.tmpl | 4 ++-- templates/package/content/vagrant.tmpl | 2 +- templates/post-install.tmpl | 2 +- .../view_content/pull_merge_instruction.tmpl | 3 +-- templates/repo/view_list.tmpl | 2 +- templates/swagger/ui.tmpl | 4 ++-- web_src/js/custcomp/GiteaOriginUrl.js | 17 +++++++++++++++++ webpack.config.js | 3 +++ 21 files changed, 50 insertions(+), 27 deletions(-) create mode 100644 web_src/js/custcomp/GiteaOriginUrl.js diff --git a/templates/base/head_script.tmpl b/templates/base/head_script.tmpl index c4ac18a86ee5e..de77856d4b2de 100644 --- a/templates/base/head_script.tmpl +++ b/templates/base/head_script.tmpl @@ -46,3 +46,4 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly. {{/* in case some pages don't render the pageData, we make sure it is an object to prevent null access */}} window.config.pageData = window.config.pageData || {}; + diff --git a/templates/package/content/cargo.tmpl b/templates/package/content/cargo.tmpl index 54c40a5b0dc0a..f78647ca69c63 100644 --- a/templates/package/content/cargo.tmpl +++ b/templates/package/content/cargo.tmpl @@ -8,7 +8,7 @@ default = "gitea" [registries.gitea] -index = "{{AppUrl}}{{.PackageDescriptor.Owner.Name}}/_cargo-index.git" +index = "" [net] git-fetch-with-cli = true diff --git a/templates/package/content/chef.tmpl b/templates/package/content/chef.tmpl index f0f8de7bd5587..edc175f9beddc 100644 --- a/templates/package/content/chef.tmpl +++ b/templates/package/content/chef.tmpl @@ -4,7 +4,7 @@
-
knife[:supermarket_site] = '{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/chef'
+
knife[:supermarket_site] = ''
diff --git a/templates/package/content/composer.tmpl b/templates/package/content/composer.tmpl index 8cc18f8ba8fb7..9acf20955c891 100644 --- a/templates/package/content/composer.tmpl +++ b/templates/package/content/composer.tmpl @@ -7,7 +7,7 @@
{
 	"repositories": [{
 			"type": "composer",
-			"url": "{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/composer"
+			"url": ""
 		}
 	]
 }
diff --git a/templates/package/content/conan.tmpl b/templates/package/content/conan.tmpl index c496cee55cf62..138890f334c52 100644 --- a/templates/package/content/conan.tmpl +++ b/templates/package/content/conan.tmpl @@ -4,7 +4,7 @@
-
conan remote add gitea {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/conan
+
conan remote add gitea 
diff --git a/templates/package/content/conda.tmpl b/templates/package/content/conda.tmpl index ecc26bce98e64..3c79d3902fae6 100644 --- a/templates/package/content/conda.tmpl +++ b/templates/package/content/conda.tmpl @@ -4,11 +4,11 @@
-
channel_alias: {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/conda
+				
channel_alias: 
 channels:
-  - {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/conda
+  - 
 default_channels:
-  - {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/conda
+ -
diff --git a/templates/package/content/generic.tmpl b/templates/package/content/generic.tmpl index 2948d9eb02cac..eae4d670f9c6f 100644 --- a/templates/package/content/generic.tmpl +++ b/templates/package/content/generic.tmpl @@ -4,8 +4,11 @@
-
{{range .PackageDescriptor.Files}}curl {{AppUrl}}api/packages/{{$.PackageDescriptor.Owner.Name}}/generic/{{$.PackageDescriptor.Package.Name}}/{{$.PackageDescriptor.Version.Version}}/{{.File.Name}}
-{{end}}
+

+					{{- range .PackageDescriptor.Files -}}
+curl 
+ {{- end -}} +
diff --git a/templates/package/content/helm.tmpl b/templates/package/content/helm.tmpl index 59cdc157b4087..fc190e0e459bb 100644 --- a/templates/package/content/helm.tmpl +++ b/templates/package/content/helm.tmpl @@ -4,7 +4,7 @@
-
helm repo add gitea {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/helm
+				
helm repo add gitea 
 helm repo update
diff --git a/templates/package/content/maven.tmpl b/templates/package/content/maven.tmpl index 0b5612151c577..ff89145fd0023 100644 --- a/templates/package/content/maven.tmpl +++ b/templates/package/content/maven.tmpl @@ -7,19 +7,19 @@
<repositories>
 	<repository>
 		<id>gitea</id>
-		<url>{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/maven</url>
+			<url></url>
 	</repository>
 </repositories>
 
 <distributionManagement>
 	<repository>
 		<id>gitea</id>
-		<url>{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/maven</url>
+		<url></url>
 	</repository>
 
 	<snapshotRepository>
 		<id>gitea</id>
-		<url>{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/maven</url>
+		<url></url>
 	</snapshotRepository>
 </distributionManagement>
@@ -37,7 +37,7 @@
-
mvn dependency:get -DremoteRepositories={{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/maven -Dartifact={{.PackageDescriptor.Metadata.GroupID}}:{{.PackageDescriptor.Metadata.ArtifactID}}:{{.PackageDescriptor.Version.Version}}
+
mvn dependency:get -DremoteRepositories= -Dartifact={{.PackageDescriptor.Metadata.GroupID}}:{{.PackageDescriptor.Metadata.ArtifactID}}:{{.PackageDescriptor.Version.Version}}
diff --git a/templates/package/content/npm.tmpl b/templates/package/content/npm.tmpl index 33d51d4dfd87d..ea514c5263ad9 100644 --- a/templates/package/content/npm.tmpl +++ b/templates/package/content/npm.tmpl @@ -4,7 +4,7 @@
-
{{if .PackageDescriptor.Metadata.Scope}}{{.PackageDescriptor.Metadata.Scope}}:{{end}}registry={{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/npm/
+
{{if .PackageDescriptor.Metadata.Scope}}{{.PackageDescriptor.Metadata.Scope}}:{{end}}registry=
diff --git a/templates/package/content/nuget.tmpl b/templates/package/content/nuget.tmpl index 4ea41fa826a28..8ed2f04e4a55f 100644 --- a/templates/package/content/nuget.tmpl +++ b/templates/package/content/nuget.tmpl @@ -4,7 +4,7 @@
-
dotnet nuget add source --name Gitea --username your_username --password your_token {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/nuget/index.json
+
dotnet nuget add source --name Gitea --username your_username --password your_token 
diff --git a/templates/package/content/pub.tmpl b/templates/package/content/pub.tmpl index 999e48ce82011..e81439d4daece 100644 --- a/templates/package/content/pub.tmpl +++ b/templates/package/content/pub.tmpl @@ -4,7 +4,7 @@
-
dart pub add {{.PackageDescriptor.Package.Name}}:{{.PackageDescriptor.Version.Version}} --hosted-url={{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/pub/
+
dart pub add {{.PackageDescriptor.Package.Name}}:{{.PackageDescriptor.Version.Version}} --hosted-url=
diff --git a/templates/package/content/pypi.tmpl b/templates/package/content/pypi.tmpl index 1ae243813de65..830ba9bd67e54 100644 --- a/templates/package/content/pypi.tmpl +++ b/templates/package/content/pypi.tmpl @@ -4,7 +4,7 @@
-
pip install --index-url {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/pypi/simple {{.PackageDescriptor.Package.Name}}
+
pip install --index-url 
diff --git a/templates/package/content/rubygems.tmpl b/templates/package/content/rubygems.tmpl index 0cb7b670b1dea..d8190ba4f59df 100644 --- a/templates/package/content/rubygems.tmpl +++ b/templates/package/content/rubygems.tmpl @@ -4,11 +4,11 @@
-
gem install {{.PackageDescriptor.Package.Name}} --version "{{.PackageDescriptor.Version.Version}}" --source "{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/rubygems"
+
gem install {{.PackageDescriptor.Package.Name}} --version "{{.PackageDescriptor.Version.Version}}" --source ""
-
source "{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/rubygems" do
+				
source "" do
 	gem "{{.PackageDescriptor.Package.Name}}", "{{.PackageDescriptor.Version.Version}}"
 end
diff --git a/templates/package/content/vagrant.tmpl b/templates/package/content/vagrant.tmpl index 7bd686e6ab689..a6a92f5ecd8cb 100644 --- a/templates/package/content/vagrant.tmpl +++ b/templates/package/content/vagrant.tmpl @@ -4,7 +4,7 @@
-
vagrant box add --box-version {{.PackageDescriptor.Version.Version}} "{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/vagrant/{{.PackageDescriptor.Package.Name}}"
+
vagrant box add --box-version {{.PackageDescriptor.Version.Version}} ""
diff --git a/templates/post-install.tmpl b/templates/post-install.tmpl index e098f43fda82e..0d6cd3082c185 100644 --- a/templates/post-install.tmpl +++ b/templates/post-install.tmpl @@ -13,7 +13,7 @@
diff --git a/templates/repo/issue/view_content/pull_merge_instruction.tmpl b/templates/repo/issue/view_content/pull_merge_instruction.tmpl index 21bb3d8e79b90..b7e61cdf94ffc 100644 --- a/templates/repo/issue/view_content/pull_merge_instruction.tmpl +++ b/templates/repo/issue/view_content/pull_merge_instruction.tmpl @@ -5,8 +5,7 @@
{{if eq $.Issue.PullRequest.Flow 0}}
git checkout -b {{if ne $.Issue.PullRequest.HeadRepo.ID $.Issue.PullRequest.BaseRepo.ID}}{{$.Issue.PullRequest.HeadRepo.OwnerName}}-{{end}}{{$.Issue.PullRequest.HeadBranch}} {{$.Issue.PullRequest.BaseBranch}}
- {{/* the only legacy HTMLURL used in template, which doesn't affect users too much and is very diffcult to fix, it should be fixed together with other AppUrl usages*/}} -
git pull {{if ne $.Issue.PullRequest.HeadRepo.ID $.Issue.PullRequest.BaseRepo.ID}}{{$.Issue.PullRequest.HeadRepo.HTMLURL}}{{else}}origin{{end}} {{$.Issue.PullRequest.HeadBranch}}
+
git pull {{if ne $.Issue.PullRequest.HeadRepo.ID $.Issue.PullRequest.BaseRepo.ID}}{{else}}origin{{end}} {{$.Issue.PullRequest.HeadBranch}}
{{else}}
git fetch origin {{$.Issue.PullRequest.GetGitRefName}}:{{$.Issue.PullRequest.HeadBranch}}
{{end}} diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index b923a9e6c08b2..61bdf712f6ae1 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -52,7 +52,7 @@ {{if $entry.IsSubModule}} {{svg "octicon-file-submodule"}} - {{$refURL := $subModuleFile.RefURL AppUrl $.Repository.FullName $.SSHDomain}} + {{$refURL := $subModuleFile.RefURL AppUrl $.Repository.FullName $.SSHDomain}} {{/* FIXME: the usage of AppUrl seems incorrect, it would be fixed in the future, use AppSubUrl instead */}} {{if $refURL}} {{$entry.Name}}@{{ShortSha $subModuleFile.RefID}} {{else}} diff --git a/templates/swagger/ui.tmpl b/templates/swagger/ui.tmpl index d4d0889f9d4ab..57b560bc1591d 100644 --- a/templates/swagger/ui.tmpl +++ b/templates/swagger/ui.tmpl @@ -6,8 +6,8 @@ - {{svg "octicon-reply"}}{{.locale.Tr "return_to_gitea"}} -
+ {{svg "octicon-reply"}}{{.locale.Tr "return_to_gitea"}} +
diff --git a/web_src/js/custcomp/GiteaOriginUrl.js b/web_src/js/custcomp/GiteaOriginUrl.js new file mode 100644 index 0000000000000..47fd13bfc1d7e --- /dev/null +++ b/web_src/js/custcomp/GiteaOriginUrl.js @@ -0,0 +1,17 @@ +// this is a Gitea's private HTML component, it converts an absolute or relative URL to an absolute URL with the current origin +window.customElements.define('gitea-origin-url', class extends HTMLElement { + connectedCallback() { + const urlStr = this.getAttribute('data-url'); + try { + // only process absolute HTTP/HTTPS URL or relative URLs ('/xxx' or '//host/xxx') + if (urlStr.startsWith('http://') || urlStr.startsWith('https://') || urlStr.startsWith('/')) { + const url = new URL(urlStr, window.origin); + url.protocol = window.location.protocol; + url.host = window.location.host; + this.textContent = url.toString(); + return; + } + } catch {} + this.textContent = urlStr; + } +}); diff --git a/webpack.config.js b/webpack.config.js index e5e592052e115..e255f2d7f14bf 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -59,6 +59,9 @@ export default { fileURLToPath(new URL('web_src/fomantic/build/semantic.css', import.meta.url)), fileURLToPath(new URL('web_src/less/index.less', import.meta.url)), ], + custcomp: [ + fileURLToPath(new URL('web_src/js/custcomp/GiteaOriginUrl.js', import.meta.url)), + ], swagger: [ fileURLToPath(new URL('web_src/js/standalone/swagger.js', import.meta.url)), fileURLToPath(new URL('web_src/less/standalone/swagger.less', import.meta.url)), From 896b6b7d695f81eabb2d32803d159380d048ccd0 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 15 Feb 2023 09:39:14 +0800 Subject: [PATCH 2/2] rename to webcomponents, remove onerror, --- templates/base/head_script.tmpl | 2 +- web_src/js/{custcomp => webcomponents}/GiteaOriginUrl.js | 0 webpack.config.js | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename web_src/js/{custcomp => webcomponents}/GiteaOriginUrl.js (100%) diff --git a/templates/base/head_script.tmpl b/templates/base/head_script.tmpl index de77856d4b2de..efe58dcc1a50f 100644 --- a/templates/base/head_script.tmpl +++ b/templates/base/head_script.tmpl @@ -46,4 +46,4 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly. {{/* in case some pages don't render the pageData, we make sure it is an object to prevent null access */}} window.config.pageData = window.config.pageData || {}; - + diff --git a/web_src/js/custcomp/GiteaOriginUrl.js b/web_src/js/webcomponents/GiteaOriginUrl.js similarity index 100% rename from web_src/js/custcomp/GiteaOriginUrl.js rename to web_src/js/webcomponents/GiteaOriginUrl.js diff --git a/webpack.config.js b/webpack.config.js index e255f2d7f14bf..2ac463abef2b6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -59,8 +59,8 @@ export default { fileURLToPath(new URL('web_src/fomantic/build/semantic.css', import.meta.url)), fileURLToPath(new URL('web_src/less/index.less', import.meta.url)), ], - custcomp: [ - fileURLToPath(new URL('web_src/js/custcomp/GiteaOriginUrl.js', import.meta.url)), + webcomponents: [ + fileURLToPath(new URL('web_src/js/webcomponents/GiteaOriginUrl.js', import.meta.url)), ], swagger: [ fileURLToPath(new URL('web_src/js/standalone/swagger.js', import.meta.url)),