From a14e556625e29b077e2fa485d040cdcdbb6db01e Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Fri, 2 Feb 2024 22:02:36 -0800 Subject: [PATCH] Ensure the name is reserved, and direct queries return package data --- src/bundled_packages/index.js | 4 ++-- src/controllers/getPackagesPackageName.js | 19 +++++++++++++++++++ src/controllers/postPackages.js | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/bundled_packages/index.js b/src/bundled_packages/index.js index 839fa7ca..538c1513 100644 --- a/src/bundled_packages/index.js +++ b/src/bundled_packages/index.js @@ -8,9 +8,9 @@ module.exports = { // Used to check if a specific name belongs to a bundled package isNameBundled: (name) => { if (BUNDLED_PACKAGES[name]) { - return true; + return { ok: true, content: true }; } else { - return false; + return { ok: true, content: false }; } }, diff --git a/src/controllers/getPackagesPackageName.js b/src/controllers/getPackagesPackageName.js index 7efb5806..43207c1b 100644 --- a/src/controllers/getPackagesPackageName.js +++ b/src/controllers/getPackagesPackageName.js @@ -43,6 +43,25 @@ module.exports = { * @returns {sso} */ async logic(params, context) { + + // Lets first check if this is a bundled package we should return + const isBundled = context.bundled.isBundled(params.packageName); + + if (isBundled.ok && isBundled.content) { + // This is in fact a bundled package + const bundledData = context.bundled.getBundledPackage(params.packageName); + + if (!bundledData.ok) { + const sso = new context.sso(); + + return sso.notOk().addContent(bundledData).addCalls("bundled.isBundled", isBundled); + } + + const sso = new context.sso(); + + return sso.isOk().addContent(bundledData.content); + } + let pack = await context.database.getPackageByName( params.packageName, true diff --git a/src/controllers/postPackages.js b/src/controllers/postPackages.js index b80b43cc..9f509a81 100644 --- a/src/controllers/postPackages.js +++ b/src/controllers/postPackages.js @@ -179,6 +179,21 @@ module.exports = { .addCalls("db.packageNameAvailability", nameAvailable); } + // Now to check if this package is a bundled package (since they don't exist on the db) + const isBundled = context.bundled.isNameBundled(newPack.content.name); + + if (isBundled.ok && isBundled.content) { + const sso = new context.sso(); + + return sso + .notOk() + .addShort("package_exists") + .addCalls("auth.verifyAuth", user) + .addCalls("vcs.ownership", gitowner) + .addCalls("vcs.newPackageData", newPack) + .addCalls("bundled.isNameBundled", isBundled); + } + // Now with valid package data, we can insert them into the DB const insertedNewPack = await context.database.insertNewPackage( newPack.content