fix(Zim): storage path

This commit is contained in:
Jake Turner 2025-12-07 20:18:58 -08:00
parent f318426a57
commit 9ec514e145
No known key found for this signature in database
GPG Key ID: 694BC38EF2ED4844
3 changed files with 11 additions and 11 deletions

View File

@ -5,7 +5,8 @@ import { inject } from '@adonisjs/core'
import { ServiceStatus } from '../../types/services.js' import { ServiceStatus } from '../../types/services.js'
import transmit from '@adonisjs/transmit/services/main' import transmit from '@adonisjs/transmit/services/main'
import { doResumableDownloadWithRetry } from '../utils/downloads.js' import { doResumableDownloadWithRetry } from '../utils/downloads.js'
import path from 'path' import { join } from 'path'
import { ZIM_STORAGE_PATH } from '../utils/fs.js'
@inject() @inject()
export class DockerService { export class DockerService {
@ -16,7 +17,6 @@ export class DockerService {
public static CYBERCHEF_SERVICE_NAME = 'nomad_cyberchef' public static CYBERCHEF_SERVICE_NAME = 'nomad_cyberchef'
public static FLATNOTES_SERVICE_NAME = 'nomad_flatnotes' public static FLATNOTES_SERVICE_NAME = 'nomad_flatnotes'
public static KOLIBRI_SERVICE_NAME = 'nomad_kolibri' public static KOLIBRI_SERVICE_NAME = 'nomad_kolibri'
public static NOMAD_STORAGE_PATH = '/storage'
constructor() { constructor() {
this.docker = new Docker({ socketPath: '/var/run/docker.sock' }) this.docker = new Docker({ socketPath: '/var/run/docker.sock' })
@ -330,8 +330,8 @@ export class DockerService {
**/ **/
const WIKIPEDIA_ZIM_URL = const WIKIPEDIA_ZIM_URL =
'https://github.com/Crosstalk-Solutions/project-nomad/raw/refs/heads/master/install/wikipedia_en_100_mini_2025-06.zim' '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 filename = 'wikipedia_en_100_mini_2025-06.zim'
const filepath = path.join(process.cwd(), DockerService.NOMAD_STORAGE_PATH, zimPath) const filepath = join(process.cwd(), ZIM_STORAGE_PATH, filename)
logger.info(`[DockerService] Kiwix Serve pre-install: Downloading ZIM file to ${filepath}`) logger.info(`[DockerService] Kiwix Serve pre-install: Downloading ZIM file to ${filepath}`)
this._broadcast( this._broadcast(

View File

@ -14,6 +14,7 @@ import {
ensureDirectoryExists, ensureDirectoryExists,
getFileStatsIfExists, getFileStatsIfExists,
listDirectoryContents, listDirectoryContents,
ZIM_STORAGE_PATH,
} from '../utils/fs.js' } from '../utils/fs.js'
import { join } from 'path' import { join } from 'path'
import { CuratedCollectionWithStatus, CuratedCollectionsFile } from '../../types/downloads.js' import { CuratedCollectionWithStatus, CuratedCollectionsFile } from '../../types/downloads.js'
@ -29,13 +30,10 @@ const COLLECTIONS_URL =
@inject() @inject()
export class ZimService { export class ZimService {
private zimStoragePath = '/storage/zim'
constructor(private dockerService: DockerService) {} constructor(private dockerService: DockerService) {}
async list() { async list() {
const dirPath = join(process.cwd(), this.zimStoragePath) const dirPath = join(process.cwd(), ZIM_STORAGE_PATH)
await ensureDirectoryExists(dirPath) await ensureDirectoryExists(dirPath)
const all = await listDirectoryContents(dirPath) const all = await listDirectoryContents(dirPath)
@ -154,7 +152,7 @@ export class ZimService {
throw new Error('Could not determine filename from URL') 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 // Dispatch a background download job
const result = await RunDownloadJob.dispatch({ const result = await RunDownloadJob.dispatch({
@ -207,7 +205,7 @@ export class ZimService {
} }
downloadFilenames.push(filename) downloadFilenames.push(filename)
const filepath = join(process.cwd(), this.zimStoragePath, filename) const filepath = join(process.cwd(), ZIM_STORAGE_PATH, filename)
await RunDownloadJob.dispatch({ await RunDownloadJob.dispatch({
url, url,
@ -286,7 +284,7 @@ export class ZimService {
fileName += '.zim' fileName += '.zim'
} }
const fullPath = join(process.cwd(), this.zimStoragePath, fileName) const fullPath = join(process.cwd(), ZIM_STORAGE_PATH, fileName)
const exists = await getFileStatsIfExists(fullPath) const exists = await getFileStatsIfExists(fullPath)
if (!exists) { if (!exists) {

View File

@ -4,6 +4,8 @@ import { FileEntry } from '../../types/files.js'
import { createReadStream } from 'fs' import { createReadStream } from 'fs'
import { LSBlockDevice, NomadDiskInfoRaw } from '../../types/system.js' import { LSBlockDevice, NomadDiskInfoRaw } from '../../types/system.js'
export const ZIM_STORAGE_PATH = '/storage/zim'
export async function listDirectoryContents(path: string): Promise<FileEntry[]> { export async function listDirectoryContents(path: string): Promise<FileEntry[]> {
const entries = await readdir(path, { withFileTypes: true }) const entries = await readdir(path, { withFileTypes: true })
const results: FileEntry[] = [] const results: FileEntry[] = []