From 9c5bd70b8962cc613e131bdef24224289e568fab Mon Sep 17 00:00:00 2001 From: Trevor Arjeski Date: Fri, 11 Oct 2024 15:00:59 +0300 Subject: [PATCH] add local session cookie config Added the ability to specify the leetcode session cookie manually instead of needing the my_cookies python utility. --- leetcode.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/leetcode.el b/leetcode.el index 7c55c6e..8a84d46 100644 --- a/leetcode.el +++ b/leetcode.el @@ -79,7 +79,8 @@ (defun leetcode--check-deps () "Check if all dependencies installed." - (if (executable-find "my_cookies") + (if (or (executable-find "my_cookies") + leetcode-session-cookie) t (leetcode--install-my-cookie) nil)) @@ -122,6 +123,11 @@ mysql, mssql, oraclesql." :group 'leetcode :type 'boolean) +(defcustom leetcode-session-cookie nil + "Leetcode session cookie." + :group 'leetcode + :type 'string) + (cl-defstruct leetcode-user "A LeetCode User. The object with following attributes: @@ -376,6 +382,11 @@ query consolePanelConfig($titleSlug: String!) { VALUE should be the referer." (cons "Referer" value)) +(defun leetcode--local-cookie-get () + "Gets locally set session cookie." + (when-let ((my-cookie leetcode-session-cookie)) + `((,leetcode--cookie-session ,my-cookie)))) + (defun leetcode--cookie-get-all () "Get leetcode session with `my_cookies'. You can install it with pip." (let* ((my-cookies (executable-find "my_cookies")) @@ -703,7 +714,8 @@ submission status." "We are not login actually, we are retrieving LeetCode login session from local browser. It also cleans LeetCode cookies in `url-cookie-file'." (ignore-errors (url-cookie-delete-cookies leetcode--domain)) - (let* ((leetcode-cookie (leetcode--cookie-get-all))) + (let* ((leetcode-cookie (or (leetcode--local-cookie-get) + (leetcode--cookie-get-all)))) (cl-loop for (key value) in leetcode-cookie do (url-cookie-store key value nil leetcode--domain "/" t))) ;; After login, we should have our user data already.