mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-14 13:12:09 +08:00
Feature: Trilium Service widget (#5380)
Some checks failed
Crowdin Action / Crowdin Sync (push) Has been cancelled
Docker CI / Linting Checks (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Repository Maintenance / Stale (push) Has been cancelled
Repository Maintenance / Lock Old Threads (push) Has been cancelled
Repository Maintenance / Close Answered Discussions (push) Has been cancelled
Repository Maintenance / Close Outdated Discussions (push) Has been cancelled
Repository Maintenance / Close Unsupported Feature Requests (push) Has been cancelled
Some checks failed
Crowdin Action / Crowdin Sync (push) Has been cancelled
Docker CI / Linting Checks (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Repository Maintenance / Stale (push) Has been cancelled
Repository Maintenance / Lock Old Threads (push) Has been cancelled
Repository Maintenance / Close Answered Discussions (push) Has been cancelled
Repository Maintenance / Close Outdated Discussions (push) Has been cancelled
Repository Maintenance / Close Unsupported Feature Requests (push) Has been cancelled
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
38
src/widgets/trilium/component.jsx
Normal file
38
src/widgets/trilium/component.jsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import Block from "components/services/widget/block";
|
||||
import Container from "components/services/widget/container";
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
|
||||
const { data: metricsData, error: metricsError } = useWidgetAPI(widget, "metrics");
|
||||
|
||||
if (metricsError) {
|
||||
return <Container service={service} error={metricsError} />;
|
||||
}
|
||||
|
||||
if (!metricsData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="trilium.version" />
|
||||
<Block label="trilium.notesCount" />
|
||||
<Block label="trilium.dbSize" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const version = metricsData.version?.app;
|
||||
const notesCount = metricsData.database?.activeNotes || 0;
|
||||
const databaseSizeBytes = metricsData.statistics?.databaseSizeBytes || 0;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="trilium.version" value={version ? `v${version}` : t("trilium.unknown")} />
|
||||
<Block label="trilium.notesCount" value={t("common.number", { value: notesCount })} />
|
||||
<Block label="trilium.dbSize" value={t("common.bytes", { value: databaseSizeBytes })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
15
src/widgets/trilium/widget.js
Normal file
15
src/widgets/trilium/widget.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/etapi/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
metrics: {
|
||||
endpoint: "metrics?format=json",
|
||||
validate: ["version", "database"],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
||||
Reference in New Issue
Block a user