diff --git a/admin/app/services/kiwix_library_service.ts b/admin/app/services/kiwix_library_service.ts index 81f63fa8..7ec3955b 100644 --- a/admin/app/services/kiwix_library_service.ts +++ b/admin/app/services/kiwix_library_service.ts @@ -1,8 +1,12 @@ import { XMLBuilder, XMLParser } from 'fast-xml-parser' -import { readFile, writeFile, rename, readdir } from 'fs/promises' -import { join } from 'path' -import { Archive } from '@openzim/libzim' -import { KIWIX_LIBRARY_XML_PATH, ZIM_STORAGE_PATH, ensureDirectoryExists, isValidZimFile } from '../utils/fs.js' +import { readFile, writeFile, rename, readdir } from 'node:fs/promises' +import { join } from 'node:path' +import { + KIWIX_LIBRARY_XML_PATH, + ZIM_STORAGE_PATH, + ensureDirectoryExists, + isValidZimFile, +} from '../utils/fs.js' import logger from '@adonisjs/core/services/logger' import { randomUUID } from 'node:crypto' @@ -60,6 +64,7 @@ export class KiwixLibraryService { logger.warn(`[KiwixLibraryService] Skipping invalid/corrupted ZIM file: ${zimFilePath}`) return null } + const { Archive } = await import('@openzim/libzim') const archive = new Archive(zimFilePath) const getMeta = (key: string): string | undefined => { @@ -179,8 +184,7 @@ export class KiwixLibraryService { faviconMimeType: b['@_faviconMimeType'], favicon: b['@_favicon'], date: b['@_date'], - articleCount: - b['@_articleCount'] !== undefined ? Number(b['@_articleCount']) : undefined, + articleCount: b['@_articleCount'] !== undefined ? Number(b['@_articleCount']) : undefined, mediaCount: b['@_mediaCount'] !== undefined ? Number(b['@_mediaCount']) : undefined, size: b['@_size'] !== undefined ? Number(b['@_size']) : undefined, })) diff --git a/admin/app/services/zim_extraction_service.ts b/admin/app/services/zim_extraction_service.ts index 072098ca..5b5f702a 100644 --- a/admin/app/services/zim_extraction_service.ts +++ b/admin/app/services/zim_extraction_service.ts @@ -1,4 +1,4 @@ -import { Archive, Entry } from '@openzim/libzim' +import type { Archive, Entry } from '@openzim/libzim' import * as cheerio from 'cheerio' import { HTML_SELECTORS_TO_REMOVE, NON_CONTENT_HEADING_PATTERNS } from '../../constants/zim_extraction.js' import { extractStructuredContent } from '../utils/zim_html.js' @@ -63,6 +63,7 @@ export class ZIMExtractionService { throw new Error(`ZIM file is invalid or corrupted: ${filePath}`) } + const { Archive } = await import('@openzim/libzim') const archive = new Archive(filePath) // Extract archive-level metadata once @@ -265,4 +266,4 @@ export class ZIMExtractionService { return false; } } -} \ No newline at end of file +} diff --git a/admin/bin/test.ts b/admin/bin/test.ts index d759efe4..f4f0d1f0 100644 --- a/admin/bin/test.ts +++ b/admin/bin/test.ts @@ -12,6 +12,27 @@ process.env.NODE_ENV = 'test' +// Keep a clean checkout able to boot the test runner without requiring a +// developer's database/Redis credentials. A checked-in .env.test still wins +// through Adonis' normal environment loading; these values only fill gaps. +const testDefaults: Record = { + PORT: '3333', + APP_KEY: 'test-only-app-key-not-for-production', + HOST: '127.0.0.1', + URL: 'http://127.0.0.1:3333', + LOG_LEVEL: 'error', + DB_HOST: '127.0.0.1', + DB_PORT: '3306', + DB_USER: 'root', + DB_DATABASE: 'nomad_test', + REDIS_HOST: '127.0.0.1', + REDIS_PORT: '6379', +} + +for (const [key, value] of Object.entries(testDefaults)) { + process.env[key] ??= value +} + import 'reflect-metadata' import { Ignitor, prettyPrintError } from '@adonisjs/core' import { configure, processCLIArgs, run } from '@japa/runner'