Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: shadowban users (#3581)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude authored Jan 18, 2023
1 parent b778902 commit 67d942b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ LINKFREE_MONGO_CONNECTION_STRING="mongodb://mongodb:27017/linkfree"
NEXT_PUBLIC_GA_MEASUREMENT_ID=""
NEXT_PUBLIC_BASE_URL="http://localhost:3000"
NODE_ENV="development"
SHADOWBAN=""
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ LINKFREE_MONGO_CONNECTION_STRING="mongodb://localhost:27017/linkfree"
NEXT_PUBLIC_GA_MEASUREMENT_ID=""
NEXT_PUBLIC_BASE_URL="http://localhost:3000"
NODE_ENV="development"
SHADOWBAN=""
1 change: 1 addition & 0 deletions data/eddiejaoude2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "Eddie Jaoude Test profile",
"displayStatsPublic": true,
"type": "personal",
"bio": "This is my profile where I test stuff",
"avatar": "https://github.com/eddiejaoude2.png",
Expand Down
6 changes: 5 additions & 1 deletion pages/api/discover/popular.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export default async function handler(req, res) {

let popularProfiles = [];
try {
popularProfiles = await Profile.find({}).sort({ views: -1 }).limit(20);
popularProfiles = await Profile.find({
username: { $nin: process.env.SHADOWBAN.split(",") },
})
.sort({ views: -1 })
.limit(20);
} catch (e) {
logger.error(e, "failed to load profiles");
}
Expand Down
5 changes: 4 additions & 1 deletion pages/api/discover/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export default async function handler(req, res) {

let randomProfiles = [];
try {
randomProfiles = await Profile.aggregate([{ $sample: { size: 5 } }]);
randomProfiles = await Profile.aggregate([
{ $sample: { size: 5 } },
{ $match: { username: { $nin: process.env.SHADOWBAN.split(",") } } },
]);
} catch (e) {
logger.error(e, "failed to load profiles");
}
Expand Down
1 change: 1 addition & 0 deletions pages/api/discover/trending.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default async function handler(req, res) {
date: {
$gte: new Date(new Date().setDate(new Date().getDate() - 1)),
},
username: { $nin: process.env.SHADOWBAN.split(",") },
},
},
{
Expand Down

0 comments on commit 67d942b

Please sign in to comment.