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

Commit

Permalink
preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
tnix100 authored Nov 29, 2024
1 parent 2da0e3e commit c991169
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
15 changes: 12 additions & 3 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@
("quote", pymongo.TEXT)
], name="search", partialFilterExpression={"pswd": {"$type": "string"}})
except: pass
"""
try: db.usersv0.create_index([
("delete_after", pymongo.ASCENDING)
], name="scheduled_deletions", partialFilterExpression={"delete_after": {"$type": "number"}})
except: pass
"""

# Create authenticators indexes
try: db.authenticators.create_index([("user", pymongo.ASCENDING)], name="user")
Expand All @@ -68,17 +70,20 @@
try: db.relationships.create_index([("_id.from", pymongo.ASCENDING)], name="from")
except: pass

# Create netinfo indexes
"""
try: db.netinfo.create_index([("last_refreshed", pymongo.ASCENDING)], name="last_refreshed")
except: pass
"""

# Create netlog indexes
try: db.netlog.create_index([("_id.ip", pymongo.ASCENDING)], name="ip")
except: pass
try: db.netlog.create_index([("_id.user", pymongo.ASCENDING)], name="user")
except: pass
"""
try: db.netlog.create_index([("last_used", pymongo.ASCENDING)], name="last_used")
except: pass
"""

# Create posts indexes
try:
Expand All @@ -100,13 +105,13 @@
("p", pymongo.TEXT)
], name="search", partialFilterExpression={"post_origin": "home", "isDeleted": False})
except: pass

"""
try:
db.posts.create_index([
("deleted_at", pymongo.ASCENDING)
], name="scheduled_purges", partialFilterExpression={"isDeleted": True, "mod_deleted": False})
except: pass

"""
try:
db.posts.create_index([
("post_origin", pymongo.ASCENDING),
Expand All @@ -115,6 +120,7 @@
], name="pinned_posts", partialFilterExpression={"pinned": True})
except: pass

"""
# Create post revisions indexes
try:
db.post_revisions.create_index([
Expand All @@ -127,6 +133,7 @@
("time", pymongo.ASCENDING)
], name="scheduled_purges")
except: pass
"""

# Create chats indexes
try:
Expand Down Expand Up @@ -165,13 +172,15 @@
], name="all_reports")
except: pass

"""
# Create audit log indexes
try:
db.audit_log.create_index([
("time", pymongo.ASCENDING),
("type", pymongo.ASCENDING)
], name="scheduled_purges")
except: pass
"""

# Create post reactions index
try:
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from cloudlink import CloudlinkServer
from supporter import Supporter
from security import background_tasks_loop
#from security import background_tasks_loop
from rest_api import app as rest_api


Expand All @@ -23,7 +23,7 @@
cl.supporter = supporter

# Start background tasks loop
Thread(target=background_tasks_loop, daemon=True).start()
#Thread(target=background_tasks_loop, daemon=True).start()

# Initialise REST API
rest_api.cl = cl
Expand Down
7 changes: 5 additions & 2 deletions rest_api/v0/me.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,20 @@ async def delete_account(data: DeleteAccountBody):
if not security.check_password_hash(data.password, account["pswd"]):
security.ratelimit(f"login:u:{request.user}", 5, 60)
return {"error": True, "type": "invalidCredentials"}, 401

# Schedule account for deletion
db.usersv0.update_one({"_id": request.user}, {"$set": {
"tokens": [],
"delete_after": int(time.time())+604800 # 7 days
"delete_after": int(time.time())
}})

# Disconnect clients
for client in app.cl.usernames.get(request.user, []):
client.kick()

# Delete account
security.delete_account(request.user)

return {"error": False}, 200


Expand Down
2 changes: 2 additions & 0 deletions rest_api/v0/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ async def update_post(query_args: PostIdQueryArgs, data: PostBody):
abort(400)

# Add revision
"""
db.post_revisions.insert_one({
"_id": str(uuid.uuid4()),
"post_id": post["_id"],
"old_content": post["p"],
"new_content": data.content,
"time": int(time.time())
})
"""

# Update post
post["edited_at"] = int(time.time())
Expand Down

0 comments on commit c991169

Please sign in to comment.