From 9ec514e145307763d8cbcc425124f5998fe86142 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Sun, 7 Dec 2025 20:18:58 -0800 Subject: [PATCH] fix(Zim): storage path --- admin/app/services/docker_service.ts | 8 ++++---- admin/app/services/zim_service.ts | 12 +++++------- admin/app/utils/fs.ts | 2 ++ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/admin/app/services/docker_service.ts b/admin/app/services/docker_service.ts index fbfa4ac..8054f5b 100644 --- a/admin/app/services/docker_service.ts +++ b/admin/app/services/docker_service.ts @@ -5,7 +5,8 @@ import { inject } from '@adonisjs/core' import { ServiceStatus } from '../../types/services.js' import transmit from '@adonisjs/transmit/services/main' import { doResumableDownloadWithRetry } from '../utils/downloads.js' -import path from 'path' +import { join } from 'path' +import { ZIM_STORAGE_PATH } from '../utils/fs.js' @inject() export class DockerService { @@ -16,7 +17,6 @@ export class DockerService { public static CYBERCHEF_SERVICE_NAME = 'nomad_cyberchef' public static FLATNOTES_SERVICE_NAME = 'nomad_flatnotes' public static KOLIBRI_SERVICE_NAME = 'nomad_kolibri' - public static NOMAD_STORAGE_PATH = '/storage' constructor() { this.docker = new Docker({ socketPath: '/var/run/docker.sock' }) @@ -330,8 +330,8 @@ export class DockerService { **/ const WIKIPEDIA_ZIM_URL = 'https://github.com/Crosstalk-Solutions/project-nomad/raw/refs/heads/master/install/wikipedia_en_100_mini_2025-06.zim' - const zimPath = '/zim/wikipedia_en_100_mini_2025-06.zim' - const filepath = path.join(process.cwd(), DockerService.NOMAD_STORAGE_PATH, zimPath) + const filename = 'wikipedia_en_100_mini_2025-06.zim' + const filepath = join(process.cwd(), ZIM_STORAGE_PATH, filename) logger.info(`[DockerService] Kiwix Serve pre-install: Downloading ZIM file to ${filepath}`) this._broadcast( diff --git a/admin/app/services/zim_service.ts b/admin/app/services/zim_service.ts index f3fbf4d..6ea8d89 100644 --- a/admin/app/services/zim_service.ts +++ b/admin/app/services/zim_service.ts @@ -14,6 +14,7 @@ import { ensureDirectoryExists, getFileStatsIfExists, listDirectoryContents, + ZIM_STORAGE_PATH, } from '../utils/fs.js' import { join } from 'path' import { CuratedCollectionWithStatus, CuratedCollectionsFile } from '../../types/downloads.js' @@ -29,13 +30,10 @@ const COLLECTIONS_URL = @inject() export class ZimService { - private zimStoragePath = '/storage/zim' - constructor(private dockerService: DockerService) {} async list() { - const dirPath = join(process.cwd(), this.zimStoragePath) - + const dirPath = join(process.cwd(), ZIM_STORAGE_PATH) await ensureDirectoryExists(dirPath) const all = await listDirectoryContents(dirPath) @@ -154,7 +152,7 @@ export class ZimService { throw new Error('Could not determine filename from URL') } - const filepath = join(process.cwd(), this.zimStoragePath, filename) + const filepath = join(process.cwd(), ZIM_STORAGE_PATH, filename) // Dispatch a background download job const result = await RunDownloadJob.dispatch({ @@ -207,7 +205,7 @@ export class ZimService { } downloadFilenames.push(filename) - const filepath = join(process.cwd(), this.zimStoragePath, filename) + const filepath = join(process.cwd(), ZIM_STORAGE_PATH, filename) await RunDownloadJob.dispatch({ url, @@ -286,7 +284,7 @@ export class ZimService { fileName += '.zim' } - const fullPath = join(process.cwd(), this.zimStoragePath, fileName) + const fullPath = join(process.cwd(), ZIM_STORAGE_PATH, fileName) const exists = await getFileStatsIfExists(fullPath) if (!exists) { diff --git a/admin/app/utils/fs.ts b/admin/app/utils/fs.ts index 6f27847..c18ab39 100644 --- a/admin/app/utils/fs.ts +++ b/admin/app/utils/fs.ts @@ -4,6 +4,8 @@ import { FileEntry } from '../../types/files.js' import { createReadStream } from 'fs' import { LSBlockDevice, NomadDiskInfoRaw } from '../../types/system.js' +export const ZIM_STORAGE_PATH = '/storage/zim' + export async function listDirectoryContents(path: string): Promise { const entries = await readdir(path, { withFileTypes: true }) const results: FileEntry[] = []