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

View File

@@ -3,20 +3,31 @@ import { apis } from '@affine/electron-api';
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) {
target = /^https?:\/\//.test(target)
? target
: BUILD_CONFIG.serverUrlPrefix + target;
const isFullUrl = /^https?:\/\//.test(target);
const redirectProxy = origin + '/redirect-proxy';
target = isFullUrl ? target : origin + target;
const targetUrl = new URL(target);
let url: string;
// safe to open directly if in the same origin
if (targetUrl.origin === location.origin) {
if (targetUrl.origin === origin) {
url = target;
} else {
const builder = new URL(BUILD_CONFIG.serverUrlPrefix + '/redirect-proxy');
builder.searchParams.set('redirect_uri', target);
url = builder.toString();
const search = new URLSearchParams({
redirect_uri: target,
});
url = `${redirectProxy}?${search.toString()}`;
}
if (BUILD_CONFIG.isElectron) {