Merge pull request #56 from EbookFoundation/staging

fix tagging
master
Theodore Kluge 2019-05-06 20:14:00 -04:00 committed by GitHub
commit f23c83949f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -22,15 +22,15 @@ module.exports = {
if (!body.metadata) throw new HttpError(400, 'Missing OPDS metadata') if (!body.metadata) throw new HttpError(400, 'Missing OPDS metadata')
if (!body.metadata['@type'] || body.metadata['@type'] !== 'http://schema.org/Book') throw new HttpError(400, 'Invalid \'@type\': expected \'http://schema.org/Book\'') if (!body.metadata['@type'] || body.metadata['@type'] !== 'http://schema.org/Book') throw new HttpError(400, 'Invalid \'@type\': expected \'http://schema.org/Book\'')
let tags = (body.metadata.tags || '').split(/,\s*/) let tags = (body.metadata.tags || '').split(/,\s*/).filter(x => x.length)
if (!tags.length && body.metadata.title) tags = body.metadata.title.split(/\s+/).filter(x => x.length < 3) if (!tags.length && body.metadata.title) tags = body.metadata.title.replace(/[^\w\s]/g, '').split(/\s+/).filter(x => x.length >= 3)
const query = { const query = {
hostname: host, hostname: host,
title: body.metadata.title, title: body.metadata.title,
author: body.metadata.author, author: body.metadata.author,
publisher: body.metadata.publisher, publisher: body.metadata.publisher,
identifier: body.metadata.identifier, identifier: body.metadata.identifier,
tags: JSON.stringify(tags), tags: JSON.stringify(tags || []),
version: body.metadata.modified.replace(/\D/g, '') version: body.metadata.modified.replace(/\D/g, '')
} }