mirror of
https://github.com/zedeus/nitter.git
synced 2025-04-21 16:34:12 +00:00
feat: list json api (#3)
This commit is contained in:
commit
55d215b197
3 changed files with 26 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -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
16
src/jsons/list.nim
Normal 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
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue