Phase 6 add CrossWire SWORD imports
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import {
|
||||
classifySwordModule,
|
||||
fetchSwordConfCatalog,
|
||||
loadLicenseApproval,
|
||||
loadSwordPilotModules,
|
||||
swordPackageUrl,
|
||||
writeSwordAudit,
|
||||
} from './sword-lib.js'
|
||||
|
||||
const pilot = await loadSwordPilotModules()
|
||||
const licenseRegistry = await loadLicenseApproval()
|
||||
const catalog = await fetchSwordConfCatalog(pilot.repository.mods_tarball_url)
|
||||
|
||||
const modules = []
|
||||
|
||||
for (const item of pilot.modules) {
|
||||
const catalogEntry = catalog.modules.get(item.id.toLowerCase())
|
||||
|
||||
if (!catalogEntry) {
|
||||
modules.push({
|
||||
id: item.id,
|
||||
intended_resource_type: item.intended_resource_type,
|
||||
found: false,
|
||||
license_status: 'missing',
|
||||
review_notes: 'Module was not found in the CrossWire catalog.',
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
const conf = catalogEntry.conf
|
||||
const license = classifySwordModule(conf, licenseRegistry)
|
||||
modules.push({
|
||||
id: catalogEntry.module_id,
|
||||
intended_resource_type: item.intended_resource_type,
|
||||
found: true,
|
||||
title: conf.Description ?? catalogEntry.module_id,
|
||||
abbreviation: conf.Abbreviation ?? catalogEntry.module_id,
|
||||
lang: conf.Lang ?? 'n/a',
|
||||
mod_drv: conf.ModDrv,
|
||||
source_type: conf.SourceType,
|
||||
version: conf.Version,
|
||||
sword_version_date: conf.SwordVersionDate,
|
||||
distribution_license: conf.DistributionLicense ?? 'n/a',
|
||||
text_source: conf.TextSource ?? 'n/a',
|
||||
package_url: swordPackageUrl(catalogEntry.module_id, pilot.repository.package_base_url),
|
||||
license_status: license.status,
|
||||
license_rule: license.rule,
|
||||
redistribution: license.redistribution ?? false,
|
||||
commercial_use: license.commercial_use ?? null,
|
||||
share_alike: license.share_alike ?? false,
|
||||
import_enabled: item.import_enabled !== false,
|
||||
import_status: item.import_status ?? (item.import_enabled === false ? 'deferred' : 'candidate'),
|
||||
review_notes: license.notes,
|
||||
reason: item.reason,
|
||||
})
|
||||
}
|
||||
|
||||
const audit = {
|
||||
schema_version: 'librebible.sword-module-audit.v1',
|
||||
generated_at: new Date().toISOString(),
|
||||
repository: pilot.repository,
|
||||
catalog_sha256: catalog.sha256,
|
||||
modules,
|
||||
}
|
||||
|
||||
await writeSwordAudit(audit)
|
||||
|
||||
const approved = modules.filter((module) => module.license_status.startsWith('approved')).length
|
||||
const review = modules.filter((module) => module.license_status === 'review').length
|
||||
const rejected = modules.filter((module) => module.license_status === 'rejected').length
|
||||
|
||||
console.log(`SWORD audit complete: ${modules.length} module(s), ${approved} approved, ${review} review, ${rejected} rejected.`)
|
||||
Reference in New Issue
Block a user