refactor: use getVolumePath helper

This commit is contained in:
Nicolas Meienberger
2025-10-17 23:39:16 +02:00
parent 5b6a86331e
commit ad54948a69
4 changed files with 9 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
import type { BackendStatus } from "@ironmount/schemas"; import type { BackendStatus } from "@ironmount/schemas";
import { VOLUME_MOUNT_BASE } from "../../core/constants";
import type { Volume } from "../../db/schema"; import type { Volume } from "../../db/schema";
import { getVolumePath } from "../volumes/helpers";
import { makeDirectoryBackend } from "./directory/directory-backend"; import { makeDirectoryBackend } from "./directory/directory-backend";
import { makeNfsBackend } from "./nfs/nfs-backend"; import { makeNfsBackend } from "./nfs/nfs-backend";
import { makeSmbBackend } from "./smb/smb-backend"; import { makeSmbBackend } from "./smb/smb-backend";
@@ -18,7 +18,7 @@ export type VolumeBackend = {
}; };
export const createVolumeBackend = (volume: Volume): VolumeBackend => { export const createVolumeBackend = (volume: Volume): VolumeBackend => {
const path = `${VOLUME_MOUNT_BASE}/${volume.name}/_data`; const path = getVolumePath(volume.name);
switch (volume.config.backend) { switch (volume.config.backend) {
case "nfs": { case "nfs": {

View File

@@ -1,6 +1,6 @@
import { Hono } from "hono"; import { Hono } from "hono";
import { VOLUME_MOUNT_BASE } from "../../core/constants";
import { volumeService } from "../volumes/volume.service"; import { volumeService } from "../volumes/volume.service";
import { getVolumePath } from "../volumes/helpers";
export const driverController = new Hono() export const driverController = new Hono()
.post("/VolumeDriver.Capabilities", (c) => { .post("/VolumeDriver.Capabilities", (c) => {
@@ -32,10 +32,8 @@ export const driverController = new Hono()
const volumeName = body.Name.replace(/^im-/, ""); const volumeName = body.Name.replace(/^im-/, "");
const mountpoint = `${VOLUME_MOUNT_BASE}/${volumeName}/_data`;
return c.json({ return c.json({
Mountpoint: mountpoint, Mountpoint: getVolumePath(volumeName),
}); });
}) })
.post("/VolumeDriver.Unmount", (c) => { .post("/VolumeDriver.Unmount", (c) => {
@@ -53,7 +51,7 @@ export const driverController = new Hono()
const { volume } = await volumeService.getVolume(body.Name.replace(/^im-/, "")); const { volume } = await volumeService.getVolume(body.Name.replace(/^im-/, ""));
return c.json({ return c.json({
Mountpoint: `${VOLUME_MOUNT_BASE}/${volume.name}/_data`, Mountpoint: getVolumePath(volume.name),
}); });
}) })
.post("/VolumeDriver.Get", async (c) => { .post("/VolumeDriver.Get", async (c) => {
@@ -68,7 +66,7 @@ export const driverController = new Hono()
return c.json({ return c.json({
Volume: { Volume: {
Name: `im-${volume.name}`, Name: `im-${volume.name}`,
Mountpoint: `${VOLUME_MOUNT_BASE}/${volume.name}/_data`, Mountpoint: getVolumePath(volume.name),
Status: {}, Status: {},
}, },
Err: "", Err: "",
@@ -79,7 +77,7 @@ export const driverController = new Hono()
const res = volumes.map((volume) => ({ const res = volumes.map((volume) => ({
Name: `im-${volume.name}`, Name: `im-${volume.name}`,
Mountpoint: `${VOLUME_MOUNT_BASE}/${volume.name}/_data`, Mountpoint: getVolumePath(volume.name),
Status: {}, Status: {},
})); }));

View File

@@ -118,7 +118,7 @@ const getVolume = async (name: string) => {
let statfs: Partial<StatFs> = {}; let statfs: Partial<StatFs> = {};
if (volume.status === "mounted") { if (volume.status === "mounted") {
statfs = await getStatFs(`${VOLUME_MOUNT_BASE}/${name}/_data`).catch(() => ({})); statfs = await getStatFs(getVolumePath(name)).catch(() => ({}));
} }
return { volume, statfs }; return { volume, statfs };

View File

@@ -28,7 +28,7 @@
"enabled": true, "enabled": true,
"actions": { "actions": {
"source": { "source": {
"organizeImports": "on" "organizeImports": "off"
} }
} }
} }