|
@@ -64,6 +64,7 @@
|
|
|
(let ((album-artist (album-artist (track-album track)))
|
|
(let ((album-artist (album-artist (track-album track)))
|
|
|
(track-artist (track-artist track)))
|
|
(track-artist (track-artist track)))
|
|
|
(with-object
|
|
(with-object
|
|
|
|
|
+ (maybe-key-value "id" (track-id track))
|
|
|
(maybe-key-value "artist" track-artist)
|
|
(maybe-key-value "artist" track-artist)
|
|
|
(maybe-key-value "album_artist" (unless (equal track-artist album-artist) album-artist))
|
|
(maybe-key-value "album_artist" (unless (equal track-artist album-artist) album-artist))
|
|
|
(maybe-key-value "album" (album-album (track-album track)))
|
|
(maybe-key-value "album" (album-album (track-album track)))
|
|
@@ -71,7 +72,6 @@
|
|
|
(maybe-key-value "no" (clear-track-no (track-no track)))
|
|
(maybe-key-value "no" (clear-track-no (track-no track)))
|
|
|
(maybe-key-value "title" (track-title track))
|
|
(maybe-key-value "title" (track-title track))
|
|
|
(maybe-key-value "bit_rate" (track-bit-rate track))
|
|
(maybe-key-value "bit_rate" (track-bit-rate track))
|
|
|
- (maybe-key-value "vbr" (if (track-is-vbr track) :true :false))
|
|
|
|
|
(maybe-key-value "duration" (track-duration track))
|
|
(maybe-key-value "duration" (track-duration track))
|
|
|
(maybe-key-value "url" (get-url (track-path track)))
|
|
(maybe-key-value "url" (get-url (track-path track)))
|
|
|
(maybe-key-value "cover" (get-url (album-cover (track-album track)))))))
|
|
(maybe-key-value "cover" (get-url (album-cover (track-album track)))))))
|
|
@@ -261,13 +261,15 @@
|
|
|
:content (trivial-utf-8:string-to-utf-8-bytes (to-json params))))
|
|
:content (trivial-utf-8:string-to-utf-8-bytes (to-json params))))
|
|
|
|
|
|
|
|
(defvar *bot-auth-chat-id* nil "Authentication chat id")
|
|
(defvar *bot-auth-chat-id* nil "Authentication chat id")
|
|
|
|
|
+(defun tg-get-chat-member (user-id &optional (chat-id *bot-auth-chat-id*))
|
|
|
|
|
+ (getf (telegram-request "getChatMember"
|
|
|
|
|
+ `(:|chat_id| ,chat-id :|user_id| ,user-id))
|
|
|
|
|
+ :|result|))
|
|
|
|
|
+
|
|
|
(defparameter +authorized-statuses+ '("creator" "administrator" "member"))
|
|
(defparameter +authorized-statuses+ '("creator" "administrator" "member"))
|
|
|
(defun authorize-user (info)
|
|
(defun authorize-user (info)
|
|
|
(ignore-errors
|
|
(ignore-errors
|
|
|
- (let* ((response (telegram-request "getChatMember"
|
|
|
|
|
- `(:|chat_id| ,*bot-auth-chat-id*
|
|
|
|
|
- :|user_id| ,(getf info :|id|))))
|
|
|
|
|
- (chat-member (getf response :|result|))
|
|
|
|
|
|
|
+ (let* ((chat-member (tg-get-chat-member (getf info :|id|)))
|
|
|
(status (getf chat-member :|status|)))
|
|
(status (getf chat-member :|status|)))
|
|
|
(member status +authorized-statuses+ :test #'equal))))
|
|
(member status +authorized-statuses+ :test #'equal))))
|
|
|
|
|
|
|
@@ -294,11 +296,29 @@
|
|
|
+401+))
|
|
+401+))
|
|
|
(error (e) (log:error e) +400+)))
|
|
(error (e) (log:error e) +400+)))
|
|
|
|
|
|
|
|
-(defun user-info (params)
|
|
|
|
|
|
|
+(defun self-info (params)
|
|
|
(declare #.*standard-optimize-settings* (ignorable params))
|
|
(declare #.*standard-optimize-settings* (ignorable params))
|
|
|
(with-user (info)
|
|
(with-user (info)
|
|
|
(200-json info)))
|
|
(200-json info)))
|
|
|
|
|
|
|
|
|
|
+(defun find-user-info (username)
|
|
|
|
|
+ (first
|
|
|
|
|
+ (sort
|
|
|
|
|
+ (loop for info being the hash-value of (server-token-user *server*)
|
|
|
|
|
+ when (equal username (getf info :|username|))
|
|
|
|
|
+ collect info)
|
|
|
|
|
+ #'< :key (lambda (i) (getf i :|auth_date|)))))
|
|
|
|
|
+
|
|
|
|
|
+(defun user-info (params)
|
|
|
|
|
+ (declare #.*standard-optimize-settings* (ignorable params))
|
|
|
|
|
+ (with-user (info)
|
|
|
|
|
+ (let ((info (find-user-info (getf params :user))))
|
|
|
|
|
+ (if info
|
|
|
|
|
+ (progn
|
|
|
|
|
+ (dolist (ind '(:|hash| :|id| :|auth_date|)) (remf info ind))
|
|
|
|
|
+ (200-json info))
|
|
|
|
|
+ +404+))))
|
|
|
|
|
+
|
|
|
(defvar *mapper* (myway:make-mapper))
|
|
(defvar *mapper* (myway:make-mapper))
|
|
|
(myway:connect *mapper* "/api/cat/:category/size" 'get-category-size)
|
|
(myway:connect *mapper* "/api/cat/:category/size" 'get-category-size)
|
|
|
(myway:connect *mapper* "/api/cat/:category" 'get-category)
|
|
(myway:connect *mapper* "/api/cat/:category" 'get-category)
|
|
@@ -307,7 +327,8 @@
|
|
|
(myway:connect *mapper* "/api/stats" 'stats)
|
|
(myway:connect *mapper* "/api/stats" 'stats)
|
|
|
(myway:connect *mapper* "/api/rescan" 'request-rescan :method :POST)
|
|
(myway:connect *mapper* "/api/rescan" 'request-rescan :method :POST)
|
|
|
(myway:connect *mapper* "/api/login" 'login :method :POST)
|
|
(myway:connect *mapper* "/api/login" 'login :method :POST)
|
|
|
-(myway:connect *mapper* "/api/user" 'user-info)
|
|
|
|
|
|
|
+(myway:connect *mapper* "/api/user" 'self-info)
|
|
|
|
|
+(myway:connect *mapper* "/api/user/:user" 'user-info)
|
|
|
|
|
|
|
|
(defun main (&rest args &key (port 5000) (debug nil) (use-thread t) (serve-files nil) &allow-other-keys)
|
|
(defun main (&rest args &key (port 5000) (debug nil) (use-thread t) (serve-files nil) &allow-other-keys)
|
|
|
;; Load config file
|
|
;; Load config file
|