dobo 2.10.1 → 2.11.1
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
|
|
10
|
-
|
|
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)) ?? ''
|
|
@@ -155,7 +155,6 @@ async function buildFromDbModel (opts = {}) {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
const props = [...this.properties, ...extFields]
|
|
158
|
-
|
|
159
158
|
for (const p of props) {
|
|
160
159
|
if (excludedTypes.includes(p.type) || excludedNames.includes(p.name)) continue
|
|
161
160
|
if (opts.partial && fields.length > 0 && !fields.includes(p.name)) continue
|
|
@@ -229,11 +228,11 @@ async function buildFromDbModel (opts = {}) {
|
|
|
229
228
|
async function validate (body, joiModel, opts = {}) {
|
|
230
229
|
const { defaultsDeep } = this.app.lib.aneka
|
|
231
230
|
const { isEmpty } = this.app.lib._
|
|
232
|
-
let {
|
|
233
|
-
|
|
231
|
+
let { extFields = [], params = {}, partial } = opts
|
|
234
232
|
params = defaultsDeep(params, this.app.dobo.config.validationParams)
|
|
235
233
|
const { rule = {} } = params
|
|
236
234
|
delete params.rule
|
|
235
|
+
const fields = partial ? Object.keys(body) : [...opts.fields]
|
|
237
236
|
if (isEmpty(joiModel)) joiModel = await buildFromDbModel.call(this, { fields, rule, extFields, partial })
|
|
238
237
|
if (!joiModel) return { value: body }
|
|
239
238
|
try {
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-03-17
|
|
4
|
+
|
|
5
|
+
- [2.11.1] Bug fix on ```model.validate()```: if ```partial``` is true, set ```fields``` from ```body``` keys
|
|
6
|
+
|
|
7
|
+
## 2026-03-16
|
|
8
|
+
|
|
9
|
+
- [2.11.0] Attachment can now listed by its type (```image```, ```video```, etc)
|
|
10
|
+
- [2.11.0] Add ```_last``` to autodetect last item in list in ```@id.js```
|
|
11
|
+
|
|
3
12
|
## 2026-03-12
|
|
4
13
|
|
|
5
14
|
- [2.10.1] Bug fix in ```model._simpleLookup()``` should return ```null``` if query results empty value
|