-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from WaifuAPI/staging
Staging
- Loading branch information
Showing
9 changed files
with
332 additions
and
190 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,33 @@ | ||
import createError from 'http-errors'; | ||
import Stats from '../../../models/schemas/Stat.js'; | ||
|
||
// Get Internal Status or statistics | ||
const getStats = async (req, res, next) => { | ||
const key = req.headers.key; | ||
// Check for valid access key in headers | ||
if (!key || key !== process.env.ACCESS_KEY) { | ||
return res.status(401).json({ | ||
message: 'Unauthorized', | ||
}); | ||
} | ||
try { | ||
const [result] = await Stats.aggregate([ | ||
// Select a random document from the results | ||
{ $sample: { size: 1 } }, | ||
{ $project: { __v: 0, _id: 0 } }, | ||
]); | ||
|
||
if (!result) { | ||
return next(createError(404, 'Could not find any Stats')); | ||
} | ||
|
||
res.status(200).json(result); | ||
|
||
await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { stats: 1 } }); | ||
} catch (error) { | ||
await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); | ||
return next(error); | ||
} | ||
}; | ||
|
||
export { getStats }; |
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
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
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
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
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
Oops, something went wrong.