Sfoglia il codice sorgente

Revert "Support both web and Android sessions"

This reverts commit 661be438ec0363dd3b153854765081707ab2d369.
Zed 1 anno fa
parent
commit
41fa47bfbf
4 ha cambiato i file con 18 aggiunte e 47 eliminazioni
  1. 7 13
      src/apiutils.nim
  2. 9 18
      src/experimental/parser/session.nim
  3. 0 4
      src/experimental/types/session.nim
  4. 2 12
      src/types.nim

+ 7 - 13
src/apiutils.nim

@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: AGPL-3.0-only
-import httpclient, asyncdispatch, options, strformat, strutils, uri, times, math, tables
+import httpclient, asyncdispatch, options, strutils, uri, times, math, tables
 import jsony, packedjson, zippy, oauth1
 import types, auth, consts, parserutils, http_pool
 import experimental/types/common
@@ -28,27 +28,21 @@ proc getOauthHeader(url, oauthToken, oauthTokenSecret: string): string =
 
   return getOauth1RequestHeader(params)["authorization"]
 
-proc genHeaders*(url: string; session: Session): HttpHeaders =
+proc genHeaders*(url, oauthToken, oauthTokenSecret: string): HttpHeaders =
+  let header = getOauthHeader(url, oauthToken, oauthTokenSecret)
+
   result = newHttpHeaders({
     "connection": "keep-alive",
+    "authorization": header,
     "content-type": "application/json",
     "x-twitter-active-user": "yes",
     "authority": "api.x.com",
     "accept-encoding": "gzip",
     "accept-language": "en-US,en;q=0.9",
     "accept": "*/*",
-    "DNT": "1",
+    "DNT": "1"
   })
 
-  case session.kind
-  of oauth:
-    result["authorization"] = getOauthHeader(url, session.oauthToken, session.oauthSecret)
-  of cookie:
-    result["authorization"] = "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
-    result["x-twitter-auth-type"] = "OAuth2Session"
-    result["x-csrf-token"] = session.ct0
-    result["cookie"] = &"ct0={session.ct0}; auth_token={session.authToken}"
-
 template fetchImpl(result, fetchBody) {.dirty.} =
   once:
     pool = HttpPool()
@@ -60,7 +54,7 @@ template fetchImpl(result, fetchBody) {.dirty.} =
 
   try:
     var resp: AsyncResponse
-    pool.use(genHeaders($url, session)):
+    pool.use(genHeaders($url, session.oauthToken, session.oauthSecret)):
       template getContent =
         resp = await c.get($url)
         result = await resp.body

+ 9 - 18
src/experimental/parser/session.nim

@@ -1,24 +1,15 @@
 import std/strutils
 import jsony
 import ../types/session
-from ../../types import Session, SessionKind
+from ../../types import Session
 
 proc parseSession*(raw: string): Session =
-  let session = raw.fromJson(RawSession)
+  let 
+    session = raw.fromJson(RawSession)
+    id = session.oauthToken[0 ..< session.oauthToken.find('-')]
 
-  case session.kind
-  of "oauth":
-    let id = session.oauthToken[0 ..< session.oauthToken.find('-')]
-    result = Session(
-      kind: oauth,
-      id: parseBiggestInt(id),
-      oauthToken: session.oauthToken,
-      oauthSecret: session.oauthTokenSecret
-    )
-  of "cookie":
-    result = Session(
-      kind: cookie,
-      id: 999,
-      ct0: session.ct0,
-      authToken: session.authToken
-    )
+  result = Session(
+    id: parseBiggestInt(id),
+    oauthToken: session.oauthToken,
+    oauthSecret: session.oauthTokenSecret
+  )

+ 0 - 4
src/experimental/types/session.nim

@@ -1,8 +1,4 @@
 type
   RawSession* = object
-    kind*: string
     oauthToken*: string
     oauthTokenSecret*: string
-    ct0*: string
-    authToken*: string
-    

+ 2 - 12
src/types.nim

@@ -31,20 +31,10 @@ type
     remaining*: int
     reset*: int
 
-  SessionKind* = enum
-    oauth
-    cookie
-
   Session* = ref object
-    case kind*: SessionKind
-    of oauth:
-      oauthToken*: string
-      oauthSecret*: string
-    of cookie:
-      ct0*: string
-      authToken*: string
-
     id*: int64
+    oauthToken*: string
+    oauthSecret*: string
     pending*: int
     limited*: bool
     limitedAt*: int