Files
Homelab-manager/server/src/routes/nextcloud.ts
T
bobbanandClaude Sonnet 5.5 65214f6f0f Nextcloud cron and Nextcloud's own checks; bulk close and open again
Nextcloud: its own "Cron last run" setup check (GET /settings/setupcheck,
Nextcloud 28+, found by class name) raises an alert when background jobs have
stopped; other checks that report an error are one alert, warnings are shown
on the page. The core version Nextcloud says is available is shown too. Before
28, cron and the checks are unknown, never "fine".

Alerts page: bulk Close... (one reason, written on each incident, undoable) and
Open again. Bulk Wake now leaves closed alerts alone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 22:12:10 +01:00

54 lines
2.2 KiB
TypeScript

import { Router } from "express";
import { eq } from "drizzle-orm";
import { db } from "../db/client.js";
import { integrations, nextcloudState } from "../db/schema.js";
import { requireAuth } from "../auth/middleware.js";
import { isNextcloudFresh, nextcloudProblems, nextcloudSyncStatuses, setupIssuesOf } from "../services/nextcloudSync.js";
import { asyncHandler } from "../utils/asyncHandler.js";
export const nextcloudRouter = Router();
nextcloudRouter.use(requireAuth);
/** Every Nextcloud, how it is, from what the last read stored: maintenance mode, the data disk, the users, the app updates and what is wrong. Everyone signed in can see it, like the other pages made of stored readings. */
nextcloudRouter.get("/", asyncHandler(async (_req, res) => {
const [rows, states, statuses] = await Promise.all([
db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "nextcloud")).orderBy(integrations.name),
db.select().from(nextcloudState),
nextcloudSyncStatuses(),
]);
const byId = new Map(states.map((s) => [s.integrationId, s]));
const now = Date.now();
res.json({
nextclouds: rows.map((r) => {
const state = byId.get(r.id) ?? null;
const status = statuses[r.id] ?? null;
const fresh = isNextcloudFresh(status ?? undefined, now);
return {
id: r.id,
name: r.name,
enabled: r.enabled,
status,
fresh,
state: state
? {
version: state.version,
maintenance: state.maintenance,
needsUpgrade: state.needsUpgrade,
detail: state.detail,
freeBytes: state.freeBytes,
users: state.users,
files: state.files,
active24h: state.active24h,
appUpdates: state.appUpdates,
coreUpdate: state.coreUpdate,
cron: state.cronState ? { state: state.cronState, text: state.cronText } : null,
setupIssues: setupIssuesOf(state),
updatedAt: state.updatedAt,
}
: null,
problems: state && fresh ? nextcloudProblems(r.id, r.name, state) : [],
};
}),
});
}));