dobo 2.18.0 → 2.18.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.
|
@@ -6,10 +6,12 @@ async function createAttachment (...args) {
|
|
|
6
6
|
if (args.length === 0) return this.action(action, ...args)
|
|
7
7
|
const [id, opts = {}] = args
|
|
8
8
|
const { fs } = this.app.lib
|
|
9
|
-
const { isEmpty } = this.app.lib._
|
|
9
|
+
const { isEmpty, last } = this.app.lib._
|
|
10
10
|
const { source, field = 'file', file, fullPath, stats, mimeType, req } = opts
|
|
11
11
|
if (isEmpty(file)) return
|
|
12
12
|
if (!source) throw this.plugin.error('isMissing%s', this.plugin.t('field.source'))
|
|
13
|
+
const [, filename] = last(source.split('/')).split('@')
|
|
14
|
+
if (isEmpty(filename)) return
|
|
13
15
|
const baseDir = await getAttachmentPath.call(this, id, field, file, { dirOnly: true })
|
|
14
16
|
let dir = `${baseDir}/${field}`
|
|
15
17
|
if ((field || '').endsWith('[]')) dir = `${baseDir}/${field.replace('[]', '')}`
|
|
@@ -20,7 +20,7 @@ async function sanitizeBody ({ body = {}, partial, strict, extFields = [], noDef
|
|
|
20
20
|
const result = {}
|
|
21
21
|
|
|
22
22
|
const sanitize = (name, type) => {
|
|
23
|
-
if (onlyTypes.length > 0 && !onlyTypes.includes(type)) return
|
|
23
|
+
// if (onlyTypes.length > 0 && !onlyTypes.includes(type)) return
|
|
24
24
|
if (['object', 'array'].includes(type)) result[name] = sanitizeObject(result[name], { strict, action, model: this.name })
|
|
25
25
|
else if (type === 'boolean') result[name] = sanitizeBoolean(result[name])
|
|
26
26
|
else if (['float', 'double'].includes(type)) result[name] = sanitizeFloat(result[name], { strict })
|
|
@@ -28,11 +28,23 @@ async function sanitizeRecord (record = {}, opts = {}) {
|
|
|
28
28
|
for (const key in newRecord) {
|
|
29
29
|
const prop = this.getProperty(key)
|
|
30
30
|
if (!prop) continue
|
|
31
|
-
const value = ['object', 'array'].includes(prop.type) ? cloneDeep(newRecord[key]) : newRecord[key]
|
|
32
31
|
if (prop.formatValue && opts.retainOriginalValue) {
|
|
33
|
-
const
|
|
34
|
-
if (isFunction(prop.formatValue)) newRecord._orig[key] = await prop.formatValue.call(this,
|
|
35
|
-
else if (isString(prop.formatValue)) newRecord._orig[key] = await callHandler(this.plugin, this,
|
|
32
|
+
const val = ['object', 'array'].includes(prop.type) ? cloneDeep(newRecord._orig[key]) : newRecord._orig[key]
|
|
33
|
+
if (isFunction(prop.formatValue)) newRecord._orig[key] = await prop.formatValue.call(this, val, newRecord._orig, opts)
|
|
34
|
+
else if (isString(prop.formatValue)) newRecord._orig[key] = await callHandler(this.plugin, this, val, newRecord._orig, opts)
|
|
35
|
+
}
|
|
36
|
+
let value = ['object', 'array'].includes(prop.type) ? cloneDeep(newRecord[key]) : newRecord[key]
|
|
37
|
+
if (prop.values) {
|
|
38
|
+
const values = (isString(prop.values) ? await callHandler(prop.values) : [...prop.values]).map(v => {
|
|
39
|
+
if (isString(v)) v = { value: v, text: v }
|
|
40
|
+
if (opts.req) {
|
|
41
|
+
const { camelCase } = this.app.lib._
|
|
42
|
+
const key = camelCase(`${prop.name} ${v.text}`)
|
|
43
|
+
if (opts.req.te(key)) v.text = opts.req.t(key)
|
|
44
|
+
}
|
|
45
|
+
return v
|
|
46
|
+
})
|
|
47
|
+
value = (values.find(v => v.value === value) ?? {}).text ?? value
|
|
36
48
|
}
|
|
37
49
|
if (prop.format) {
|
|
38
50
|
if (isFunction(prop.format)) newRecord[key] = await prop.format.call(this, value, newRecord, opts)
|
|
@@ -45,6 +57,8 @@ async function sanitizeRecord (record = {}, opts = {}) {
|
|
|
45
57
|
}
|
|
46
58
|
newRecord[key] = format(value, prop.type, options)
|
|
47
59
|
}
|
|
60
|
+
// exception
|
|
61
|
+
if (['year'].includes(key)) newRecord[key] = (get(newRecord, `_orig.${key}`, newRecord[key]) + '')
|
|
48
62
|
}
|
|
49
63
|
}
|
|
50
64
|
if (record._ref) newRecord._ref = record._ref
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-04-17
|
|
4
|
+
|
|
5
|
+
- [2.18.1] Bug fix in ```model.createAttachment()```
|
|
6
|
+
- [2.18.1] Bug fix in ```model.sanitizeBody()```
|
|
7
|
+
- [2.18.1] Bug fix in ```model.sanitizeRecord()```
|
|
8
|
+
|
|
3
9
|
## 2026-04-16
|
|
4
10
|
|
|
5
11
|
- [2.18.0] Add parameter options to ```sanitizeObject()```
|