ml-testing-toolkit 18.13.2-rorfs.0 → 18.13.2-rorfs.2
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/package.json
CHANGED
|
@@ -33,6 +33,13 @@ const dbAdapter = require('./db/adapters/dbAdapter')
|
|
|
33
33
|
const fileAdapter = require('./fileAdapter')
|
|
34
34
|
const axios = require('axios').default
|
|
35
35
|
|
|
36
|
+
const cache = {} // make sure we return the same data after the first fetch
|
|
37
|
+
const fetch = async objectOrUrl => {
|
|
38
|
+
if (!/^https?:\/\//.test(objectOrUrl)) return objectOrUrl
|
|
39
|
+
if (!cache[objectOrUrl]) cache[objectOrUrl] = (await axios.get(objectOrUrl)).data
|
|
40
|
+
return cache[objectOrUrl]
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
const read = async (id, user) => {
|
|
37
44
|
let document
|
|
38
45
|
const Config = require('./config')
|
|
@@ -55,8 +62,7 @@ const read = async (id, user) => {
|
|
|
55
62
|
if (id.endsWith('/')) {
|
|
56
63
|
document = { data: await find(id) }
|
|
57
64
|
} else {
|
|
58
|
-
|
|
59
|
-
document = { data: data?.toString().startsWith('https://') ? (await axios.get(data.toString())).data : data }
|
|
65
|
+
document = { data: await fetch(await fileAdapter.read(id)) }
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
return document
|