Merge pull request #949 from eikek/convert-pdf-task

Make convert-all-pdfs an admin endpoint
This commit is contained in:
mergify[bot] 2021-07-24 23:37:22 +00:00 committed by GitHub
commit a27e519a55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 48 deletions

View File

@ -6,6 +6,9 @@
### Rest API Changes
- Removed `sec/item/convertallpdfs` endpoint in favor for new
`admin/attachments/convertallpdfs` endpoint which is now an admin
task
- Removed `sec/collective/previews` endpoint, in favor for new
`admin/attachments/generatePreviews` endpoint which is now an admin
task to generate previews for all files. The now removed enpoint did

View File

@ -68,14 +68,14 @@ object JobFactory {
args,
"Create preview images",
now,
submitter.getOrElse(DocspellSystem.taskGroup),
submitter.getOrElse(DocspellSystem.user),
Priority.Low,
Some(DocspellSystem.allPreviewTaskTracker)
)
def convertAllPdfs[F[_]: Sync](
collective: Option[Ident],
account: AccountId,
submitter: Option[Ident],
prio: Priority
): F[RJob] =
for {
@ -84,11 +84,11 @@ object JobFactory {
job = RJob.newJob(
id,
ConvertAllPdfArgs.taskName,
account.collective,
collective.getOrElse(DocspellSystem.taskGroup),
ConvertAllPdfArgs(collective),
s"Convert all pdfs not yet converted",
now,
account.user,
submitter.getOrElse(DocspellSystem.user),
prio,
collective
.map(c => c / ConvertAllPdfArgs.taskName)

View File

@ -181,7 +181,7 @@ trait OItem[F[_]] {
*/
def convertAllPdf(
collective: Option[Ident],
account: AccountId,
submitter: Option[Ident],
notifyJoex: Boolean
): F[UpdateResult]
@ -687,11 +687,11 @@ object OItem {
def convertAllPdf(
collective: Option[Ident],
account: AccountId,
submitter: Option[Ident],
notifyJoex: Boolean
): F[UpdateResult] =
for {
job <- JobFactory.convertAllPdfs[F](collective, account, Priority.Low)
job <- JobFactory.convertAllPdfs[F](collective, submitter, Priority.Low)
_ <- queue.insertIfNew(job)
_ <- if (notifyJoex) joex.notifyAllNodes else ().pure[F]
} yield UpdateResult.success

View File

@ -1350,6 +1350,37 @@ paths:
schema:
$ref: "#/components/schemas/BasicResult"
/admin/attachments/convertallpdfs:
post:
operationId: "admin-attachments-convertallpdf"
tags: [Attachment, Admin]
summary: Convert all PDF files not yet converted
description: |
Docspell converts PDF files into PDF/A files by default, if
the OcrMyPDF tool is configured.
This endpoint can be used to submit a task that runs this on
all files that have not been converted yet in this way.
This conversion tool has been added in version 0.9.0 and so
older files can be "migrated" this way, or maybe after
enabling the tool (it is optional).
The task finds all files collective and submits a task for
each file to convert. These tasks are submitted with a low
priority so that normal processing can still proceed.
The body of the request should be empty.
security:
- adminHeader: []
responses:
200:
description: Ok
content:
application/json:
schema:
$ref: "#/components/schemas/BasicResult"
/sec/source:
get:
operationId: "sec-source-get-all"
@ -1428,33 +1459,6 @@ paths:
schema:
$ref: "#/components/schemas/BasicResult"
/sec/item/convertallpdfs:
post:
operationId: "sec-item-convert-all-pdfs"
tags: [ Item ]
summary: Convert all non-converted pdfs.
description: |
Submits a job that will find all pdf files that have not been
converted and converts them using the ocrmypdf tool (if
enabled). This tool has been added in version 0.9.0 and so
older files can be "migrated" this way, or maybe after
enabling the tool.
The task finds all files of the current collective and submits
task for each file to convert. These tasks are submitted with
a low priority so that normal processing can still proceed.
The body of the request should be empty.
security:
- authTokenHeader: []
responses:
200:
description: Ok
content:
application/json:
schema:
$ref: "#/components/schemas/BasicResult"
/sec/item/search:
get:
operationId: "sec-item-search-by-get"

View File

@ -194,13 +194,21 @@ object AttachmentRoutes {
val dsl = Http4sDsl[F]
import dsl._
HttpRoutes.of { case POST -> Root / "generatePreviews" =>
HttpRoutes.of {
case POST -> Root / "generatePreviews" =>
for {
res <- backend.item.generateAllPreviews(MakePreviewArgs.StoreMode.Replace, true)
resp <- Ok(
Conversions.basicResult(res, "Generate all previews task submitted.")
)
} yield resp
case POST -> Root / "convertallpdfs" =>
for {
res <-
backend.item.convertAllPdf(None, None, true)
resp <- Ok(Conversions.basicResult(res, "Convert all PDFs task submitted"))
} yield resp
}
}

View File

@ -47,13 +47,6 @@ object ItemRoutes {
import dsl._
HttpRoutes.of {
case POST -> Root / "convertallpdfs" =>
for {
res <-
backend.item.convertAllPdf(user.account.collective.some, user.account, true)
resp <- Ok(Conversions.basicResult(res, "Task submitted"))
} yield resp
case GET -> Root / "search" :? QP.Query(q) :? QP.Limit(limit) :? QP.Offset(
offset
) :? QP.WithDetails(detailFlag) =>