mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
Feature: cache release data, allow disable release checking (#4917)
This commit is contained in:
parent
544b9aef2f
commit
859bd459a8
@ -447,7 +447,7 @@ quicklaunch:
|
|||||||
suggestionUrl: https://ac.ecosia.org/autocomplete?type=list&q=
|
suggestionUrl: https://ac.ecosia.org/autocomplete?type=list&q=
|
||||||
```
|
```
|
||||||
|
|
||||||
## Homepage Version
|
## Homepage Version & Update Checking
|
||||||
|
|
||||||
By default the release version is displayed at the bottom of the page. To hide this, use the `hideVersion` setting, like so:
|
By default the release version is displayed at the bottom of the page. To hide this, use the `hideVersion` setting, like so:
|
||||||
|
|
||||||
@ -455,6 +455,12 @@ By default the release version is displayed at the bottom of the page. To hide t
|
|||||||
hideVersion: true
|
hideVersion: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can disable checking for new versions from GitHub (enabled by default) with:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
disableUpdateCheck: true
|
||||||
|
```
|
||||||
|
|
||||||
## Log Path
|
## Log Path
|
||||||
|
|
||||||
By default the homepage logfile is written to the a `logs` subdirectory of the `config` folder. In order to customize this path, you can set the `logpath` setting. A `logs` folder will be created in that location where the logfile will be written.
|
By default the homepage logfile is written to the a `logs` subdirectory of the `config` folder. In order to customize this path, you can set the `logpath` setting. A `logs` folder will be created in that location where the logfile will be written.
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
|
import cache from "memory-cache";
|
||||||
import { useTranslation } from "next-i18next";
|
import { useTranslation } from "next-i18next";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import { compareVersions, validate } from "compare-versions";
|
import { compareVersions, validate } from "compare-versions";
|
||||||
import { MdNewReleases } from "react-icons/md";
|
import { MdNewReleases } from "react-icons/md";
|
||||||
|
|
||||||
export default function Version() {
|
const LATEST_RELEASE_CACHE_KEY = "latestRelease";
|
||||||
|
|
||||||
|
export default function Version({ disableUpdateCheck = false }) {
|
||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
|
|
||||||
const buildTime = process.env.NEXT_PUBLIC_BUILDTIME?.length
|
const buildTime = process.env.NEXT_PUBLIC_BUILDTIME?.length
|
||||||
@ -12,8 +15,6 @@ export default function Version() {
|
|||||||
const revision = process.env.NEXT_PUBLIC_REVISION?.length ? process.env.NEXT_PUBLIC_REVISION : "dev";
|
const revision = process.env.NEXT_PUBLIC_REVISION?.length ? process.env.NEXT_PUBLIC_REVISION : "dev";
|
||||||
const version = process.env.NEXT_PUBLIC_VERSION?.length ? process.env.NEXT_PUBLIC_VERSION : "dev";
|
const version = process.env.NEXT_PUBLIC_VERSION?.length ? process.env.NEXT_PUBLIC_VERSION : "dev";
|
||||||
|
|
||||||
const { data: releaseData } = useSWR("/api/releases");
|
|
||||||
|
|
||||||
// use Intl.DateTimeFormat to format the date
|
// use Intl.DateTimeFormat to format the date
|
||||||
const formatDate = (date) => {
|
const formatDate = (date) => {
|
||||||
const options = {
|
const options = {
|
||||||
@ -24,7 +25,15 @@ export default function Version() {
|
|||||||
return new Intl.DateTimeFormat(i18n.language, options).format(new Date(date));
|
return new Intl.DateTimeFormat(i18n.language, options).format(new Date(date));
|
||||||
};
|
};
|
||||||
|
|
||||||
const latestRelease = releaseData?.[0];
|
let latestRelease = cache.get(LATEST_RELEASE_CACHE_KEY);
|
||||||
|
|
||||||
|
const { data: releaseData } = useSWR(latestRelease || disableUpdateCheck ? null : "/api/releases");
|
||||||
|
|
||||||
|
if (releaseData) {
|
||||||
|
latestRelease = releaseData?.[0];
|
||||||
|
// cache the latest release for 1h
|
||||||
|
cache.put(LATEST_RELEASE_CACHE_KEY, latestRelease, 3600000);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="version" className="flex flex-row items-center">
|
<div id="version" className="flex flex-row items-center">
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
import cachedFetch from "utils/proxy/cached-fetch";
|
import cachedFetch from "utils/proxy/cached-fetch";
|
||||||
|
import createLogger from "utils/logger";
|
||||||
|
|
||||||
|
const logger = createLogger("releases");
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
const releasesURL = "https://api.github.com/repos/gethomepage/homepage/releases";
|
const releasesURL = "https://api.github.com/repos/gethomepage/homepage/releases";
|
||||||
|
try {
|
||||||
return res.send(await cachedFetch(releasesURL, 5));
|
return res.send(await cachedFetch(releasesURL, 5));
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(`Error checking GitHub releases: ${e}`);
|
||||||
|
return res.send([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -480,7 +480,7 @@ function Home({ initialSettings }) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="version" className="flex mt-4 w-full justify-end">
|
<div id="version" className="flex mt-4 w-full justify-end">
|
||||||
{!settings.hideVersion && <Version />}
|
{!settings.hideVersion && <Version disableUpdateCheck={settings.disableUpdateCheck} />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user