diff --git a/README.md b/README.md index e7cc6451..27b3e59d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Website](https://img.shields.io/website?down_message=offline&label=theindex.moe&up_message=online&url=https%3A%2F%2Ftheindex.moe)](https://theindex.moe) -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Snaacky/theindex/Docker?logo=github)](https://github.com/Snaacky/theindex) +[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Snaacky/theindex/publish-docker-image.yml?logo=github)](https://github.com/Snaacky/theindex) [![CodeFactor](https://www.codefactor.io/repository/github/snaacky/theindex/badge)](https://www.codefactor.io/repository/github/snaacky/theindex) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/a91c8d3ec420474cbac1a524073c83ee)](https://www.codacy.com/gh/Snaacky/theindex/dashboard) [![Discord](https://img.shields.io/discord/974468300304171038?label=Discord&logo=discord)](https://discord.gg/snackbox) @@ -94,7 +94,6 @@ Here is a collection of the possible environment variables with their default va | `CACHE_URL` | Connection string for the redis cache database | `"redis://redis:6379"` | | `CHROME_URL` | WebSocket URL to a running chrome instance | `"ws://chrome:3300"` | | `AUDIT_WEBHOOK` | WebHook-URL for audit-log, leave empty to disable support | `""` | -| `SOCKS_PROXY` | Connection string for SOCKS5 proxy to use for pinging | `""` | | `DISCORD_CLIENT_ID` | Discord OAuth2 client ID | `"your_discord_oauth_client_id"` | | `DISCORD_CLIENT_SECRET` | Discord OAuth2 client secret | `"your_discord_oauth_client_secret"` | | `DISCORD_BOT_TOKEN` | Required to access BOT resources | `"your_discord_bot_token"` | @@ -265,7 +264,6 @@ our ideas, and we find some time, we will certainly implement your requested fea - We bake everything into a [docker image](https://www.docker.com/) - Running on [node js](https://nodejs.org/) - User-authentication via [NextAuth.js](https://next-auth.js.org/) -- PWA-support with [next-pwa](https://www.npmjs.com/package/next-pwa) - [mongodb](https://www.mongodb.com) as database backend - [redis](https://redis.io) as cache - [puppeteer](https://github.com/puppeteer/puppeteer) to create screenshots of websites diff --git a/lib/db/users.ts b/lib/db/users.ts index e234a619..ad4aceeb 100644 --- a/lib/db/users.ts +++ b/lib/db/users.ts @@ -19,7 +19,7 @@ export async function userExists(uid: string): Promise { ) } -async function gatherUserInfo(user: User): Promise { +export async function gatherUserInfo(user: User): Promise { if (user === null || typeof user === 'undefined') { console.warn( 'Well... gathering user data of', diff --git a/lib/db/views.ts b/lib/db/views.ts index d74bf1c9..8c97b95a 100644 --- a/lib/db/views.ts +++ b/lib/db/views.ts @@ -55,13 +55,15 @@ export async function getLastViews(type: Types, n: number) { // resolve content info return ( await Promise.all( - sorted.map( - async (s) => - await findOne( - singularToPlural(type), - type === 'user' ? { uid: s.contentId } : { _id: s.contentId } - ) - ) + sorted.map(async (s) => { + const data = await findOne( + singularToPlural(type), + type === Types.user ? { uid: s.contentId } : { _id: s.contentId } + ) + + data.views = s.count + return data + }) ) ).filter((s) => s !== null && typeof s !== 'undefined') } @@ -89,7 +91,7 @@ export async function addView({ uid, type, contentId }) { }) } -export async function deleteView(_id) { +export async function deleteView(_id: string) { return await deleteOne('views', { _id }) } @@ -97,6 +99,6 @@ export async function countViews() { return await count('views') } -export async function countViewsOfContent(type, contentId) { - return await count('users', { type, contentId }) +export async function countViewsOfContent(type: Types, _id: string) { + return await count('views', { type, _id }) } diff --git a/pages/admin.tsx b/pages/admin.tsx index bfadeeda..7f54a45a 100644 --- a/pages/admin.tsx +++ b/pages/admin.tsx @@ -145,6 +145,9 @@ const Admin = ({
{popular.map((item, i) =>
{item.name} +
+ {item.views} Views +
)}
diff --git a/types/User.ts b/types/User.ts index 78aeee35..928e469c 100644 --- a/types/User.ts +++ b/types/User.ts @@ -15,6 +15,7 @@ export enum AccountType { admin = 'admin', editor = 'editor', user = 'user', + views: number } export interface UserUpdate {