Commit d838c166 authored by Markus Opolka's avatar Markus Opolka
Browse files

Add XML validation and handling in front and backend

parent ff6b0916
......@@ -45,12 +45,17 @@ function inCacheFormat (docname, docobj) {
collection: docobj.TEI.teiHeader.fileDesc.titleStmt.collection._text,
url: '/api/letters/' + docname.slice(0, -4),
name: docname.replace(/_/g, ' ').slice(0, -4),
valid: true,
hash: hash,
object: docobj
}
} catch (err) {
console.log(arguments.callee) // eslint-disable-line no-caller
console.error('>> Error while loading ' + docname)
doc = {
name: docname.replace(/_/g, ' ').slice(0, -4),
valid: false
}
}
return doc
......@@ -147,11 +152,13 @@ app.get('/api/search', function (req, res) {
}
let data = []
for (let item of cache.keys()) {
let obj = loadDocument(item)
let results = lib.search(obj, query)
if (results !== null) {
data.push(results)
for (let name of cache.keys()) {
let obj = loadDocument(name)
if (obj.valid) {
let results = lib.search(obj, query)
if (results !== null) {
data.push(results)
}
}
}
......@@ -176,18 +183,22 @@ app.get('/api/features/:letter?', function (req, res) {
if (req.params.letter) {
console.time('> Search Features - Letter')
let obj = loadDocument(DOC)
let results = lib.features(obj, query)
if (results !== null) {
data.push(results)
if (obj.valid) {
let results = lib.features(obj, query)
if (results !== null) {
data.push(results)
}
}
console.timeEnd('> Search Features - Letter')
} else {
console.time('> Search Features')
for (let item of cache.keys()) {
let obj = loadDocument(item)
let results = lib.features(obj, query)
if (results !== null) {
data.push(results)
if (obj.valid) {
let results = lib.features(obj, query)
if (results !== null) {
data.push(results)
}
}
}
console.timeEnd('> Search Features')
......
......@@ -151,8 +151,8 @@ function metadataTable (objs) {
let items = []
for (let item of objs) {
let meta = item.object.TEI.teiHeader.fileDesc.titleStmt
try {
let meta = item.object.TEI.teiHeader.fileDesc.titleStmt
items.push({
title: meta.title._text,
name: item.name,
......@@ -163,11 +163,16 @@ function metadataTable (objs) {
date: meta.date._text,
place: meta.place._text,
url: item.url,
link: item.link
link: item.link,
valid: true
})
} catch (err) {
console.log(arguments.callee) // eslint-disable-line no-caller
console.log('>> Error while table formating' + meta.title._text)
console.log('>> Error while table formating' + item.name)
items.push({
name: item.name,
valid: false
})
}
}
......
......@@ -142,7 +142,7 @@ export default {
// Sums up all hits in all letters
let hits = 0
for (let value of this.results) {
hits = hits + value.count
hits = hits + value.hits
}
return hits
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment