From 57c8f92f42d8d2e8194633362564eefc9e59a1da Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Mon, 8 Jun 2026 06:10:06 +0530 Subject: [PATCH] feat(updater): add feed-config to map channel setting to feed URL --- src/main/updater/feed-config.js | 31 +++++++++++++++++++ tests/unit/main/updater/feed-config.test.js | 33 +++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/main/updater/feed-config.js create mode 100644 tests/unit/main/updater/feed-config.test.js diff --git a/src/main/updater/feed-config.js b/src/main/updater/feed-config.js new file mode 100644 index 0000000..6c2ab83 --- /dev/null +++ b/src/main/updater/feed-config.js @@ -0,0 +1,31 @@ +const REPO = 'amitwh/markdown-converter'; + +const FEEDS = { + github: { + base: `https://github.com/${REPO}/releases/download`, + }, + concreteinfo: { + base: 'https://updates.concreteinfo.co.in/v5', + }, +}; + +function platformSuffix(platform) { + if (platform === 'darwin' || platform === 'mac') return 'mac'; + if (platform === 'win32' || platform === 'windows') return 'windows'; + return 'linux'; +} + +function feedForChannel(channel, version, platform) { + const suffix = platformSuffix(platform); + const f = FEEDS[channel] || FEEDS.github; + if (channel === 'github') { + return `${f.base}/v${version}/latest-${suffix}.yml`; + } + return `${f.base}/latest-${suffix}.yml`; +} + +function resolveFeedUrl(channel, version, platform) { + return feedForChannel(channel, version, platform); +} + +module.exports = { resolveFeedUrl, FEEDS }; \ No newline at end of file diff --git a/tests/unit/main/updater/feed-config.test.js b/tests/unit/main/updater/feed-config.test.js new file mode 100644 index 0000000..99a7ee0 --- /dev/null +++ b/tests/unit/main/updater/feed-config.test.js @@ -0,0 +1,33 @@ +const { resolveFeedUrl, FEEDS } = require('../../../../src/main/updater/feed-config'); + +describe('feed-config', () => { + test('resolves github channel to GitHub Releases feed', () => { + const url = resolveFeedUrl('github', '5.0.2', 'mac'); + expect(url).toBe('https://github.com/amitwh/markdown-converter/releases/download/v5.0.2/latest-mac.yml'); + }); + + test('resolves concreteinfo channel to CI feed', () => { + const url = resolveFeedUrl('concreteinfo', '5.0.2', 'mac'); + expect(url).toBe('https://updates.concreteinfo.co.in/v5/latest-mac.yml'); + }); + + test('resolves windows platform correctly', () => { + const url = resolveFeedUrl('github', '5.0.2', 'windows'); + expect(url).toContain('latest-windows.yml'); + }); + + test('resolves linux platform correctly', () => { + const url = resolveFeedUrl('github', '5.0.2', 'linux'); + expect(url).toContain('latest-linux.yml'); + }); + + test('falls back to github on unknown channel', () => { + const url = resolveFeedUrl('something-weird', '5.0.2', 'mac'); + expect(url).toContain('github.com'); + }); + + test('exports both feeds as constants', () => { + expect(FEEDS.github).toBeDefined(); + expect(FEEDS.concreteinfo).toBeDefined(); + }); +}); \ No newline at end of file