1 import type { DESKTOP_APP_NAMES, DESKTOP_PLATFORMS, RELEASE_CATEGORIES } from '@proton/shared/lib/constants';
2 import { getDownloadUrl } from '@proton/shared/lib/helpers/url';
4 export interface Props {
5 appName: DESKTOP_APP_NAMES;
6 platform: DESKTOP_PLATFORMS;
7 version: 'latest' | string;
8 category: RELEASE_CATEGORIES;
12 CategoryName: RELEASE_CATEGORIES;
17 Sha512CheckSum: 'string';
27 * This helper will help to fetch specific or latest version of a desktop app
28 * It currently only support Drive apps.
30 export const fetchDesktopVersion = async ({
43 const response = await fetch(getDownloadUrl(`/${appName}/${platform}/version.json`));
45 throw new Error(response.statusText);
47 const { Releases: releases }: { Releases: RELEASE[] } = await response.json();
49 const filteredReleases = releases.filter((release) => release.CategoryName === category);
50 if (!filteredReleases.length) {
53 if (version === 'latest') {
54 // We assume that latest release is always the first one
55 const latestRelease = filteredReleases[0];
56 return { url: latestRelease.File.Url, version: latestRelease.Version };
58 const release = filteredReleases.find((release) => release.Version === version);
62 return { url: release.File.Url, version: release.Version };
65 throw Error(`Failed to fetch ${appName} ${platform}@${version} app's url`, {