123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package routes
- import (
- "errors"
- "fmt"
- "net/http"
- "codeberg.org/vnpower/pixivfe/v2/core"
- "codeberg.org/vnpower/pixivfe/v2/session"
- "codeberg.org/vnpower/pixivfe/v2/utils"
- )
- func AddBookmarkRoute(w http.ResponseWriter, r *http.Request) error {
- token := session.GetPixivToken(r)
- csrf := session.GetCookie(r, session.Cookie_CSRF)
- if token == "" || csrf == "" {
- return PromptUserToLoginPage(w, r)
- }
- id := GetPathVar(r, "id")
- if id == "" {
- return errors.New("No ID provided.")
- }
- URL := "https://www.pixiv.net/ajax/illusts/bookmarks/add"
- payload := fmt.Sprintf(`{
- "illust_id": "%s",
- "restrict": 0,
- "comment": "",
- "tags": []
- }`, id)
- if err := core.API_POST(r.Context(), URL, payload, token, csrf, true); err != nil {
- return err
- }
- utils.RedirectToWhenceYouCame(w, r)
- return nil
- }
- func DeleteBookmarkRoute(w http.ResponseWriter, r *http.Request) error {
- token := session.GetPixivToken(r)
- csrf := session.GetCookie(r, session.Cookie_CSRF)
- if token == "" || csrf == "" {
- return PromptUserToLoginPage(w, r)
- }
- id := GetPathVar(r, "id")
- if id == "" {
- return errors.New("No ID provided.")
- }
- // You can't unlike
- URL := "https://www.pixiv.net/ajax/illusts/bookmarks/delete"
- payload := fmt.Sprintf(`bookmark_id=%s`, id)
- if err := core.API_POST(r.Context(), URL, payload, token, csrf, false); err != nil {
- return err
- }
- utils.RedirectToWhenceYouCame(w, r)
- return nil
- }
- func LikeRoute(w http.ResponseWriter, r *http.Request) error {
- token := session.GetPixivToken(r)
- csrf := session.GetCookie(r, session.Cookie_CSRF)
- if token == "" || csrf == "" {
- return PromptUserToLoginPage(w, r)
- }
- id := GetPathVar(r, "id")
- if id == "" {
- return errors.New("No ID provided.")
- }
- URL := "https://www.pixiv.net/ajax/illusts/like"
- payload := fmt.Sprintf(`{"illust_id": "%s"}`, id)
- if err := core.API_POST(r.Context(), URL, payload, token, csrf, true); err != nil {
- return err
- }
- utils.RedirectToWhenceYouCame(w, r)
- return nil
- }
|