dobo 2.22.0 → 2.22.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.
- package/extend/dobo/feature/image.js +14 -7
- package/package.json +1 -1
- package/wiki/CHANGES.md +4 -0
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
|
|
3
|
+
async function handler (val, rec, opts) {
|
|
4
|
+
const atts = await this.listAttachment({ id: rec.id })
|
|
5
|
+
if (atts.length === 0) return
|
|
6
|
+
let items = atts.filter(att => att.mimeType.startsWith('image/'))
|
|
7
|
+
if (opts.asLink && this.app.waibu) items = items.map(f => `<a href="${f.url}">${opts.baseName ? path.basename(f.file) : f.file}</a>`)
|
|
8
|
+
else if (opts.baseName) items = items.map(f => path.basename(f.file))
|
|
9
|
+
if (opts.single) return items[0]
|
|
10
|
+
return opts.returnAsArray ? items : items.join(', ')
|
|
11
|
+
}
|
|
12
|
+
|
|
3
13
|
async function image (opts = {}) {
|
|
4
14
|
opts.field = opts.field ?? 'image'
|
|
5
15
|
opts.baseName = opts.baseName ?? true
|
|
@@ -10,13 +20,10 @@ async function image (opts = {}) {
|
|
|
10
20
|
type: 'string',
|
|
11
21
|
virtual: true,
|
|
12
22
|
getValue: async function (val, rec) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
else if (opts.baseName) items = items.map(f => path.basename(f.file))
|
|
18
|
-
if (opts.single) return items[0]
|
|
19
|
-
return items
|
|
23
|
+
return await handler.call(this, val, rec, { ...opts, asLink: false })
|
|
24
|
+
},
|
|
25
|
+
format: async function (val, rec) {
|
|
26
|
+
return await handler.call(this, val, rec, { ...opts, asLink: true })
|
|
20
27
|
}
|
|
21
28
|
}
|
|
22
29
|
}
|
package/package.json
CHANGED