feat: add webdav support

This commit is contained in:
Nicolas Meienberger
2025-09-26 19:13:09 +02:00
parent 323312ec7b
commit bc6e6c9700
18 changed files with 523 additions and 141 deletions

View File

@@ -55,13 +55,17 @@ export const volumeController = new Hono()
const res = await volumeService.getVolume(name);
const response = {
...res,
volume: {
...res.volume,
createdAt: res.volume.createdAt.getTime(),
updatedAt: res.volume.updatedAt.getTime(),
lastHealthCheck: res.volume.lastHealthCheck.getTime(),
},
statfs: {
total: res.statfs.total ?? 0,
used: res.statfs.used ?? 0,
free: res.statfs.free ?? 0,
},
} satisfies GetVolumeResponseDto;
return c.json(response, 200);

View File

@@ -6,7 +6,7 @@ import { resolver } from "hono-openapi/arktype";
const volumeSchema = type({
name: "string",
path: "string",
type: type.enumerated("nfs", "smb", "directory"),
type: type.enumerated("nfs", "smb", "directory", "webdav"),
status: type.enumerated("mounted", "unmounted", "error", "unknown"),
lastError: "string | null",
createdAt: "number",
@@ -100,13 +100,15 @@ export const deleteVolumeDto = describeRoute({
},
});
const statfsSchema = type({
total: "number",
used: "number",
free: "number",
});
const getVolumeResponse = type({
volume: volumeSchema,
statfs: type({
total: "number = 0",
used: "number = 0",
free: "number = 0",
}),
statfs: statfsSchema,
});
export type GetVolumeResponseDto = typeof getVolumeResponse.infer;

View File

@@ -12,6 +12,7 @@ import { createVolumeBackend } from "../backends/backend";
import { toMessage } from "../../utils/errors";
import { getStatFs, type StatFs } from "../../utils/mountinfo";
import { VOLUME_MOUNT_BASE } from "../../core/constants";
import { logger } from "../../utils/logger";
const listVolumes = async () => {
const volumes = await db.query.volumesTable.findMany({});
@@ -73,7 +74,7 @@ const mountVolume = async (name: string) => {
await db
.update(volumesTable)
.set({ status, lastError: error, lastHealthCheck: new Date() })
.set({ status, lastError: error ?? null, lastHealthCheck: new Date() })
.where(eq(volumesTable.name, name));
return { error, status };