mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
/*
|
|
* Copyright (c) 2026 by Christian Kellner.
|
|
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
|
|
*/
|
|
|
|
import fetch from 'node-fetch';
|
|
import { getPackageVersion } from '../../utils.js';
|
|
import semver from 'semver';
|
|
|
|
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();
|
|
if (data.tag_name == null || semver.gte(localFredyVersion, data.tag_name)) {
|
|
return null;
|
|
}
|
|
return {
|
|
newVersion: true,
|
|
version: data.tag_name,
|
|
url: data.html_url,
|
|
body: data.body,
|
|
localFredyVersion,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @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 };
|
|
});
|
|
}
|