fix(core): avoid using serverUrlPrefix config (#8448)

This commit is contained in:
forehalo
2024-10-08 04:50:02 +00:00
parent cc4be9c670
commit e61ed98ac3
2 changed files with 21 additions and 7 deletions
+3
View File
@@ -17,6 +17,9 @@ export type BUILD_CONFIG_TYPE = {
isMobileWeb: boolean; isMobileWeb: boolean;
// this is for the electron app // this is for the electron app
/**
* @deprecated need to be refactored
*/
serverUrlPrefix: string; serverUrlPrefix: string;
appVersion: string; appVersion: string;
editorVersion: string; editorVersion: string;
+18 -7
View File
@@ -3,20 +3,31 @@ import { apis } from '@affine/electron-api';
const logger = new DebugLogger('popup'); const logger = new DebugLogger('popup');
const origin = BUILD_CONFIG.isElectron
? BUILD_CONFIG.serverUrlPrefix
: location.origin;
/**
* @deprecated need to be refactored as [UrlService] dependencies on [ServerConfigService]
*/
export function popupWindow(target: string) { export function popupWindow(target: string) {
target = /^https?:\/\//.test(target) const isFullUrl = /^https?:\/\//.test(target);
? target
: BUILD_CONFIG.serverUrlPrefix + target; const redirectProxy = origin + '/redirect-proxy';
target = isFullUrl ? target : origin + target;
const targetUrl = new URL(target); const targetUrl = new URL(target);
let url: string; let url: string;
// safe to open directly if in the same origin // safe to open directly if in the same origin
if (targetUrl.origin === location.origin) { if (targetUrl.origin === origin) {
url = target; url = target;
} else { } else {
const builder = new URL(BUILD_CONFIG.serverUrlPrefix + '/redirect-proxy'); const search = new URLSearchParams({
builder.searchParams.set('redirect_uri', target); redirect_uri: target,
url = builder.toString(); });
url = `${redirectProxy}?${search.toString()}`;
} }
if (BUILD_CONFIG.isElectron) { if (BUILD_CONFIG.isElectron) {