mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Fetch new package list
This commit is contained in:
parent
5864b09bde
commit
cddcec9ba5
6 changed files with 564 additions and 11 deletions
|
|
@ -203,6 +203,70 @@ export function readDatabaseFromLocalCache() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../api/aikido.js").NewPackageEntry[]} data
|
||||
* @param {string | number} version
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function writeNewPackagesListToLocalCache(data, version) {
|
||||
try {
|
||||
const listPath = getNewPackagesListPath();
|
||||
const versionPath = getNewPackagesListVersionPath();
|
||||
|
||||
fs.writeFileSync(listPath, JSON.stringify(data));
|
||||
fs.writeFileSync(versionPath, version.toString());
|
||||
} catch {
|
||||
ui.writeWarning(
|
||||
"Failed to write new packages list to local cache, next time the list will be fetched from the server again."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {{newPackagesList: import("../api/aikido.js").NewPackageEntry[] | null, version: string | null}}
|
||||
*/
|
||||
export function readNewPackagesListFromLocalCache() {
|
||||
try {
|
||||
const listPath = getNewPackagesListPath();
|
||||
if (!fs.existsSync(listPath)) {
|
||||
return { newPackagesList: null, version: null };
|
||||
}
|
||||
|
||||
const data = fs.readFileSync(listPath, "utf8");
|
||||
const newPackagesList = JSON.parse(data);
|
||||
const versionPath = getNewPackagesListVersionPath();
|
||||
let version = null;
|
||||
if (fs.existsSync(versionPath)) {
|
||||
version = fs.readFileSync(versionPath, "utf8").trim();
|
||||
}
|
||||
return { newPackagesList, version };
|
||||
} catch {
|
||||
ui.writeWarning(
|
||||
"Failed to read new packages list from local cache. Continuing without local cache."
|
||||
);
|
||||
return { newPackagesList: null, version: null };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
function getNewPackagesListPath() {
|
||||
const safeChainDir = getSafeChainDirectory();
|
||||
const ecosystem = getEcoSystem();
|
||||
return path.join(safeChainDir, `newPackagesList_${ecosystem}.json`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
function getNewPackagesListVersionPath() {
|
||||
const safeChainDir = getSafeChainDirectory();
|
||||
const ecosystem = getEcoSystem();
|
||||
return path.join(safeChainDir, `newPackagesList_version_${ecosystem}.txt`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {SafeChainConfig}
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue