Compare commits
2 Commits
39d2ac80ca
...
ee53b9338c
Author | SHA1 | Date |
---|---|---|
William Grant | ee53b9338c | |
William Grant | 9df5e79e91 |
|
@ -7,28 +7,48 @@ export interface IRedirection {
|
||||||
permanent: boolean;
|
permanent: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE should update periodically
|
||||||
|
let fallbackVersion = '1.11.1';
|
||||||
|
let lastChecked = 1694059030086; // 2023-09-07 03:57
|
||||||
|
|
||||||
const redirects: IRedirection[] = getConfig().serverRuntimeConfig.redirects;
|
const redirects: IRedirection[] = getConfig().serverRuntimeConfig.redirects;
|
||||||
|
|
||||||
async function fetchLatestVersion(repo: string) {
|
async function fetchLatestVersion(repo: string) {
|
||||||
const fallbackVersion = '1.11.0'; // NOTE should update periodically
|
// Only update once per 15 minutes
|
||||||
const res = await fetch(
|
if (lastChecked > Date.now() - 1000 * 60 * 15) {
|
||||||
`https://api.github.com/repos/oxen-io/${repo}/releases/latest`
|
const res = await fetch(
|
||||||
);
|
`https://api.github.com/repos/oxen-io/${repo}/releases/latest`
|
||||||
const data = await res.json();
|
);
|
||||||
if (!data) return fallbackVersion;
|
const data = await res.json();
|
||||||
|
if (!data) return fallbackVersion;
|
||||||
|
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Redirect Service: Code ${res.status} | ${data.message}`,
|
`Redirect Service: Code ${res.status} | ${data.message}`,
|
||||||
`${data.documentation && `| See ${data.documentation}`}`
|
`${data.documentation && `| See ${data.documentation}`}`
|
||||||
);
|
);
|
||||||
console.log(
|
console.log(
|
||||||
`Redirect Service: Falling back to version ${fallbackVersion}.`
|
`Redirect Service: Falling back to version ${fallbackVersion}. Last checked on ${new Date(
|
||||||
);
|
lastChecked
|
||||||
return fallbackVersion;
|
).toUTCString()}.}`
|
||||||
|
);
|
||||||
|
return fallbackVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
const foundVersion = data['tag_name'].split('v')[1];
|
||||||
|
|
||||||
|
if (foundVersion && foundVersion !== fallbackVersion) {
|
||||||
|
fallbackVersion = foundVersion;
|
||||||
|
lastChecked = Date.now();
|
||||||
|
console.log(
|
||||||
|
`Redirect Service: Fetched new version from GitHub ${fallbackVersion} at ${new Date(
|
||||||
|
lastChecked
|
||||||
|
).toUTCString()}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data['tag_name'].split('v')[1];
|
return fallbackVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchDynamicRedirects() {
|
async function fetchDynamicRedirects() {
|
||||||
|
@ -41,12 +61,12 @@ async function fetchDynamicRedirects() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
source: '/mac',
|
source: '/mac',
|
||||||
destination: `https://github.com/oxen-io/session-desktop/releases/download/v${desktopVersion}/session-desktop-mac-${desktopVersion}.dmg`,
|
destination: `https://github.com/oxen-io/session-desktop/releases/download/v${desktopVersion}/session-desktop-mac-x64-${desktopVersion}.dmg`,
|
||||||
permanent: true,
|
permanent: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
source: '/windows',
|
source: '/windows',
|
||||||
destination: `https://github.com/oxen-io/session-desktop/releases/download/v${desktopVersion}/session-desktop-win-${desktopVersion}.exe`,
|
destination: `https://github.com/oxen-io/session-desktop/releases/download/v${desktopVersion}/session-desktop-win-x64-${desktopVersion}.exe`,
|
||||||
permanent: true,
|
permanent: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue