From 0792542d0115d34b324c297d93aca02a4babfae0 Mon Sep 17 00:00:00 2001 From: Yasamato Date: Sat, 30 Dec 2023 08:36:20 +0100 Subject: [PATCH 1/4] Add missing key --- pages/admin.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/admin.tsx b/pages/admin.tsx index f0e5a2ed..bfadeeda 100644 --- a/pages/admin.tsx +++ b/pages/admin.tsx @@ -143,7 +143,7 @@ const Admin = ({ Items with the most current views in the last 10k item views
- {popular.map((item, i) =>
+ {popular.map((item, i) =>
{item.name}
)}
From f8452dd016f74fb558bb484e8344f15a7bba9726 Mon Sep 17 00:00:00 2001 From: Yasamato Date: Sat, 30 Dec 2023 11:26:07 +0100 Subject: [PATCH 2/4] Adjust readme.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 From d63e504d50eabc436a51fbc3c18ed3f8bd2d2e23 Mon Sep 17 00:00:00 2001 From: Yasamato Date: Sat, 30 Dec 2023 13:10:55 +0100 Subject: [PATCH 3/4] Add view count to popular --- lib/db/users.ts | 2 +- lib/db/views.ts | 22 ++++++++++++---------- types/User.ts | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) 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/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 { From 23975add769c132ca8d7eb0a521565a4a5fcbcd6 Mon Sep 17 00:00:00 2001 From: Yasamato Date: Sat, 30 Dec 2023 13:13:15 +0100 Subject: [PATCH 4/4] Update admin.tsx --- pages/admin.tsx | 3 +++ 1 file changed, 3 insertions(+) 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 +
)}