-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Fix broken profile images and set default image for users with…
…out profile picture
- Loading branch information
1 parent
c4c74e9
commit 1cbc174
Showing
1 changed file
with
65 additions
and
0 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,65 @@ | ||
// Packages | ||
const User = require("../models/User"); | ||
const chalk = require("chalk"); | ||
|
||
// Load environment variables | ||
require("dotenv").config(); | ||
|
||
// TODO: Fix hardcoded URL | ||
|
||
// Fix broken profile images | ||
const fixBrokenProfileImages = async () => { | ||
// Find all users | ||
const users = await User.find(); | ||
|
||
// Loop through all users | ||
for (const user of users) { | ||
let needsUpdate = false; | ||
|
||
// If the profile image is not found, set it to the default image | ||
if (!user.profilePicture) { | ||
user.profilePicture = | ||
"https://camphouse.vmgware.dev/images/profiles/ProfilePicture.png"; | ||
console.log( | ||
chalk.yellow( | ||
"User profile image has been set to the default image for: " + | ||
user.username | ||
) | ||
); | ||
needsUpdate = true; | ||
} | ||
|
||
// If it doesn't contain storage.vmgware.dev, set it to the default image | ||
if ( | ||
!user.profilePicture.includes("storage.vmgware.dev") && | ||
!user.profilePicture.includes("camphouse.vmgware.dev") | ||
) { | ||
user.profilePicture = | ||
"https://camphouse.vmgware.dev/images/profiles/ProfilePicture.png"; | ||
console.log( | ||
chalk.yellow( | ||
"User profile image has been set to the default image for: " + | ||
user.username | ||
) | ||
); | ||
needsUpdate = true; | ||
} | ||
|
||
if (needsUpdate) { | ||
await User.findByIdAndUpdate(user._id, { profilePicture: user.profilePicture }); | ||
} | ||
} | ||
|
||
console.log(chalk.green("All broken profile images have been fixed")); | ||
}; | ||
|
||
// Begin the server | ||
(async () => { | ||
console.log(chalk.green("Fixing broken profile images...")); | ||
|
||
// Connect to MongoDB | ||
require("../db"); | ||
|
||
await fixBrokenProfileImages(); | ||
process.exit(); | ||
})(); |