mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 01:16:18 -05:00
Add Docs module for searching and organizing PDFs and EPUBs
Create a new Docs module that consolidates PDF and eBook handling into a unified system with subjects and authors support. This replaces the separate PDF/eBook modelers with a single Doc model backed by an alembic migration (rename ebook to doc). Key changes: - New modules/docs package with models, API, extractors, and lib - Subject and author metadata extraction with case-insensitive normalization for cleaner PDF metadata - Frontend Docs pages with AuthorsPage, SubjectsPage using CollectionTable, and doc card deletion - Global search integration for subjects and authors - Generic collection item count support - Frontend file card metadata adjusted to match collection sort - Bump yt-dlp version
This commit is contained in:
parent
4a21499bdd
commit
aefc7b1def
90 changed files with 4484 additions and 1189 deletions
85
modules/docs/api.py
Normal file
85
modules/docs/api.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
from http import HTTPStatus
|
||||
|
||||
from sanic import response, Request, Blueprint
|
||||
from sanic_ext import validate
|
||||
from sanic_ext.extensions.openapi import openapi
|
||||
|
||||
from wrolpi.api_utils import json_response
|
||||
from wrolpi.common import logger, wrol_mode_check, api_param_limiter
|
||||
from wrolpi.errors import ValidationError
|
||||
from wrolpi.schema import JSONErrorResponse
|
||||
from . import schema
|
||||
from .lib import get_statistics, _doc_response, _get_doc, _get_doc_by_file_group, _delete_docs, _search_docs
|
||||
|
||||
NAME = 'docs'
|
||||
|
||||
docs_bp = Blueprint('Docs', '/api/docs')
|
||||
|
||||
logger = logger.getChild(__name__)
|
||||
|
||||
|
||||
@docs_bp.get('/statistics')
|
||||
@openapi.response(HTTPStatus.OK, schema.DocStatisticsResponse)
|
||||
async def statistics(_: Request):
|
||||
ret = get_statistics()
|
||||
return json_response(ret, HTTPStatus.OK)
|
||||
|
||||
|
||||
@docs_bp.get('/<doc_id:int>')
|
||||
@openapi.description('Get a doc by doc ID')
|
||||
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
|
||||
async def get_doc(request: Request, doc_id: int):
|
||||
session = request.ctx.session
|
||||
doc = _get_doc(session, doc_id)
|
||||
return json_response(_doc_response(doc))
|
||||
|
||||
|
||||
@docs_bp.get('/view/<file_group_id:int>')
|
||||
@openapi.description('Get a doc by file_group ID')
|
||||
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
|
||||
async def get_doc_by_file_group(request: Request, file_group_id: int):
|
||||
session = request.ctx.session
|
||||
doc = _get_doc_by_file_group(session, file_group_id)
|
||||
return json_response(_doc_response(doc))
|
||||
|
||||
|
||||
@docs_bp.delete('/<doc_ids:int>', name='doc_delete_one')
|
||||
@docs_bp.delete('/<doc_ids:[0-9,]+>', name='doc_delete_many')
|
||||
@openapi.description('Delete Docs')
|
||||
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
|
||||
@wrol_mode_check
|
||||
async def delete_docs(_: Request, doc_ids: str):
|
||||
try:
|
||||
doc_ids = [int(i) for i in str(doc_ids).split(',')]
|
||||
except ValueError:
|
||||
raise ValidationError('Could not parse doc ids')
|
||||
_delete_docs(*doc_ids)
|
||||
return response.empty()
|
||||
|
||||
|
||||
doc_limit_limiter = api_param_limiter(100)
|
||||
|
||||
|
||||
@docs_bp.post('/search')
|
||||
@openapi.definition(
|
||||
summary='Search docs with filtering',
|
||||
body=schema.DocSearchRequest,
|
||||
)
|
||||
@openapi.response(HTTPStatus.OK, schema.DocSearchResponse)
|
||||
@validate(schema.DocSearchRequest)
|
||||
async def search_docs(_: Request, body: schema.DocSearchRequest):
|
||||
limit = doc_limit_limiter(body.limit)
|
||||
offset = body.offset or 0
|
||||
file_groups, total = _search_docs(
|
||||
search_str=body.search_str,
|
||||
author=body.author,
|
||||
subject=body.subject,
|
||||
language=body.language,
|
||||
mimetype=body.mimetype,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
order_by=body.order_by,
|
||||
tag_names=body.tag_names,
|
||||
)
|
||||
ret = dict(file_groups=file_groups, totals=dict(file_groups=total))
|
||||
return json_response(ret)
|
||||
Loading…
Add table
Add a link
Reference in a new issue