Skip to content

Commit

Permalink
Ensure the name is reserved, and direct queries return package data
Browse files Browse the repository at this point in the history
  • Loading branch information
confused-Techie committed Feb 3, 2024
1 parent 9ff0fb0 commit a14e556
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bundled_packages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
},

Expand Down
19 changes: 19 additions & 0 deletions src/controllers/getPackagesPackageName.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/controllers/postPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a14e556

Please sign in to comment.