Skip to content

Commit

Permalink
util: throw error when cookie file is not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
xhcoding committed Jul 31, 2023
1 parent 2c7fc19 commit 19f95af
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions aichat-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,24 @@ Returns stdout on success, otherwise returns nil."

(defun aichat-get-cookies-from-file (filename)
"Get cookies from FILENAME."
(when (file-exists-p filename)
(let ((cookies (aichat-json-parse-file filename)))
(mapcar (lambda (cookie)
(let ((name (alist-get 'name cookie))
(value (alist-get 'value cookie))
(expires (if (assq 'expirationDate cookie)
(format-time-string "%FT%T%z"
(seconds-to-time
(alist-get 'expirationDate cookie)))
nil))
(domain (alist-get 'domain cookie))
(localpart (alist-get 'path cookie))
(secure (if (eq (alist-get 'secure cookie) :json-false)
nil
t)))
(list name value expires domain localpart secure)))
cookies))))
(if (file-exists-p filename)
(let ((cookies (aichat-json-parse-file filename)))
(mapcar (lambda (cookie)
(let ((name (alist-get 'name cookie))
(value (alist-get 'value cookie))
(expires (if (assq 'expirationDate cookie)
(format-time-string "%FT%T%z"
(seconds-to-time
(alist-get 'expirationDate cookie)))
nil))
(domain (alist-get 'domain cookie))
(localpart (alist-get 'path cookie))
(secure (if (eq (alist-get 'secure cookie) :json-false)
nil
t)))
(list name value expires domain localpart secure)))
cookies))
(error "%s not exists" filename)))

(defun aichat--make-get-cookies-command(domain browser-name)
"Make shell command with `domain' and `browser-name'."
Expand Down

0 comments on commit 19f95af

Please sign in to comment.