Compare commits
3 Commits
efcc4a14b6
...
3e9a3d0769
Author | SHA1 | Date | |
---|---|---|---|
3e9a3d0769 | |||
c5464fe992 | |||
2960bbfd61 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
*.db
|
*.db
|
||||||
uploads
|
uploads
|
||||||
merged_source_files.txt
|
merged_source_files.txt
|
||||||
|
__pycache__
|
||||||
|
95
main.py
95
main.py
@ -24,7 +24,7 @@ app.add_middleware(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Database setup
|
# Database setup
|
||||||
DB_PATH = "devrant_community.db"
|
DB_PATH = "rant_community.db"
|
||||||
UPLOAD_DIR = Path("uploads")
|
UPLOAD_DIR = Path("uploads")
|
||||||
UPLOAD_DIR.mkdir(exist_ok=True)
|
UPLOAD_DIR.mkdir(exist_ok=True)
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ def hash_password(password: str) -> str:
|
|||||||
def generate_token() -> str:
|
def generate_token() -> str:
|
||||||
return secrets.token_urlsafe(32)
|
return secrets.token_urlsafe(32)
|
||||||
|
|
||||||
async def get_current_user(token_id: Optional[int] = Form(None),
|
async def DELETE_get_current_user(token_id: Optional[int] = Form(None),
|
||||||
token_key: Optional[str] = Form(None),
|
token_key: Optional[str] = Form(None),
|
||||||
user_id: Optional[int] = Form(None)):
|
user_id: Optional[int] = Form(None)):
|
||||||
if not all([token_id, token_key, user_id]):
|
if not all([token_id, token_key, user_id]):
|
||||||
@ -318,7 +318,7 @@ async def login(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@app.get("/api/devrant/rants")
|
@app.get("/api/rant/rants")
|
||||||
async def get_rants(
|
async def get_rants(
|
||||||
sort: str = "recent",
|
sort: str = "recent",
|
||||||
limit: int = 20,
|
limit: int = 20,
|
||||||
@ -328,7 +328,7 @@ async def get_rants(
|
|||||||
token_key: Optional[str] = None,
|
token_key: Optional[str] = None,
|
||||||
user_id: Optional[int] = None
|
user_id: Optional[int] = None
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id) if token_id else None
|
current_user_id = await authenticate_user(token_id, token_key, user_id) if token_id else None
|
||||||
|
|
||||||
# Get rants with user info
|
# Get rants with user info
|
||||||
order_by = "r.created_time DESC" if sort == "recent" else "r.score DESC"
|
order_by = "r.created_time DESC" if sort == "recent" else "r.score DESC"
|
||||||
@ -384,7 +384,7 @@ async def get_rants(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@app.get("/api/devrant/rants/{rant_id}")
|
@app.get("/api/rant/rants/{rant_id}")
|
||||||
async def get_rant(
|
async def get_rant(
|
||||||
rant_id: int,
|
rant_id: int,
|
||||||
app: int = 3,
|
app: int = 3,
|
||||||
@ -393,7 +393,7 @@ async def get_rant(
|
|||||||
token_key: Optional[str] = None,
|
token_key: Optional[str] = None,
|
||||||
user_id: Optional[int] = None
|
user_id: Optional[int] = None
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id) if token_id else None
|
current_user_id = await authenticate_user(token_id, token_key, user_id) if token_id else None
|
||||||
|
|
||||||
# Get rant with user info
|
# Get rant with user info
|
||||||
rant_row = await db.query_one(
|
rant_row = await db.query_one(
|
||||||
@ -474,7 +474,7 @@ async def get_rant(
|
|||||||
"subscribed": subscribed
|
"subscribed": subscribed
|
||||||
}
|
}
|
||||||
|
|
||||||
@app.post("/api/devrant/rants")
|
@app.post("/api/rant/rants")
|
||||||
async def create_rant(
|
async def create_rant(
|
||||||
rant: str = Form(...),
|
rant: str = Form(...),
|
||||||
tags: str = Form(...),
|
tags: str = Form(...),
|
||||||
@ -485,7 +485,7 @@ async def create_rant(
|
|||||||
user_id: int = Form(...),
|
user_id: int = Form(...),
|
||||||
image: Optional[UploadFile] = File(None)
|
image: Optional[UploadFile] = File(None)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ async def create_rant(
|
|||||||
if duplicate:
|
if duplicate:
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"error": "It looks like you just posted this same rant! Your connection might have timed out while posting so you might have seen an error, but sometimes the rant still gets posted and in this case it seems it did, so please check :) If this was not the case please contact info@devrant.io. Thanks!"
|
"error": "It looks like you just posted this same rant! Your connection might have timed out while posting so you might have seen an error, but sometimes the rant still gets posted and in this case it seems it did, so please check :) If this was not the case please contact info@rant.io. Thanks!"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Handle image upload
|
# Handle image upload
|
||||||
@ -529,7 +529,7 @@ async def create_rant(
|
|||||||
|
|
||||||
return {"success": True, "rant_id": rant_id}
|
return {"success": True, "rant_id": rant_id}
|
||||||
|
|
||||||
@app.post("/api/devrant/rants/{rant_id}")
|
@app.post("/api/rant/rants/{rant_id}")
|
||||||
async def update_rant(
|
async def update_rant(
|
||||||
rant_id: int,
|
rant_id: int,
|
||||||
rant: str = Form(...),
|
rant: str = Form(...),
|
||||||
@ -539,7 +539,7 @@ async def update_rant(
|
|||||||
token_key: str = Form(...),
|
token_key: str = Form(...),
|
||||||
user_id: int = Form(...)
|
user_id: int = Form(...)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -560,7 +560,7 @@ async def update_rant(
|
|||||||
|
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
@app.delete("/api/devrant/rants/{rant_id}")
|
@app.delete("/api/rant/rants/{rant_id}")
|
||||||
async def delete_rant(
|
async def delete_rant(
|
||||||
rant_id: int,
|
rant_id: int,
|
||||||
app: int = 3,
|
app: int = 3,
|
||||||
@ -568,7 +568,7 @@ async def delete_rant(
|
|||||||
token_key: str = None,
|
token_key: str = None,
|
||||||
user_id: int = None
|
user_id: int = None
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -589,7 +589,7 @@ async def delete_rant(
|
|||||||
|
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
@app.post("/api/devrant/rants/{rant_id}/vote")
|
@app.post("/api/rant/rants/{rant_id}/vote")
|
||||||
async def vote_rant(
|
async def vote_rant(
|
||||||
rant_id: int,
|
rant_id: int,
|
||||||
vote: int = Form(...),
|
vote: int = Form(...),
|
||||||
@ -599,7 +599,7 @@ async def vote_rant(
|
|||||||
token_key: str = Form(...),
|
token_key: str = Form(...),
|
||||||
user_id: int = Form(...)
|
user_id: int = Form(...)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -688,7 +688,7 @@ async def vote_rant(
|
|||||||
"rant": await format_rant(rant_data, user_data, current_user_id)
|
"rant": await format_rant(rant_data, user_data, current_user_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@app.post("/api/devrant/rants/{rant_id}/favorite")
|
@app.post("/api/rant/rants/{rant_id}/favorite")
|
||||||
async def favorite_rant(
|
async def favorite_rant(
|
||||||
rant_id: int,
|
rant_id: int,
|
||||||
app: int = Form(3),
|
app: int = Form(3),
|
||||||
@ -696,7 +696,7 @@ async def favorite_rant(
|
|||||||
token_key: str = Form(...),
|
token_key: str = Form(...),
|
||||||
user_id: int = Form(...)
|
user_id: int = Form(...)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -709,7 +709,7 @@ async def favorite_rant(
|
|||||||
except Exception:
|
except Exception:
|
||||||
return {"success": False, "error": "Already favorited"}
|
return {"success": False, "error": "Already favorited"}
|
||||||
|
|
||||||
@app.post("/api/devrant/rants/{rant_id}/unfavorite")
|
@app.post("/api/rant/rants/{rant_id}/unfavorite")
|
||||||
async def unfavorite_rant(
|
async def unfavorite_rant(
|
||||||
rant_id: int,
|
rant_id: int,
|
||||||
app: int = Form(3),
|
app: int = Form(3),
|
||||||
@ -717,7 +717,7 @@ async def unfavorite_rant(
|
|||||||
token_key: str = Form(...),
|
token_key: str = Form(...),
|
||||||
user_id: int = Form(...)
|
user_id: int = Form(...)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -728,7 +728,7 @@ async def unfavorite_rant(
|
|||||||
|
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
@app.post("/api/devrant/rants/{rant_id}/comments")
|
@app.post("/api/rant/rants/{rant_id}/comments")
|
||||||
async def create_comment(
|
async def create_comment(
|
||||||
rant_id: int,
|
rant_id: int,
|
||||||
comment: str = Form(...),
|
comment: str = Form(...),
|
||||||
@ -738,7 +738,7 @@ async def create_comment(
|
|||||||
user_id: int = Form(...),
|
user_id: int = Form(...),
|
||||||
image: Optional[UploadFile] = File(None)
|
image: Optional[UploadFile] = File(None)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "confirmed": False}
|
return {"success": False, "confirmed": False}
|
||||||
|
|
||||||
@ -792,7 +792,7 @@ async def get_comment(
|
|||||||
token_key: Optional[str] = None,
|
token_key: Optional[str] = None,
|
||||||
user_id: Optional[int] = None
|
user_id: Optional[int] = None
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id) if token_id else None
|
current_user_id = await authenticate_user(token_id, token_key, user_id) if token_id else None
|
||||||
|
|
||||||
row = await db.query_one(
|
row = await db.query_one(
|
||||||
"""SELECT c.*, u.id as user_id, u.username, u.score as user_score,
|
"""SELECT c.*, u.id as user_id, u.username, u.score as user_score,
|
||||||
@ -835,7 +835,7 @@ async def update_comment(
|
|||||||
token_key: str = Form(...),
|
token_key: str = Form(...),
|
||||||
user_id: int = Form(...)
|
user_id: int = Form(...)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -864,7 +864,7 @@ async def delete_comment(
|
|||||||
token_key: str = None,
|
token_key: str = None,
|
||||||
user_id: int = None
|
user_id: int = None
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -893,7 +893,7 @@ async def vote_comment(
|
|||||||
token_key: str = Form(...),
|
token_key: str = Form(...),
|
||||||
user_id: int = Form(...)
|
user_id: int = Form(...)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -952,7 +952,7 @@ async def get_profile(
|
|||||||
token_key: Optional[str] = None,
|
token_key: Optional[str] = None,
|
||||||
auth_user_id: Optional[int] = None
|
auth_user_id: Optional[int] = None
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, auth_user_id) if token_id else None
|
current_user_id = await authenticate_user(token_id, token_key, auth_user_id) if token_id else None
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
user = await db.get("users", {"id": user_id})
|
user = await db.get("users", {"id": user_id})
|
||||||
@ -1097,7 +1097,7 @@ async def get_user_id(
|
|||||||
|
|
||||||
return {"success": True, "user_id": user['id']}
|
return {"success": True, "user_id": user['id']}
|
||||||
|
|
||||||
@app.get("/api/devrant/search")
|
@app.get("/api/rant/search")
|
||||||
async def search(
|
async def search(
|
||||||
term: str,
|
term: str,
|
||||||
app: int = 3,
|
app: int = 3,
|
||||||
@ -1105,7 +1105,7 @@ async def search(
|
|||||||
token_key: Optional[str] = None,
|
token_key: Optional[str] = None,
|
||||||
user_id: Optional[int] = None
|
user_id: Optional[int] = None
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id) if token_id else None
|
current_user_id = await authenticate_user(token_id, token_key, user_id) if token_id else None
|
||||||
|
|
||||||
# Search rants
|
# Search rants
|
||||||
rows = await db.query_raw(
|
rows = await db.query_raw(
|
||||||
@ -1148,11 +1148,12 @@ async def get_notifications(
|
|||||||
ext_prof: int = 1,
|
ext_prof: int = 1,
|
||||||
last_time: Optional[int] = None,
|
last_time: Optional[int] = None,
|
||||||
app: int = 3,
|
app: int = 3,
|
||||||
token_id: int = None,
|
token_id: Optional[int] = None,
|
||||||
token_key: str = None,
|
token_key: Optional[str] = None,
|
||||||
user_id: int = None
|
user_id: Optional[int] = None
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
# Use the generic authenticate_user function
|
||||||
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -1185,7 +1186,8 @@ async def get_notifications(
|
|||||||
if not row['read']:
|
if not row['read']:
|
||||||
unread_count += 1
|
unread_count += 1
|
||||||
|
|
||||||
# Mark as read
|
# Mark notifications as read
|
||||||
|
if rows: # Only update if there are notifications
|
||||||
await db.update("notifications", {"read": 1}, {"user_id": current_user_id})
|
await db.update("notifications", {"read": 1}, {"user_id": current_user_id})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -1206,6 +1208,25 @@ async def get_notifications(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async def authenticate_user(token_id: Optional[int] = None,
|
||||||
|
token_key: Optional[str] = None,
|
||||||
|
user_id: Optional[int] = None):
|
||||||
|
"""Generic authentication function that works with any parameter source"""
|
||||||
|
if not all([token_id, token_key, user_id]):
|
||||||
|
return None
|
||||||
|
|
||||||
|
token = await db.get("auth_tokens", {
|
||||||
|
"id": token_id,
|
||||||
|
"token_key": token_key,
|
||||||
|
"user_id": user_id
|
||||||
|
})
|
||||||
|
|
||||||
|
if not token or token['expire_time'] <= int(datetime.now().timestamp()):
|
||||||
|
return None
|
||||||
|
|
||||||
|
return user_id
|
||||||
|
|
||||||
|
|
||||||
@app.delete("/api/users/me/notif-feed")
|
@app.delete("/api/users/me/notif-feed")
|
||||||
async def clear_notifications(
|
async def clear_notifications(
|
||||||
app: int = Form(3),
|
app: int = Form(3),
|
||||||
@ -1213,7 +1234,7 @@ async def clear_notifications(
|
|||||||
token_key: str = Form(...),
|
token_key: str = Form(...),
|
||||||
user_id: int = Form(...)
|
user_id: int = Form(...)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -1233,7 +1254,7 @@ async def edit_profile(
|
|||||||
token_key: str = Form(...),
|
token_key: str = Form(...),
|
||||||
user_id: int = Form(...)
|
user_id: int = Form(...)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -1262,7 +1283,7 @@ async def resend_confirmation(
|
|||||||
token_key: str = Form(...),
|
token_key: str = Form(...),
|
||||||
user_id: int = Form(...)
|
user_id: int = Form(...)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
@ -1277,7 +1298,7 @@ async def mark_news_read(
|
|||||||
token_key: str = Form(...),
|
token_key: str = Form(...),
|
||||||
user_id: int = Form(...)
|
user_id: int = Form(...)
|
||||||
):
|
):
|
||||||
current_user_id = await get_current_user(token_id, token_key, user_id)
|
current_user_id = await authenticate_user(token_id, token_key, user_id)
|
||||||
if not current_user_id:
|
if not current_user_id:
|
||||||
return {"success": False, "error": "Authentication required"}
|
return {"success": False, "error": "Authentication required"}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>DevRant Community</title>
|
<title>Rant Community</title>
|
||||||
<style>
|
<style>
|
||||||
* {
|
* {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@ -555,7 +555,7 @@
|
|||||||
<!-- Navigation -->
|
<!-- Navigation -->
|
||||||
<nav>
|
<nav>
|
||||||
<div class="nav-container">
|
<div class="nav-container">
|
||||||
<a href="#" class="logo" onclick="showFeed()">DevRant</a>
|
<a href="#" class="logo" onclick="showFeed()">Rant</a>
|
||||||
<div class="nav-links">
|
<div class="nav-links">
|
||||||
<a href="#" onclick="showFeed()">Feed</a>
|
<a href="#" onclick="showFeed()">Feed</a>
|
||||||
<a href="#" onclick="showSearch()">Search</a>
|
<a href="#" onclick="showSearch()">Search</a>
|
||||||
@ -636,8 +636,9 @@
|
|||||||
document.getElementById('createRantBtn').style.display = isLoggedIn ? 'flex' : 'none';
|
document.getElementById('createRantBtn').style.display = isLoggedIn ? 'flex' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function apiCall(endpoint, options = {}) {
|
|
||||||
const url = `${API_URL}${endpoint}`;
|
async function apiCall(endpoint, options = {}) {
|
||||||
|
let url = `${API_URL}${endpoint}`;
|
||||||
|
|
||||||
// Add auth to FormData or URLSearchParams if logged in
|
// Add auth to FormData or URLSearchParams if logged in
|
||||||
if (currentUser && options.body) {
|
if (currentUser && options.body) {
|
||||||
@ -657,7 +658,7 @@
|
|||||||
// Add auth to query params for GET requests
|
// Add auth to query params for GET requests
|
||||||
if (currentUser && (options.method === 'GET' || !options.method)) {
|
if (currentUser && (options.method === 'GET' || !options.method)) {
|
||||||
const separator = endpoint.includes('?') ? '&' : '?';
|
const separator = endpoint.includes('?') ? '&' : '?';
|
||||||
endpoint += `${separator}app=${APP_ID}&token_id=${currentUser.token_id}&token_key=${currentUser.token_key}&user_id=${currentUser.id}`;
|
url += `${separator}app=${APP_ID}&token_id=${currentUser.token_id}&token_key=${currentUser.token_key}&user_id=${currentUser.id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -668,7 +669,8 @@
|
|||||||
console.error('API Error:', error);
|
console.error('API Error:', error);
|
||||||
return { success: false, error: error.message };
|
return { success: false, error: error.message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// View functions
|
// View functions
|
||||||
async function showFeed(sort = 'recent') {
|
async function showFeed(sort = 'recent') {
|
||||||
@ -689,7 +691,7 @@
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const params = new URLSearchParams({ sort, limit: 50, skip: 0, app: APP_ID });
|
const params = new URLSearchParams({ sort, limit: 50, skip: 0, app: APP_ID });
|
||||||
const data = await apiCall(`/devrant/rants?${params}`);
|
const data = await apiCall(`/rant/rants?${params}`);
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
content.innerHTML = `
|
content.innerHTML = `
|
||||||
@ -751,7 +753,7 @@
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const params = new URLSearchParams({ app: APP_ID });
|
const params = new URLSearchParams({ app: APP_ID });
|
||||||
const data = await apiCall(`/devrant/rants/${rantId}?${params}`);
|
const data = await apiCall(`/rant/rants/${rantId}?${params}`);
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
const rant = data.rant;
|
const rant = data.rant;
|
||||||
@ -970,7 +972,7 @@
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const params = new URLSearchParams({ term, app: APP_ID });
|
const params = new URLSearchParams({ term, app: APP_ID });
|
||||||
const data = await apiCall(`/devrant/search?${params}`);
|
const data = await apiCall(`/rant/search?${params}`);
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
if (data.results.length === 0) {
|
if (data.results.length === 0) {
|
||||||
@ -981,7 +983,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function showNotifications() {
|
async function showNotifications() {
|
||||||
currentView = 'notifications';
|
currentView = 'notifications';
|
||||||
|
|
||||||
const content = document.getElementById('content');
|
const content = document.getElementById('content');
|
||||||
@ -994,9 +996,9 @@
|
|||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
ext_prof: 1,
|
ext_prof: 1,
|
||||||
last_time: Math.floor(Date.now() / 1000) - 86400,
|
last_time: Math.floor(Date.now() / 1000) - 86400
|
||||||
app: APP_ID
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await apiCall(`/users/me/notif-feed?${params}`);
|
const data = await apiCall(`/users/me/notif-feed?${params}`);
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
@ -1006,7 +1008,7 @@
|
|||||||
<h2>Notifications</h2>
|
<h2>Notifications</h2>
|
||||||
${items.length === 0 ? '<p style="text-align: center; color: var(--text-dim); margin-top: 2rem;">No notifications</p>' : ''}
|
${items.length === 0 ? '<p style="text-align: center; color: var(--text-dim); margin-top: 2rem;">No notifications</p>' : ''}
|
||||||
${items.map(notif => `
|
${items.map(notif => `
|
||||||
<div class="rant-card" onclick="showRant(${notif.rant_id})">
|
<div class="rant-card" onclick="showRant(${notif.rant_id})" style="cursor: pointer;">
|
||||||
<p><strong>${notif.username}</strong> ${notif.type === 'comment' ? 'commented on your rant' : 'mentioned you'}</p>
|
<p><strong>${notif.username}</strong> ${notif.type === 'comment' ? 'commented on your rant' : 'mentioned you'}</p>
|
||||||
<p style="color: var(--text-dim); font-size: 0.9rem;">${formatTime(notif.created_time)}</p>
|
<p style="color: var(--text-dim); font-size: 0.9rem;">${formatTime(notif.created_time)}</p>
|
||||||
</div>
|
</div>
|
||||||
@ -1015,23 +1017,32 @@
|
|||||||
|
|
||||||
// Update notification count
|
// Update notification count
|
||||||
updateNotificationCount(0);
|
updateNotificationCount(0);
|
||||||
|
} else {
|
||||||
|
content.innerHTML = `
|
||||||
|
<h2>Notifications</h2>
|
||||||
|
<p style="text-align: center; color: var(--error); margin-top: 2rem;">Failed to load notifications: ${data.error || 'Unknown error'}</p>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkNotifications() {
|
|
||||||
|
|
||||||
|
|
||||||
|
async function checkNotifications() {
|
||||||
if (!currentUser) return;
|
if (!currentUser) return;
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
ext_prof: 1,
|
ext_prof: 1,
|
||||||
last_time: Math.floor(Date.now() / 1000) - 86400,
|
last_time: Math.floor(Date.now() / 1000) - 86400
|
||||||
app: APP_ID
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await apiCall(`/users/me/notif-feed?${params}`);
|
const data = await apiCall(`/users/me/notif-feed?${params}`);
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
updateNotificationCount(data.data.num_unread);
|
updateNotificationCount(data.data.num_unread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function updateNotificationCount(count) {
|
function updateNotificationCount(count) {
|
||||||
const notifCount = document.getElementById('notifCount');
|
const notifCount = document.getElementById('notifCount');
|
||||||
@ -1219,7 +1230,7 @@
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const formData = new FormData(event.target);
|
const formData = new FormData(event.target);
|
||||||
|
|
||||||
const data = await apiCall('/devrant/rants', {
|
const data = await apiCall('/rant/rants', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
@ -1244,7 +1255,7 @@
|
|||||||
formData.append('reason', 0); // Not for me
|
formData.append('reason', 0); // Not for me
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await apiCall(`/devrant/rants/${rantId}/vote`, {
|
const data = await apiCall(`/rant/rants/${rantId}/vote`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
@ -1289,7 +1300,7 @@
|
|||||||
const endpoint = isFavorited ? 'unfavorite' : 'favorite';
|
const endpoint = isFavorited ? 'unfavorite' : 'favorite';
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
const data = await apiCall(`/devrant/rants/${rantId}/${endpoint}`, {
|
const data = await apiCall(`/rant/rants/${rantId}/${endpoint}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
@ -1303,7 +1314,7 @@
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const formData = new FormData(event.target);
|
const formData = new FormData(event.target);
|
||||||
|
|
||||||
const data = await apiCall(`/devrant/rants/${rantId}/comments`, {
|
const data = await apiCall(`/rant/rants/${rantId}/comments`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
@ -1322,7 +1333,7 @@
|
|||||||
params.append('token_key', currentUser.token_key);
|
params.append('token_key', currentUser.token_key);
|
||||||
params.append('user_id', currentUser.id);
|
params.append('user_id', currentUser.id);
|
||||||
|
|
||||||
const data = await apiCall(`/devrant/rants/${rantId}?${params}`, {
|
const data = await apiCall(`/rant/rants/${rantId}?${params}`, {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user