Admin : déroulant sommaire PDF par chapitre, transitions pages, URL GrateWizard
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- Ajout API /api/admin/pdf-outline (extraction sommaire PDF côté serveur via pdfjs-dist) - Déroulant <select> dans chaque ligne de chapitre admin avec les 61 titres/sous-titres du PDF - Sauvegarde des associations chapitre→page PDF via config YAML - Transition douce (fondu 1s/1.2s) pour le changement de pages dans le viewer PDF - Correction des numéros de pages réels dans chapterPages (extraits du sommaire PDF) - URL GrateWizard prod → gratewizard.axiom-team.fr Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
43
server/api/admin/pdf-outline.get.ts
Normal file
43
server/api/admin/pdf-outline.get.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { join } from 'node:path'
|
||||
import { readFileSync } from 'node:fs'
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
const config = await readYaml('bookplayer.config.yml')
|
||||
const pdfFile = config?.book?.pdfFile || '/pdf/une-economie-du-don.pdf'
|
||||
const pdfPath = join(process.cwd(), 'public', pdfFile)
|
||||
|
||||
let data: Uint8Array
|
||||
try {
|
||||
data = new Uint8Array(readFileSync(pdfPath))
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
|
||||
const pdfjsLib = await import('pdfjs-dist/legacy/build/pdf.mjs')
|
||||
const doc = await pdfjsLib.getDocument({ data, useSystemFonts: true }).promise
|
||||
const outline = await doc.getOutline()
|
||||
|
||||
if (!outline || outline.length === 0) {
|
||||
doc.destroy()
|
||||
return []
|
||||
}
|
||||
|
||||
const entries: Array<{ title: string; page: number; level: number }> = []
|
||||
|
||||
async function extract(items: any[], level: number) {
|
||||
for (const item of items) {
|
||||
let page: number | null = null
|
||||
try {
|
||||
let dest = item.dest
|
||||
if (typeof dest === 'string') dest = await doc.getDestination(dest)
|
||||
if (dest) page = (await doc.getPageIndex(dest[0])) + 1
|
||||
} catch {}
|
||||
if (page !== null) entries.push({ title: item.title, page, level })
|
||||
if (item.items?.length) await extract(item.items, level + 1)
|
||||
}
|
||||
}
|
||||
|
||||
await extract(outline, 0)
|
||||
doc.destroy()
|
||||
return entries
|
||||
})
|
||||
Reference in New Issue
Block a user