Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions inc/classes/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -29,6 +32,68 @@ private function getDefaultErrorImage() {
* LSky Pro upload interface
*/
public function LSKY_API($image) {
if ($this->lsky_api_version == 'v1') {
Copy link

Copilot AI Sep 22, 2025

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.

Suggested change
if ($this->lsky_api_version == 'v1') {
if (strtoupper($this->lsky_api_version) == 'V1') {

Copilot uses AI. Check for mistakes.
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));
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging should not be left in production code. This error_log statement should be removed or wrapped in a debug flag check.

Suggested change
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 uses AI. Check for mistakes.
return $output;


Copy link

Copilot AI Sep 22, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.
}
public function LSKY_API_V1($image) {
$upload_url = iro_opt('lsky_url') . '/api/v1/upload';
$filename = $image['cmt_img_file']['name'];
$filedata = $image['cmt_img_file']['tmp_name'];
Expand Down
23 changes: 22 additions & 1 deletion opt/options/theme-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -3209,11 +3209,32 @@ function iro_validate_optional_url( $value ) {
array(
'id' => 'lsky_api_key',
'type' => 'text',
'title' => __('Lsky Pro v1 Token','sakurairo_csf'),
'title' => __('Lsky Pro Token','sakurairo_csf'),
'dependency' => array( 'img_upload_api', '==', 'lsky', '', 'true' ),
'desc' => __('Fill in the Token here, Please note that there is no "Bearer " at first, to get please visit your Lsky Pro home page address/api','sakurairo_csf'),
),

array(
'id' => 'lsky_api_version',
'type' => 'select',
'title' => __('Lsky Pro API Version','sakurairo_csf'),
'dependency' => array( 'img_upload_api', '==', 'lsky', '', 'true' ),
'desc' => __('Choose the API Version here','sakurairo_csf'),
'options' => array(
'V1' => __('V1','sakurairo_csf'),
'V2' => __('V2','sakurairo_csf'),
),
'default' => 'V1'
),

array(
'id' => 'lsky_storage_id',
'type' => 'text',
'title' => __('Lsky Pro Storage ID','sakurairo_csf'),
'dependency' => array( 'lsky_api_version', '==', 'V2', '', 'true' ),
'desc' => __('Fill in the Storage ID here','sakurairo_csf'),
),

array(
'id' => 'lsky_url',
'type' => 'text',
Expand Down