-
-
Notifications
You must be signed in to change notification settings - Fork 406
增加Lsky Pro V2支持 #1325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
增加Lsky Pro V2支持 #1325
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,9 +9,12 @@ class Images | |||||||||
| private $smms_client_id; | ||||||||||
| private $lsky_api_key; | ||||||||||
|
|
||||||||||
| private $lsky_api_version; | ||||||||||
|
|
||||||||||
| public function __construct() { | ||||||||||
| $this->chevereto_api_key = iro_opt('chevereto_api_key'); | ||||||||||
| $this->lsky_api_key = iro_opt('lsky_api_key'); | ||||||||||
| $this->lsky_api_version = iro_opt('lsky_api_version'); | ||||||||||
| $this->imgur_client_id = iro_opt('imgur_client_id'); | ||||||||||
| $this->smms_client_id = iro_opt('smms_client_id'); | ||||||||||
| } | ||||||||||
|
|
@@ -29,6 +32,68 @@ private function getDefaultErrorImage() { | |||||||||
| * LSky Pro upload interface | ||||||||||
| */ | ||||||||||
| public function LSKY_API($image) { | ||||||||||
| if ($this->lsky_api_version == 'v1') { | ||||||||||
| return $this->LSKY_API_V1($image); | ||||||||||
| } else { | ||||||||||
| return $this->LSKY_API_V2($image); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public function LSKY_API_V2($image) { | ||||||||||
| $upload_url = iro_opt('lsky_url') . '/api/v2/upload'; | ||||||||||
| $storage_id = iro_opt('lsky_storage_id'); | ||||||||||
| $filename = $image['cmt_img_file']['name']; | ||||||||||
| $filedata = $image['cmt_img_file']['tmp_name']; | ||||||||||
| $Boundary = wp_generate_password(); | ||||||||||
| $bits = file_get_contents($filedata); | ||||||||||
|
|
||||||||||
| $body = "--$Boundary\r\n"; | ||||||||||
| $body .= "Content-Disposition: form-data; name=\"file\"; filename=\"$filename\"\r\n"; | ||||||||||
| $body .= "Content-Type: " . mime_content_type($filedata) . "\r\n\r\n"; | ||||||||||
| $body .= $bits . "\r\n"; | ||||||||||
| $body .= "--$Boundary\r\n"; | ||||||||||
| $body .= "Content-Disposition: form-data; name=\"storage_id\"\r\n\r\n"; | ||||||||||
| $body .= $storage_id . "\r\n"; | ||||||||||
| $body .= "--$Boundary--\r\n"; | ||||||||||
|
|
||||||||||
| $args = array( | ||||||||||
| 'headers' => array( | ||||||||||
| 'Authorization' => 'Bearer ' . $this->lsky_api_key, | ||||||||||
| 'Accept' => 'application/json', | ||||||||||
| 'Content-Type' => 'multipart/form-data; boundary=' . $Boundary, | ||||||||||
| 'Content-Length'=> strlen($body), | ||||||||||
| ), | ||||||||||
| 'body' => $body | ||||||||||
| ); | ||||||||||
| $response = wp_remote_post($upload_url, $args); | ||||||||||
| $reply = json_decode($response['body']); | ||||||||||
|
|
||||||||||
| if ($reply->status == "success") { | ||||||||||
| $status = 200; | ||||||||||
| $success = true; | ||||||||||
| $message = 'success'; | ||||||||||
| $link = $reply->data->public_url; | ||||||||||
| $proxy = iro_opt('comment_image_proxy') . $link; | ||||||||||
| } else { | ||||||||||
| $status = 400; | ||||||||||
| $success = false; | ||||||||||
| $message = $reply->message; | ||||||||||
| $link = $this->getDefaultErrorImage(); | ||||||||||
| $proxy = iro_opt('comment_image_proxy') . $link; | ||||||||||
| } | ||||||||||
| $output = array( | ||||||||||
| 'status' => $status, | ||||||||||
| 'success' => $success, | ||||||||||
| 'message' => $message, | ||||||||||
| 'link' => $link, | ||||||||||
| 'proxy' => $proxy, | ||||||||||
| ); | ||||||||||
| error_log("LSKY API Response:\n" . print_r($output, true)); | ||||||||||
|
||||||||||
| error_log("LSKY API Response:\n" . print_r($output, true)); | |
| if (defined('WP_DEBUG') && WP_DEBUG) { | |
| error_log("LSKY API Response:\n" . print_r($output, true)); | |
| } |
Copilot
AI
Sep 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Unnecessary blank lines should be removed to maintain consistent code formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Case mismatch in version comparison. The configuration options use uppercase 'V1' and 'V2', but this comparison uses lowercase 'v1'. This will cause V1 API calls to incorrectly route to V2.