From b30be5b344e2ae5c0e242f488638fe415ccac4c4 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Thu, 20 Apr 2023 15:37:01 +0200 Subject: [PATCH] metadata: fields list by default define in configuration --- config/config.ini.example | 3 +++ public/js/metadata.js | 27 +++++++++++++++++++++++---- templates/metadata.html.php | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/config/config.ini.example b/config/config.ini.example index ee6842a..7611cbd 100644 --- a/config/config.ini.example +++ b/config/config.ini.example @@ -9,3 +9,6 @@ PDF_STORAGE_PATH=/path/to/folder ; Manage demo link pdf : true (by default, show), false (hide), or custom link ;PDF_DEMO_LINK=true + +; Metadata default fields +;METADATA_DEFAULT_FIELDS[metadata_key].type = "text" diff --git a/public/js/metadata.js b/public/js/metadata.js index b280fa0..4979ccb 100644 --- a/public/js/metadata.js +++ b/public/js/metadata.js @@ -33,18 +33,23 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) { await loadingTask.promise.then(function(pdf) { pdf.getMetadata().then(function(metadata) { console.log(metadata); + for(fieldKey in defaultFields) { + addMetadata(fieldKey, null, defaultFields[fieldKey]['type']); + } + for(metaKey in metadata.info) { if(metaKey == "Custom" || metaKey == "PDFFormatVersion" || metaKey.match(/^Is/) || metaKey == "Trapped") { continue; } - addMetadata(metaKey, metadata.info[metaKey]); + addMetadata(metaKey, metadata.info[metaKey], "text"); } + for(metaKey in metadata.info.Custom) { if(metaKey == "sha256") { continue; } - addMetadata(metaKey, metadata.info.Custom[metaKey]); + addMetadata(metaKey, metadata.info.Custom[metaKey], "text"); } for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) { @@ -89,12 +94,26 @@ var pageRender = async function(pageIndex) { }); } -var addMetadata = function(key, value) { +var addMetadata = function(key, value, type) { + let input = document.querySelector('.input-metadata input[name="'+key+'"]'); + + if(input && input.value === null) { + input.value = value; + return; + } + + if(input) { + input.focus(); + return; + } + let div = document.createElement('div'); div.classList.add('form-floating', 'mt-3', 'input-metadata'); - let input = document.createElement('input'); + input = document.createElement('input'); input.value = value; + input.type = type; + input.name = key; input.classList.add('form-control'); let label = document.createElement('label'); diff --git a/templates/metadata.html.php b/templates/metadata.html.php index 1ceac5c..a868f2a 100644 --- a/templates/metadata.html.php +++ b/templates/metadata.html.php @@ -100,7 +100,7 @@