Skip to content

Commit

Permalink
feat(api): add thumbnail endpoint and ACAO/M (#3)
Browse files Browse the repository at this point in the history
* feat(api): add thumbnail endpoint and ACAO/M

* test(thumbnail): add test code for thumbnail

* test: not found thumbnail

* test: not status

Co-authored-by: Ryu juheon <[email protected]>
  • Loading branch information
hyriph and SaidBySolo authored Nov 24, 2021
1 parent 4f84a27 commit 11714e4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ def download_list(req_handler: "RequestHandler") -> Any:

return req_handler.ok({"list": datas})

@app.post("/thumbnail")
def download_list(req_handler: "RequestHandler", userdata: Dict[str, Any]) -> Any:
items_all = [ui.listWidget.item(i) for i in range(ui.listWidget.count())]
for item in items_all[::-1]:
cw = item
if not cw._lazy:
cw.updateLazy()
if not cw.alive or getattr(cw, "pc", None) is not None:
continue
data = item.serialize(dumps=False, compat=True)
if (userdata.get('uid') == data['uid']):
return req_handler.ok({"data": data})
else:
req_handler.not_found()

@app.post("/valid_url")
def valied_url(req: "RequestHandler", data: Dict[str, Any]):
Expand Down Expand Up @@ -260,6 +274,12 @@ def do_POST(self):
self.send_response(500, "Internal Server Error")
self.set_response({"error": "internal_server_error"})

def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET')
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
return super(RequestHandler, self).end_headers()


def entrypoint():
"""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_thumbnail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from requests.sessions import Session


def test_thumbnail(client: Session):
r = client.get("http://localhost:6009/thumbnail")
assert r.json() == {"error": "not_found"}
assert r.status_code == 404

0 comments on commit 11714e4

Please sign in to comment.