mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Replace generating preview images with an admin endpoint
It doesn't make much sense to have this per collective, because this is triggered by an admin after changing the server config file. So it is now implemented as an admin endpoint that affects all files.
This commit is contained in:
@ -193,6 +193,14 @@ trait OItem[F[_]] {
|
||||
account: AccountId,
|
||||
notifyJoex: Boolean
|
||||
): F[UpdateResult]
|
||||
|
||||
/** Submits a task that (re)generates the preview images for all
|
||||
* attachments.
|
||||
*/
|
||||
def generateAllPreviews(
|
||||
storeMode: MakePreviewArgs.StoreMode,
|
||||
notifyJoex: Boolean
|
||||
): F[UpdateResult]
|
||||
}
|
||||
|
||||
object OItem {
|
||||
@ -699,6 +707,16 @@ object OItem {
|
||||
_ <- if (notifyJoex) joex.notifyAllNodes else ().pure[F]
|
||||
} yield UpdateResult.success
|
||||
|
||||
def generateAllPreviews(
|
||||
storeMode: MakePreviewArgs.StoreMode,
|
||||
notifyJoex: Boolean
|
||||
): F[UpdateResult] =
|
||||
for {
|
||||
job <- JobFactory.allPreviews[F](AllPreviewsArgs(None, storeMode), None)
|
||||
_ <- queue.insertIfNew(job)
|
||||
_ <- if (notifyJoex) joex.notifyAllNodes else ().pure[F]
|
||||
} yield UpdateResult.success
|
||||
|
||||
private def onSuccessIgnoreError(update: F[Unit])(ar: UpdateResult): F[Unit] =
|
||||
ar match {
|
||||
case UpdateResult.Success =>
|
||||
|
@ -1136,30 +1136,6 @@ paths:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
|
||||
/sec/collective/previews:
|
||||
post:
|
||||
operationId: "sec-collective-previews-start-generate"
|
||||
tags: [ Collective ]
|
||||
summary: Starts the generate previews task
|
||||
description: |
|
||||
Submits a task that re-generates preview images of all
|
||||
attachments of the current collective. Each existing preview
|
||||
image will be replaced.
|
||||
|
||||
This can be used after changing the `preview` settings.
|
||||
|
||||
If only preview images of selected attachments should be
|
||||
regenerated, see the `/sec/attachment/{id}/preview` endpoint.
|
||||
security:
|
||||
- authTokenHeader: []
|
||||
responses:
|
||||
200:
|
||||
description: Ok
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
|
||||
/sec/user:
|
||||
get:
|
||||
operationId: "sec-user-get-all"
|
||||
@ -1348,6 +1324,32 @@ paths:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ResetPasswordResult"
|
||||
|
||||
/admin/attachments/generatePreviews:
|
||||
post:
|
||||
operationId: "admin-attachments-generate-previews"
|
||||
tags: [Attachment, Admin]
|
||||
summary: (Re)generate all preview images
|
||||
description: |
|
||||
Submits a task that re-generates preview images of all
|
||||
attachments. Each existing preview image will be replaced.
|
||||
|
||||
This can be used after changing the `preview` settings.
|
||||
|
||||
If only preview images of selected attachments should be
|
||||
regenerated, see the `/sec/attachment/{id}/preview` endpoint.
|
||||
|
||||
This is an admin route, you need to specify the secret from
|
||||
the config file via a http header `Docspell-Admin-Secret`.
|
||||
security:
|
||||
- adminHeader: []
|
||||
responses:
|
||||
200:
|
||||
description: Ok
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
|
||||
/sec/source:
|
||||
get:
|
||||
operationId: "sec-source-get-all"
|
||||
|
@ -108,9 +108,10 @@ object RestServer {
|
||||
|
||||
def adminRoutes[F[_]: Async](cfg: Config, restApp: RestApp[F]): HttpRoutes[F] =
|
||||
Router(
|
||||
"fts" -> FullTextIndexRoutes.admin(cfg, restApp.backend),
|
||||
"user" -> UserRoutes.admin(restApp.backend),
|
||||
"info" -> InfoRoutes.admin(cfg)
|
||||
"fts" -> FullTextIndexRoutes.admin(cfg, restApp.backend),
|
||||
"user" -> UserRoutes.admin(restApp.backend),
|
||||
"info" -> InfoRoutes.admin(cfg),
|
||||
"attachments" -> AttachmentRoutes.admin(restApp.backend)
|
||||
)
|
||||
|
||||
def redirectTo[F[_]: Async](path: String): HttpRoutes[F] = {
|
||||
|
@ -189,4 +189,19 @@ object AttachmentRoutes {
|
||||
} yield resp
|
||||
}
|
||||
}
|
||||
|
||||
def admin[F[_]: Async](backend: BackendApp[F]): HttpRoutes[F] = {
|
||||
val dsl = Http4sDsl[F]
|
||||
import dsl._
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import cats.implicits._
|
||||
import docspell.backend.BackendApp
|
||||
import docspell.backend.auth.AuthToken
|
||||
import docspell.backend.ops.OCollective
|
||||
import docspell.common.{ListType, MakePreviewArgs}
|
||||
import docspell.common.ListType
|
||||
import docspell.restapi.model._
|
||||
import docspell.restserver.conv.Conversions
|
||||
import docspell.restserver.http4s._
|
||||
@ -101,18 +101,6 @@ object CollectiveRoutes {
|
||||
resp <- Ok(BasicResult(true, "Task submitted"))
|
||||
} yield resp
|
||||
|
||||
case POST -> Root / "previews" =>
|
||||
for {
|
||||
res <- backend.collective.generatePreviews(
|
||||
MakePreviewArgs.StoreMode.Replace,
|
||||
user.account,
|
||||
true
|
||||
)
|
||||
resp <- Ok(
|
||||
Conversions.basicResult(res, "Generate all previews task submitted.")
|
||||
)
|
||||
} yield resp
|
||||
|
||||
case GET -> Root =>
|
||||
for {
|
||||
collDb <- backend.collective.find(user.account.collective)
|
||||
|
Reference in New Issue
Block a user