mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
improving release banner
This commit is contained in:
@@ -5,6 +5,22 @@ import { getPackageVersion } from '../../utils.js';
|
||||
const service = restana();
|
||||
const versionRouter = service.newRouter();
|
||||
|
||||
/**
|
||||
* Converts a dotted numeric string (e.g., '12.2.1.2') into a single integer (e.g., 12212).
|
||||
* Null safe: returns null for null/undefined/empty or non-numeric input.
|
||||
* Non-digits are removed; separators like '.' or '-' are ignored.
|
||||
*
|
||||
* @param {string|number|null|undefined} input
|
||||
* @returns {number|null}
|
||||
*/
|
||||
const toCompactNumber = (input) => {
|
||||
if (input == null) return null;
|
||||
const joined = String(input).match(/\d+/g)?.join('') ?? '';
|
||||
if (joined === '') return null;
|
||||
const n = Number(joined);
|
||||
return Number.isFinite(n) ? n : null;
|
||||
};
|
||||
|
||||
versionRouter.get('/', async (req, res) => {
|
||||
const versionPayload = await getCurrentVersionFromGithub();
|
||||
res.body = versionPayload == null ? { newVersion: false } : versionPayload;
|
||||
@@ -15,7 +31,7 @@ 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 (localFredyVersion === data.tag_name) {
|
||||
if (data.tag_name == null || toCompactNumber(localFredyVersion) >= toCompactNumber(data.tag_name)) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "fredy",
|
||||
"version": "12.2.0",
|
||||
"version": "12.2.1",
|
||||
"description": "[F]ind [R]eal [E]states [d]amn eas[y].",
|
||||
"scripts": {
|
||||
"prepare": "husky",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { Banner, Descriptions } from '@douyinfe/semi-ui';
|
||||
import { useSelector } from '../../services/state/store.js';
|
||||
import { MarkdownRender } from '@douyinfe/semi-ui';
|
||||
|
||||
import './VersionBanner.less';
|
||||
|
||||
@@ -12,7 +13,7 @@ export default function VersionBanner() {
|
||||
type="success"
|
||||
icon={null}
|
||||
description={
|
||||
<div>
|
||||
<div style={{ overflow: 'auto' }}>
|
||||
<p>A new version of Fredy is available. Update now to take advantage of the latest features and bug fixes.</p>
|
||||
<Descriptions row size="small">
|
||||
<Descriptions.Item itemKey="Your Version">{versionUpdate.localFredyVersion}</Descriptions.Item>
|
||||
@@ -28,16 +29,9 @@ export default function VersionBanner() {
|
||||
<small>Release Notes</small>
|
||||
</b>
|
||||
</p>
|
||||
<pre>{stripFullChangelog(versionUpdate.body)}</pre>
|
||||
<MarkdownRender raw={versionUpdate.body} style={{ height: '200px' }} />
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
function stripFullChangelog(text) {
|
||||
if (text == null) {
|
||||
return '';
|
||||
}
|
||||
return text.replace(/(?:\r?\n)\*\*Full Changelog\*\*[\s\S]*$/u, '');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user