Delete profiles and posts

This commit is contained in:
aeroreyna
2022-02-16 20:33:20 -08:00
parent 294cacf963
commit 117bc5833a
5 changed files with 63 additions and 2 deletions

View File

@@ -16,6 +16,12 @@ DB.getDB.then((DB)=>{
return DB.ObjectID(req.cookies.profile_id || req.query.profile_id || req.body.profile_id);
}
const profileBelongsToUser = async (profileid, userid) => {
const profile = await DB.getProfileCache(profileid);
if(!profile) return false;
return profile.userid == (userid + '');
}
router.get("/mine", async (req, res) => {
let userid = req.cookies.user_sid;
let profiles = await DB.getUserProfiles(userid);
@@ -239,6 +245,19 @@ DB.getDB.then((DB)=>{
});
});
router.delete("/:id", async (req, res) => {
const profileId = req.params.id;
const userid = getUserId(req);
if(!await profileBelongsToUser(profileId, userid))
return res.json({
status: "This profile is not yours."
});
await DB.removeProfile(profileId);
return res.json({
status: "ok"
});
});
router.get("/:id/follow", async (req, res) => {
let followProfileId = req.params.id;
const profileid = getProfileId(req);