mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-05 16:26:15 +02:00
fix(content): recognize Wikipedia downloads from mirror sources
When Wikipedia is downloaded via a custom mirror instead of the default Kiwix server, the completion callback now matches by filename instead of exact URL. This ensures the Wikipedia selector correctly shows "Installed" status and triggers old-version cleanup regardless of which mirror was used. Also handles the case where no Wikipedia selection exists yet (file downloaded before visiting the selector), creating the record automatically. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3b26f3cf1a
commit
38304d9012
|
|
@ -521,25 +521,47 @@ export class ZimService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onWikipediaDownloadComplete(url: string, success: boolean): Promise<void> {
|
async onWikipediaDownloadComplete(url: string, success: boolean): Promise<void> {
|
||||||
|
const filename = url.split('/').pop() || ''
|
||||||
const selection = await this.getWikipediaSelection()
|
const selection = await this.getWikipediaSelection()
|
||||||
|
|
||||||
if (!selection || selection.url !== url) {
|
// Determine which Wikipedia option this file belongs to by matching filename
|
||||||
logger.warn(`[ZimService] Wikipedia download complete callback for unknown URL: ${url}`)
|
let matchedOptionId: string | null = null
|
||||||
return
|
try {
|
||||||
|
const options = await this.getWikipediaOptions()
|
||||||
|
for (const opt of options) {
|
||||||
|
if (opt.url && opt.url.split('/').pop() === filename) {
|
||||||
|
matchedOptionId = opt.id
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// If we can't fetch options, try to continue with existing selection
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// Update status to installed
|
// Update or create the selection record
|
||||||
selection.status = 'installed'
|
// Match by filename (not URL) so mirror downloads are recognized
|
||||||
await selection.save()
|
if (selection) {
|
||||||
|
selection.option_id = matchedOptionId || selection.option_id
|
||||||
|
selection.url = url
|
||||||
|
selection.filename = filename
|
||||||
|
selection.status = 'installed'
|
||||||
|
await selection.save()
|
||||||
|
} else {
|
||||||
|
await WikipediaSelection.create({
|
||||||
|
option_id: matchedOptionId || 'unknown',
|
||||||
|
url: url,
|
||||||
|
filename: filename,
|
||||||
|
status: 'installed',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
logger.info(`[ZimService] Wikipedia download completed successfully: ${selection.filename}`)
|
logger.info(`[ZimService] Wikipedia download completed successfully: ${filename}`)
|
||||||
|
|
||||||
// Delete the old Wikipedia file if it exists and is different
|
// Delete old Wikipedia files (keep only the newly installed one)
|
||||||
// We need to find what was previously installed
|
|
||||||
const existingFiles = await this.list()
|
const existingFiles = await this.list()
|
||||||
const wikipediaFiles = existingFiles.files.filter((f) =>
|
const wikipediaFiles = existingFiles.files.filter((f) =>
|
||||||
f.name.startsWith('wikipedia_en_') && f.name !== selection.filename
|
f.name.startsWith('wikipedia_en_') && f.name !== filename
|
||||||
)
|
)
|
||||||
|
|
||||||
for (const oldFile of wikipediaFiles) {
|
for (const oldFile of wikipediaFiles) {
|
||||||
|
|
@ -551,10 +573,14 @@ export class ZimService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Download failed - keep the selection record but mark as failed
|
// Download failed - update selection if it matches this file
|
||||||
selection.status = 'failed'
|
if (selection && (!selection.filename || selection.filename === filename)) {
|
||||||
await selection.save()
|
selection.status = 'failed'
|
||||||
logger.error(`[ZimService] Wikipedia download failed for: ${selection.filename}`)
|
await selection.save()
|
||||||
|
logger.error(`[ZimService] Wikipedia download failed for: ${filename}`)
|
||||||
|
} else {
|
||||||
|
logger.error(`[ZimService] Wikipedia download failed for: ${filename} (no matching selection)`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user