feat: added following system using cookies
This commit is contained in:
23
src/routes/follow.nim
Normal file
23
src/routes/follow.nim
Normal file
@@ -0,0 +1,23 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import strutils, sequtils, uri
|
||||
import jester
|
||||
import router_utils
|
||||
import ".."/[types]
|
||||
|
||||
proc createFollowRouter*(cfg: Config) =
|
||||
router follow:
|
||||
post "/follow":
|
||||
let user = @"user"
|
||||
var prefs = cookiePrefs()
|
||||
if user.len > 0 and user notin prefs.following:
|
||||
prefs.following.add(user)
|
||||
setCookie("nitter_following", prefs.following.join(","), daysForward(360), path="/", httpOnly=true, secure=cfg.useHttps, sameSite=None)
|
||||
redirect(refPath())
|
||||
|
||||
post "/unfollow":
|
||||
let user = @"user"
|
||||
var prefs = cookiePrefs()
|
||||
if user.len > 0 and user in prefs.following:
|
||||
prefs.following.keepItIf(it != user)
|
||||
setCookie("nitter_following", prefs.following.join(","), daysForward(360), path="/", httpOnly=true, secure=cfg.useHttps, sameSite=None)
|
||||
redirect(refPath())
|
||||
Reference in New Issue
Block a user