dobo 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,16 @@
1
1
  import path from 'path'
2
2
 
3
3
  async function attachment (req, reply) {
4
- const { isString, isEmpty, find } = this.app.lib._
4
+ const { isString, isEmpty, find, last } = this.app.lib._
5
5
  const { pascalCase } = this.app.lib.aneka
6
6
  const { routePath } = this.app.waibu
7
7
  const { fs } = this.app.lib
8
8
  const mdl = this.app.dobo.getModel(req.params.model)
9
- const items = (await mdl.listAttachments({ id: req.params.id, fieldName: req.params.field, file: '*' })) ?? []
10
- let item = req.params.file === '_first' ? items[0] : undefined
9
+ const type = req.query.type
10
+ const items = (await mdl.listAttachments({ id: req.params.id, fieldName: req.params.field, file: '*', type })) ?? []
11
+ let item
12
+ if (req.params.file === '_first') item = items[0]
13
+ else if (req.params.file === '_last') item = last(items)
11
14
  if (!item) {
12
15
  item = find(items, i => {
13
16
  const [, model, id, field, file] = i.fullPath.split('/')
@@ -10,10 +10,13 @@ async function listAttachment (...args) {
10
10
  const mime = await importPkg('waibu:mime')
11
11
  const { fastGlob } = this.app.lib
12
12
 
13
- const { id = '*', fieldName = '*', file = '*' } = params
13
+ const { id = '*', fieldName = '*', file = '*', type } = params
14
14
  const { uriEncoded = true } = opts
15
15
  const root = `${getPluginDataDir('dobo')}/attachment`
16
16
  let pattern = `${root}/${this.name}/${id}/${fieldName}/${file}`
17
+ if (type === 'image') pattern += '.{jpg,jpeg,gif,png,webp,avif,svg}'
18
+ else if (type === 'video') pattern += '.{mp4,m4v,webm,mov,qt,mkv,ogg,ogv}'
19
+ else if (type) pattern += `.${type}`
17
20
  if (uriEncoded) pattern = pattern.split('/').map(p => decodeURI(p)).join('/')
18
21
  return map(await fastGlob(pattern), f => {
19
22
  const mimeType = mime.getType(path.extname(f)) ?? ''
@@ -111,7 +111,7 @@ async function modelFactory () {
111
111
  const { getModel } = this.app.dobo
112
112
  const ref = getModel(model)
113
113
  const rec = await ref.findOneRecord({ query }, { noHook: true, noCache: true, ...options })
114
- return get(rec, field)
114
+ return get(rec, field, null)
115
115
  }
116
116
 
117
117
  build = build
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "description": "DBMS for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-16
4
+
5
+ - [2.11.0] Attachment can now listed by its type (```image```, ```video```, etc)
6
+ - [2.11.0] Add ```_last``` to autodetect last item in list in ```@id.js```
7
+
8
+ ## 2026-03-12
9
+
10
+ - [2.10.1] Bug fix in ```model._simpleLookup()``` should return ```null``` if query results empty value
11
+
3
12
  ## 2026-03-11
4
13
 
5
14
  - [2.10.0] Add ```immutable``` and ```feature``` to the list of allowed property keys