mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-05-26 06:15:07 +02:00
Merge fdf8f05ce3 into 6fb070832d
This commit is contained in:
commit
d8fb36ccf8
|
|
@ -187,6 +187,35 @@ export class KiwixLibraryService {
|
|||
.filter((b) => b.id && b.path)
|
||||
}
|
||||
|
||||
private _validateLibraryXml(xmlContent: string): void {
|
||||
const parser = new XMLParser({
|
||||
ignoreAttributes: false,
|
||||
attributeNamePrefix: '@_',
|
||||
isArray: (name) => name === 'book',
|
||||
})
|
||||
|
||||
const parsed = parser.parse(xmlContent)
|
||||
if (!parsed?.library || typeof parsed.library !== 'object') {
|
||||
throw new Error('Kiwix library XML is missing the library root element.')
|
||||
}
|
||||
}
|
||||
|
||||
async ensureValidLibraryXml(): Promise<boolean> {
|
||||
try {
|
||||
const content = await readFile(this.getLibraryFilePath(), 'utf-8')
|
||||
this._validateLibraryXml(content)
|
||||
return false
|
||||
} catch (err: any) {
|
||||
if (err.code && err.code !== 'ENOENT') {
|
||||
throw err
|
||||
}
|
||||
|
||||
logger.warn('[KiwixLibraryService] Library XML is missing or invalid; rebuilding from disk.')
|
||||
await this.rebuildFromDisk()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
async rebuildFromDisk(opts?: { excludeFilenames?: string[] }): Promise<void> {
|
||||
const dirPath = join(process.cwd(), ZIM_STORAGE_PATH)
|
||||
await ensureDirectoryExists(dirPath)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ export default class KiwixMigrationProvider {
|
|||
const Service = (await import('#models/service')).default
|
||||
const { SERVICE_NAMES } = await import('../constants/service_names.js')
|
||||
const { DockerService } = await import('#services/docker_service')
|
||||
const { KiwixLibraryService } = await import('#services/kiwix_library_service')
|
||||
|
||||
const kiwixService = await Service.query()
|
||||
.where('service_name', SERVICE_NAMES.KIWIX)
|
||||
|
|
@ -34,9 +35,15 @@ export default class KiwixMigrationProvider {
|
|||
|
||||
const dockerService = new DockerService()
|
||||
const isLegacy = await dockerService.isKiwixOnLegacyConfig()
|
||||
const kiwixLibraryService = new KiwixLibraryService()
|
||||
|
||||
if (!isLegacy) {
|
||||
logger.info('[KiwixMigrationProvider] Kiwix is already in library mode — no migration needed.')
|
||||
const rebuilt = await kiwixLibraryService.ensureValidLibraryXml()
|
||||
if (rebuilt) {
|
||||
logger.info('[KiwixMigrationProvider] Rebuilt missing or invalid Kiwix library XML.')
|
||||
} else {
|
||||
logger.info('[KiwixMigrationProvider] Kiwix is already in library mode — no migration needed.')
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user