From e40eca2922ef39164e35de08a0f190a0743cb51e Mon Sep 17 00:00:00 2001 From: dishuostec Date: Wed, 14 Apr 2021 10:17:30 +0800 Subject: [PATCH] Use "window.location.protocol" instead of hardcoded "https". --- src/platforms/Gitea/API.ts | 8 ++++---- src/platforms/Gitea/index.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/platforms/Gitea/API.ts b/src/platforms/Gitea/API.ts index 2a7a849..c566d33 100644 --- a/src/platforms/Gitea/API.ts +++ b/src/platforms/Gitea/API.ts @@ -57,14 +57,14 @@ async function request( } } -export const API_ENDPOINT = `${window.location.host}/api/v1` +export const API_ENDPOINT = `${window.location.protocol}//${window.location.host}/api/v1` export async function getRepoMeta( userName: string, repoName: string, accessToken?: string, ): Promise { - const url = `https://${API_ENDPOINT}/repos/${userName}/${repoName}` + const url = `${API_ENDPOINT}/repos/${userName}/${repoName}` return await request(url, { accessToken }) } @@ -78,7 +78,7 @@ export async function getTreeData( const search = new URLSearchParams() if (recursive) search.set('recursive', '1') const url = - `https://${API_ENDPOINT}/repos/${userName}/${repoName}/git/trees/${branchName}?` + search + `${API_ENDPOINT}/repos/${userName}/${repoName}/git/trees/${branchName}?` + search return await request(url, { accessToken }) } @@ -88,7 +88,7 @@ export async function getBlobData( sha: string, accessToken?: string, ): Promise { - const url = `https://${API_ENDPOINT}/repos/${userName}/${repoName}/git/blobs/${sha}` + const url = `${API_ENDPOINT}/repos/${userName}/${repoName}/git/blobs/${sha}` return await request(url, { accessToken }) } diff --git a/src/platforms/Gitea/index.ts b/src/platforms/Gitea/index.ts index 04d12ee..8138794 100644 --- a/src/platforms/Gitea/index.ts +++ b/src/platforms/Gitea/index.ts @@ -65,7 +65,7 @@ function getUrlForRedirect( // Modern browsers have great support for handling unsafe URL, // It may be possible to sanitize path with // `path => path.includes('#') ? path.replace(/#/g, '%23') : '...' - return `https://${ + return `${window.location.protocol}//${ window.location.host }/${userName}/${repoName}/src/branch/${branchName}/${path .split('/') @@ -107,8 +107,8 @@ export const Gitea: Platform = { }, resolveUrlFromMetaData({ userName, repoName }) { return { - repoUrl: `https://${window.location.host}/${userName}/${repoName}`, - userUrl: `https://${window.location.host}/${userName}`, + repoUrl: `${window.location.protocol}//${window.location.host}/${userName}/${repoName}`, + userUrl: `${window.location.protocol}//${window.location.host}/${userName}`, } }, async getTreeData(metaData, path, recursive, accessToken) { @@ -163,6 +163,6 @@ export const Gitea: Platform = { return API.OAuth(code) }, getOAuthLink() { - return `https://${window.location.host}/api/v1/user/applications/oauth2` + return `${window.location.protocol}//${window.location.host}/api/v1/user/applications/oauth2` }, }