dobo 2.40.0 → 2.40.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.
|
@@ -292,9 +292,10 @@ export async function handleAttachmentUpload (id, trigger, options = {}) {
|
|
|
292
292
|
* @returns {Promise<void>}
|
|
293
293
|
* @param {Array<Object>} records - The records to get attachments for.
|
|
294
294
|
*/
|
|
295
|
-
export async function getAttachments (records = []) {
|
|
295
|
+
export async function getAttachments (records = [], options = {}) {
|
|
296
|
+
options.keys = ['url', 'mimeType', 'fileName']
|
|
296
297
|
for (const rec of records) {
|
|
297
|
-
rec._attachments = await this.listAttachment({ id: rec.id })
|
|
298
|
+
rec._attachments = await this.listAttachment({ id: rec.id }, options)
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
301
|
|
|
@@ -4,14 +4,14 @@ const action = 'listAttachment'
|
|
|
4
4
|
async function listAttachment (...args) {
|
|
5
5
|
if (!this.options.attachment || !this.app.waibu) return []
|
|
6
6
|
if (args.length === 0) return this.action(action, ...args)
|
|
7
|
-
const [params = {},
|
|
8
|
-
const { map, kebabCase } = this.app.lib._
|
|
7
|
+
const [params = {}, options = {}] = args
|
|
8
|
+
const { map, kebabCase, pick } = this.app.lib._
|
|
9
9
|
const { importPkg } = this.app.bajo
|
|
10
10
|
const mime = await importPkg('waibu:mime')
|
|
11
11
|
const { fastGlob } = this.app.lib
|
|
12
12
|
|
|
13
13
|
const { id = '*', field = '*', file = '*', type } = params
|
|
14
|
-
|
|
14
|
+
let { uriEncoded = true, keys = [] } = options
|
|
15
15
|
const root = `${this.app.getPluginDataDir('dobo')}/attachment`
|
|
16
16
|
let pattern = `${root}/${this.name}/${id}/${field}/${file}`
|
|
17
17
|
if (type === 'image') pattern += '.{jpg,jpeg,gif,png,webp,avif,svg}'
|
|
@@ -33,7 +33,8 @@ async function listAttachment (...args) {
|
|
|
33
33
|
const [, _model, _id, _field, _file] = fullPath.split('/')
|
|
34
34
|
row.url = routePath(`dobo:/attachment/${kebabCase(_model)}/${_id}/${_field}/${_file}`)
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
if (keys.length === 0) keys = Object.keys(row)
|
|
37
|
+
return pick(row, keys)
|
|
37
38
|
})
|
|
38
39
|
}
|
|
39
40
|
|
package/package.json
CHANGED