forked from confused-Techie/atom-backend
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0864d96
commit 2564295
Showing
3 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module.exports = { | ||
docs: { | ||
summary: "List a user's starred packages.", | ||
responses: [ | ||
{ | ||
200: { | ||
description: "Return value is similar to `GET /api/packages`.", | ||
content: {} | ||
} | ||
} | ||
] | ||
}, | ||
endpoint: { | ||
method: "GET", | ||
paths: [ "/api/users/:login/stars" ], | ||
rateLimit: "generic", | ||
successStatus: 200, | ||
options: { | ||
Allow: "GET", | ||
"X-Content-Type-Options": "nosniff" | ||
} | ||
}, | ||
params: { | ||
login: (context, req) => { return context.query.login(req); } | ||
}, | ||
async logic(params, context) { | ||
const user = await context.database.getUserByName(params.login); | ||
|
||
if (!user.ok) { | ||
const sso = new context.sso(); | ||
|
||
return sso.notOk().addContent(user.content) | ||
.addCalls("db.getUserByName", user); | ||
} | ||
|
||
let pointerCollection = await context.database.getStarredPointersByUserID(user.content.id); | ||
|
||
if (!pointerCollection.ok) { | ||
const sso = new context.sso(); | ||
|
||
return sso.notOk().addContent(pointerCollection.content) | ||
.addCalls("db.getUserByName", user) | ||
.addCalls("db.getStarredPointersByUserID", pointerCollection); | ||
} | ||
|
||
// Since even if the pointerCollection is okay, it could be empty. Meaning the user | ||
// has no stars. This is okay, but getPackageCollectionByID will fail, and result | ||
// in a not found when discovering no packages by the ids passed, which is none. | ||
// So we will catch the exception of pointerCollection being an empty array. | ||
|
||
if ( | ||
Array.isArray(pointerCollection.content) && | ||
pointerCollection.content.length === 0 | ||
) { | ||
// Check for array to protect from an unexpected return | ||
const sso = new context.sso(); | ||
|
||
return sso.isOk().addContent([]); | ||
} | ||
|
||
let packageCollection = await context.database.getPackageCollectionByID( | ||
pointerCollection.content | ||
); | ||
|
||
if (!packageCollection.ok) { | ||
const sso = new context.sso(); | ||
|
||
return sso.notOk().addContent(packageCollection.content) | ||
.addCalls("db.getUserByName", user) | ||
.addCalls("db.getStarredPointersByUserID", pointerCollection) | ||
.addCalls("db.getPackageCollectionByID", packageCollection); | ||
} | ||
|
||
packageCollection = await utils.constructPackageObjectShort(packageCollection.content); | ||
|
||
const sso = new context.sso(); | ||
|
||
return sso.isOk().addContent(packageCollection); | ||
} | ||
}; |
38 changes: 38 additions & 0 deletions
38
src/controllers/postPackagesPackageNameVersionsVersionNameEventsUninstall.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module.exports = { | ||
docs: { | ||
summary: "Previously undocumented endpoint. Since v1.0.2 has no effect.", | ||
}, | ||
endpoint: { | ||
method: "POST", | ||
paths: [ | ||
"/api/packages/:packageName/versions/:versionName/events/uninstall", | ||
"/api/themes/:packageName/versions/:versionName/events/uninstall" | ||
], | ||
rateLimit: "auth", | ||
successStatus: 201, | ||
options: { | ||
Allow: "POST", | ||
"X-Content-Type-Options": "nosniff" | ||
} | ||
}, | ||
params: {}, | ||
async logic(params, context) { | ||
/** | ||
Used when a package is uninstalled, decreases the download count by 1. | ||
Originally an undocumented endpoint. | ||
The decision to return a '201' is based on how other POST endpoints return, | ||
during a successful event. | ||
This endpoint has now been deprecated, as it serves no useful features, | ||
and on further examination may have been intended as a way to collect | ||
data on users, which is not something we implement. | ||
* Deprecated since v1.0.2 | ||
* see: https://github.com/atom/apm/blob/master/src/uninstall.coffee | ||
* While decoupling HTTP handling from logic, the function has been removed | ||
entirely: https://github.com/pulsar-edit/package-backend/pull/171 | ||
*/ | ||
|
||
const sso = new context.sso(); | ||
|
||
return sso.isOk().addContent({ ok: true }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters