Skip to content

Commit

Permalink
fix: implement new remote config
Browse files Browse the repository at this point in the history
  • Loading branch information
kkostov committed May 14, 2024
1 parent ac76184 commit 54e31e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
37 changes: 10 additions & 27 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getMicrosoftStoreUrl,
} from "./src/config.js";

import { getRemoteConfig } from "./src/remoteConfig.js";
import { resolveAndParseRemoteConfigToUrl } from "./src/remoteConfig.js";

function renderFallBack(config) {
let badges = ``;
Expand Down Expand Up @@ -52,32 +52,15 @@ const executeRedirect = async () => {
// determine configuration type
const remoteUrl = getRemoteConfigUrl(location.href);
if (remoteUrl) {
const remoteConfig = await getRemoteConfig(remoteUrl);
switch (platform) {
case "Apple":
if (remoteConfig.urlApple) {
location.href = remoteConfig.urlApple;
} else {
renderFallBack({});
}
break;
case "Google":
if (remoteConfig.urlGoogle) {
location.href = remoteConfig.urlGoogle;
} else {
renderFallBack({});
}
break;
case "Microsoft":
if (remoteConfig.urlMicrosoft) {
location.href = remoteConfig.urlMicrosoft;
} else {
renderFallBack({});
}
break;
default:
renderFallBack({});
break;
const targetUrl = await resolveAndParseRemoteConfigToUrl(
remoteUrl,
platform,
Intl.DateTimeFormat().resolvedOptions().timeZone
);
if (targetUrl) {
location.href = targetUrl;
} else {
renderFallBack({});
}
} else {
// simple link
Expand Down
4 changes: 0 additions & 4 deletions src/remoteConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @ts-check

// Intl.DateTimeFormat().resolvedOptions().timeZone

export async function resolveAndParseRemoteConfigToUrl(
configRemoteUrl,
platform,
Expand Down Expand Up @@ -69,7 +67,6 @@ export function parseRemoteConfig(configJson, platform, tz) {
const matchingConfig = geographicAreaPlace.filter((target) => {
return target["audience"]["geographicArea"]["name"] === place;
})[0];
console.log("match", matchingConfig);

const url = matchingConfig["potentialAction"]["target"]["urlTemplate"];
if (url) {
Expand All @@ -79,7 +76,6 @@ export function parseRemoteConfig(configJson, platform, tz) {
}

// if we're here, it's a match on platform
console.log("fallback:", targets[0]);
return targets[0]["potentialAction"]["target"]["urlTemplate"];
}

Expand Down

0 comments on commit 54e31e0

Please sign in to comment.