dobo 1.1.6 → 1.1.7
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/lib/add-fixtures.js +16 -3
- package/package.json +1 -1
package/lib/add-fixtures.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
|
|
3
3
|
async function addFixture (name, { spinner } = {}) {
|
|
4
|
-
const { resolvePath, readConfig, eachPlugins } = this.app.bajo
|
|
5
|
-
const { isEmpty, isArray } = this.lib._
|
|
4
|
+
const { resolvePath, readConfig, eachPlugins, getPluginDataDir } = this.app.bajo
|
|
5
|
+
const { isEmpty, isArray, isString } = this.lib._
|
|
6
|
+
const { fs } = this.lib
|
|
6
7
|
const { schema, connection } = this.getInfo(name)
|
|
7
8
|
if (connection.proxy) {
|
|
8
9
|
this.log.warn('proxiedConnBound%s', schema.name)
|
|
@@ -37,7 +38,19 @@ async function addFixture (name, { spinner } = {}) {
|
|
|
37
38
|
}
|
|
38
39
|
if (v === null) item[k] = undefined
|
|
39
40
|
}
|
|
40
|
-
await this.recordCreate(schema.name, item, { force: true })
|
|
41
|
+
const resp = await this.recordCreate(schema.name, item, { force: true })
|
|
42
|
+
if (isArray(item._attachments) && item._attachments.length > 0) {
|
|
43
|
+
for (let att of item._attachments) {
|
|
44
|
+
if (isString(att)) att = { field: 'file', file: att }
|
|
45
|
+
const fname = path.basename(att.file)
|
|
46
|
+
if (fs.existsSync(att.file)) {
|
|
47
|
+
const dest = `${getPluginDataDir(schema.ns)}/${resp.id}/${att.field}/${fname}`
|
|
48
|
+
try {
|
|
49
|
+
fs.copySync(att.file, dest)
|
|
50
|
+
} catch (err) {}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
41
54
|
result.success++
|
|
42
55
|
if (spinner) spinner.setText('recordsAdded%s%d%d', schema.name, result.success, items.length)
|
|
43
56
|
} catch (err) {
|