1
0
Fork 0
mirror of https://github.com/zedeus/nitter.git synced 2025-04-21 16:34:12 +00:00

feat: list json api ()

This commit is contained in:
guanbinrui 2025-04-01 20:48:40 +08:00 committed by GitHub
commit 55d215b197
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 1 deletions

1
.gitignore vendored
View file

@ -10,6 +10,7 @@ nitter
/public/css/style.css
/public/md/*.html
/tools/venv
/nimbledeps
nitter.conf
guest_accounts.json*
sessions.json*

16
src/jsons/list.nim Normal file
View file

@ -0,0 +1,16 @@
# SPDX-License-Identifier: AGPL-3.0-only
import json
import renderutils
import ".."/[types]
proc getListJson*(list: List): JsonNode =
result = %*{
"id": list.id,
"name": list.name,
"userId": list.userId,
"username": list.username,
"description": list.description,
"members": list.members,
"banner": list.banner
}

View file

@ -1,5 +1,6 @@
# SPDX-License-Identifier: AGPL-3.0-only
import asyncdispatch
import json
import jester
@ -10,4 +11,11 @@ proc createJsonApiRouter*(cfg: Config) =
get "/hello":
cond cfg.enableJsonApi
let headers = {"Content-Type": "application/json; charset=utf-8"}
resp Http200, headers, """{"message": "Hello, world"}"""
resp Http200, headers, """{"message": "Hello, world"}"""
get "/i/lists/@id/json":
cond cfg.enableJsonApi
let list = await getCachedList(id=(@"id"))
if list.id.len == 0:
resp Http404, showError(&"""List "{@"id"}" not found""", cfg)
resp Http200, headers, $getListJson(list)