mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Only load the malware database once
This commit is contained in:
parent
a6980d5108
commit
53bfb14fea
1 changed files with 8 additions and 1 deletions
|
|
@ -8,7 +8,13 @@ import {
|
||||||
} from "../config/configFile.js";
|
} from "../config/configFile.js";
|
||||||
import { ui } from "../environment/userInteraction.js";
|
import { ui } from "../environment/userInteraction.js";
|
||||||
|
|
||||||
|
let cachedMalwareDatabase = null;
|
||||||
|
|
||||||
export async function openMalwareDatabase() {
|
export async function openMalwareDatabase() {
|
||||||
|
if (cachedMalwareDatabase) {
|
||||||
|
return cachedMalwareDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
const malwareDatabase = await getMalwareDatabase();
|
const malwareDatabase = await getMalwareDatabase();
|
||||||
|
|
||||||
function getPackageStatus(name, version) {
|
function getPackageStatus(name, version) {
|
||||||
|
|
@ -25,13 +31,14 @@ export async function openMalwareDatabase() {
|
||||||
return packageData.reason;
|
return packageData.reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
cachedMalwareDatabase = {
|
||||||
getPackageStatus,
|
getPackageStatus,
|
||||||
isMalware: (name, version) => {
|
isMalware: (name, version) => {
|
||||||
const status = getPackageStatus(name, version);
|
const status = getPackageStatus(name, version);
|
||||||
return isMalwareStatus(status);
|
return isMalwareStatus(status);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
return cachedMalwareDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMalwareDatabase() {
|
async function getMalwareDatabase() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue