Adding in hash handling for datasource plugins.
This commit is contained in:
parent
38e97c7cdb
commit
2bb32253d8
|
@ -93,7 +93,11 @@ module.exports = {
|
||||||
for (let plugin of plugins) {
|
for (let plugin of plugins) {
|
||||||
if (plugin.name === integration) {
|
if (plugin.name === integration) {
|
||||||
// need to use commonJS require due to its dynamic runtime nature
|
// need to use commonJS require due to its dynamic runtime nature
|
||||||
return getDatasourcePlugin(plugin.name, plugin.jsUrl)
|
return getDatasourcePlugin(
|
||||||
|
plugin.name,
|
||||||
|
plugin.jsUrl,
|
||||||
|
plugin.schema?.hash
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -351,13 +351,20 @@ exports.extractPluginTarball = async file => {
|
||||||
return { metadata, directory: path }
|
return { metadata, directory: path }
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getDatasourcePlugin = async (name, url) => {
|
exports.getDatasourcePlugin = async (name, url, hash) => {
|
||||||
if (!fs.existsSync(DATASOURCE_PATH)) {
|
if (!fs.existsSync(DATASOURCE_PATH)) {
|
||||||
fs.mkdirSync(DATASOURCE_PATH)
|
fs.mkdirSync(DATASOURCE_PATH)
|
||||||
}
|
}
|
||||||
const filename = join(DATASOURCE_PATH, name)
|
const filename = join(DATASOURCE_PATH, name)
|
||||||
|
const metadataName = `${filename}.bbmetadata`
|
||||||
if (fs.existsSync(filename)) {
|
if (fs.existsSync(filename)) {
|
||||||
return require(filename)
|
const currentHash = fs.readFileSync(metadataName, "utf8")
|
||||||
|
// if hash is the same return the file, otherwise remove it and re-download
|
||||||
|
if (currentHash === hash) {
|
||||||
|
return require(filename)
|
||||||
|
} else {
|
||||||
|
fs.unlinkSync(filename)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const fullUrl = checkSlashesInUrl(
|
const fullUrl = checkSlashesInUrl(
|
||||||
`${env.MINIO_URL}/${ObjectStoreBuckets.PLUGINS}/${url}`
|
`${env.MINIO_URL}/${ObjectStoreBuckets.PLUGINS}/${url}`
|
||||||
|
@ -366,6 +373,7 @@ exports.getDatasourcePlugin = async (name, url) => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const content = await response.text()
|
const content = await response.text()
|
||||||
fs.writeFileSync(filename, content)
|
fs.writeFileSync(filename, content)
|
||||||
|
fs.writeFileSync(metadataName, hash)
|
||||||
require(filename)
|
require(filename)
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
Loading…
Reference in New Issue