2025-12-11 10:40:55 +01:00
|
|
|
/*
|
2026-01-12 15:00:36 +01:00
|
|
|
* Copyright (c) 2026 by Christian Kellner.
|
2025-12-11 10:40:55 +01:00
|
|
|
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2025-09-20 19:37:27 +02:00
|
|
|
import fetch from 'node-fetch';
|
|
|
|
|
import { getPackageVersion } from '../../utils.js';
|
2025-09-26 10:45:55 +02:00
|
|
|
import semver from 'semver';
|
2025-09-20 19:37:27 +02:00
|
|
|
|
|
|
|
|
async function getCurrentVersionFromGithub() {
|
|
|
|
|
const raw = await fetch('https://api.github.com/repos/orangecoding/fredy/releases/latest');
|
|
|
|
|
const data = await raw.json();
|
|
|
|
|
const localFredyVersion = await getPackageVersion();
|
2025-09-26 10:45:55 +02:00
|
|
|
if (data.tag_name == null || semver.gte(localFredyVersion, data.tag_name)) {
|
2025-09-20 19:37:27 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
newVersion: true,
|
|
|
|
|
version: data.tag_name,
|
|
|
|
|
url: data.html_url,
|
|
|
|
|
body: data.body,
|
|
|
|
|
localFredyVersion,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 16:56:04 +02:00
|
|
|
/**
|
|
|
|
|
* @param {import('fastify').FastifyInstance} fastify
|
|
|
|
|
*/
|
|
|
|
|
export default async function versionPlugin(fastify) {
|
|
|
|
|
fastify.get('/', async () => {
|
|
|
|
|
const versionPayload = await getCurrentVersionFromGithub();
|
|
|
|
|
const localFredyVersion = await getPackageVersion();
|
|
|
|
|
return versionPayload ?? { newVersion: false, localFredyVersion };
|
|
|
|
|
});
|
|
|
|
|
}
|