Skip to content

Commit

Permalink
users need to have more data in their content listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Dec 20, 2024
1 parent da84389 commit 2902473
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
3 changes: 1 addition & 2 deletions frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import socket
from collections import defaultdict
from datetime import datetime
from os import remove as remove_path
from secrets import token_hex
from typing import Iterable

Expand Down Expand Up @@ -229,7 +228,7 @@ def dashboard():
@app.route("/content/list")
@login_required
def content_list():
assets = [a.to_dict() for a in get_user_assets()]
assets = [a.to_dict(user_data=True) for a in get_user_assets()]
random.shuffle(assets)
resp = jsonify(assets=assets)
resp.headers["Cache-Control"] = "no-cache"
Expand Down
33 changes: 20 additions & 13 deletions util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,32 @@ class Asset(NamedTuple):
moderate_url: Optional[str] = None
moderated_by: Optional[str] = None

def to_dict(self, mod_data=False):
return {
"id": self.id,
"user": self.user,
"filetype": self.filetype,
"thumb": self.thumb,
"url": url_for("static", filename=cached_asset_name(self)),
} | (
def to_dict(self, user_data=False, mod_data=False):
return (
{
"moderate_url": url_for(
"content_moderate", asset_id=self.id, _external=True
),
"moderated_by": self.moderated_by,
"id": self.id,
"user": self.user,
"filetype": self.filetype,
"thumb": self.thumb,
"url": url_for("static", filename=cached_asset_name(self)),
}
| {
"state": self.state,
"starts": self.starts,
"ends": self.ends,
}
if mod_data
if user_data or mod_data
else {}
| (
{
"moderate_url": url_for(
"content_moderate", asset_id=self.id, _external=True
),
"moderated_by": self.moderated_by,
}
if mod_data
else {}
)
)


Expand Down

0 comments on commit 2902473

Please sign in to comment.