mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-03-31 13:45:09 +00:00
Return info about original files in item detail
This adds data to the current rest api.
This commit is contained in:
parent
ec419c7bfd
commit
957073fe62
@ -1844,6 +1844,7 @@ components:
|
|||||||
- created
|
- created
|
||||||
- updated
|
- updated
|
||||||
- attachments
|
- attachments
|
||||||
|
- sources
|
||||||
- tags
|
- tags
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
@ -1890,6 +1891,10 @@ components:
|
|||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "#/components/schemas/Attachment"
|
$ref: "#/components/schemas/Attachment"
|
||||||
|
sources:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/AttachmentSource"
|
||||||
tags:
|
tags:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
@ -1901,6 +1906,7 @@ components:
|
|||||||
- id
|
- id
|
||||||
- size
|
- size
|
||||||
- contentType
|
- contentType
|
||||||
|
- converted
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
type: string
|
type: string
|
||||||
@ -1913,6 +1919,29 @@ components:
|
|||||||
contentType:
|
contentType:
|
||||||
type: string
|
type: string
|
||||||
format: mimetype
|
format: mimetype
|
||||||
|
converted:
|
||||||
|
type: boolean
|
||||||
|
AttachmentSource:
|
||||||
|
description: |
|
||||||
|
The source or original file of an attachment.
|
||||||
|
required:
|
||||||
|
- id
|
||||||
|
- size
|
||||||
|
- contentType
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
format: ident
|
||||||
|
description: |
|
||||||
|
The id is the attachment id.
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
size:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
contentType:
|
||||||
|
type: string
|
||||||
|
format: mimetype
|
||||||
Registration:
|
Registration:
|
||||||
description: |
|
description: |
|
||||||
Data for registering a new account.
|
Data for registering a new account.
|
||||||
|
@ -84,12 +84,18 @@ trait Conversions {
|
|||||||
data.inReplyTo.map(mkIdName),
|
data.inReplyTo.map(mkIdName),
|
||||||
data.item.dueDate,
|
data.item.dueDate,
|
||||||
data.item.notes,
|
data.item.notes,
|
||||||
data.attachments.map((mkAttachment _).tupled).toList,
|
data.attachments.map((mkAttachment(data)_).tupled).toList,
|
||||||
|
data.sources.map((mkAttachmentSource _).tupled).toList,
|
||||||
data.tags.map(mkTag).toList
|
data.tags.map(mkTag).toList
|
||||||
)
|
)
|
||||||
|
|
||||||
def mkAttachment(ra: RAttachment, m: FileMeta): Attachment =
|
def mkAttachment(item: OItem.ItemData)(ra: RAttachment, m: FileMeta): Attachment = {
|
||||||
Attachment(ra.id, ra.name, m.length, MimeType.unsafe(m.mimetype.asString))
|
val converted = item.sources.find(_._1.id == ra.id).exists(_._2.checksum != m.checksum)
|
||||||
|
Attachment(ra.id, ra.name, m.length, MimeType.unsafe(m.mimetype.asString), converted)
|
||||||
|
}
|
||||||
|
|
||||||
|
def mkAttachmentSource(ra: RAttachmentSource, m: FileMeta): AttachmentSource =
|
||||||
|
AttachmentSource(ra.id, ra.name, m.length, MimeType.unsafe(m.mimetype.asString))
|
||||||
|
|
||||||
// item list
|
// item list
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@ object QItem {
|
|||||||
concEquip: Option[REquipment],
|
concEquip: Option[REquipment],
|
||||||
inReplyTo: Option[IdRef],
|
inReplyTo: Option[IdRef],
|
||||||
tags: Vector[RTag],
|
tags: Vector[RTag],
|
||||||
attachments: Vector[(RAttachment, FileMeta)]
|
attachments: Vector[(RAttachment, FileMeta)],
|
||||||
|
sources: Vector[(RAttachmentSource, FileMeta)]
|
||||||
) {
|
) {
|
||||||
|
|
||||||
def filterCollective(coll: Ident): Option[ItemData] =
|
def filterCollective(coll: Ident): Option[ItemData] =
|
||||||
@ -69,14 +70,16 @@ object QItem {
|
|||||||
]
|
]
|
||||||
.option
|
.option
|
||||||
val attachs = RAttachment.findByItemWithMeta(id)
|
val attachs = RAttachment.findByItemWithMeta(id)
|
||||||
|
val sources = RAttachmentSource.findByItemWithMeta(id)
|
||||||
|
|
||||||
val tags = RTag.findByItem(id)
|
val tags = RTag.findByItem(id)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
data <- q
|
data <- q
|
||||||
att <- attachs
|
att <- attachs
|
||||||
|
srcs <- sources
|
||||||
ts <- tags
|
ts <- tags
|
||||||
} yield data.map(d => ItemData(d._1, d._2, d._3, d._4, d._5, d._6, ts, att))
|
} yield data.map(d => ItemData(d._1, d._2, d._3, d._4, d._5, d._6, ts, att, srcs))
|
||||||
}
|
}
|
||||||
|
|
||||||
case class ListItem(
|
case class ListItem(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package docspell.store.records
|
package docspell.store.records
|
||||||
|
|
||||||
|
import bitpeace.FileMeta
|
||||||
import doobie._
|
import doobie._
|
||||||
import doobie.implicits._
|
import doobie.implicits._
|
||||||
import docspell.common._
|
import docspell.common._
|
||||||
@ -60,5 +61,24 @@ object RAttachmentSource {
|
|||||||
selectSimple(all.map(_.prefix("a")), from, where).query[RAttachmentSource].option
|
selectSimple(all.map(_.prefix("a")), from, where).query[RAttachmentSource].option
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def findByItemWithMeta(id: Ident): ConnectionIO[Vector[(RAttachmentSource, FileMeta)]] = {
|
||||||
|
import bitpeace.sql._
|
||||||
|
|
||||||
|
val aId = Columns.id.prefix("a")
|
||||||
|
val afileMeta = fileId.prefix("a")
|
||||||
|
val bPos = RAttachment.Columns.position.prefix("b")
|
||||||
|
val bId = RAttachment.Columns.id.prefix("b")
|
||||||
|
val bItem = RAttachment.Columns.itemId.prefix("b")
|
||||||
|
val mId = RFileMeta.Columns.id.prefix("m")
|
||||||
|
|
||||||
|
val cols = all.map(_.prefix("a")) ++ RFileMeta.Columns.all.map(_.prefix("m"))
|
||||||
|
val from = table ++ fr"a INNER JOIN" ++
|
||||||
|
RFileMeta.table ++ fr"m ON" ++ afileMeta.is(mId) ++ fr"INNER JOIN" ++
|
||||||
|
RAttachment.table ++ fr"b ON" ++ aId.is(bId)
|
||||||
|
val where = bItem.is(id)
|
||||||
|
|
||||||
|
(selectSimple(cols, from, where) ++ orderBy(bPos.asc)).
|
||||||
|
query[(RAttachmentSource, FileMeta)].to[Vector]
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user