Skip to content

Commit

Permalink
Added enablecdn QC API
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Zheng committed Sep 26, 2024
1 parent 43344f8 commit 510806c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
34 changes: 34 additions & 0 deletions src/cloud.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Cloud extends Base

const SVC_U_ACTIVATE = 'u/wp3/activate';
const SVC_U_LINK = 'u/wp3/link';
const SVC_U_ENABLE_CDN = 'u/wp3/enablecdn';
const SVC_D_NODES = 'd/nodes';
const SVC_D_SYNC_CONF = 'd/sync_conf';
const SVC_D_USAGE = 'd/usage';
Expand Down Expand Up @@ -95,6 +96,7 @@ class Cloud extends Base
const TYPE_CLEAR_CLOUD = 'clear_cloud';
const TYPE_ACTIVATE = 'activate';
const TYPE_LINK = 'link';
const TYPE_ENABLE_CDN = 'enablecdn';
const TYPE_SYNC_USAGE = 'sync_usage';
const TYPE_RESET = 'reset';

Expand Down Expand Up @@ -198,6 +200,34 @@ public function link_qc()
exit();
}

/**
* Enable QC CDN
*
* @since 7.0
*/
public function enable_cdn()
{
if (!$this->activated()) {
Admin_Display::error(__('You need to activate QC first.', 'litespeed-cache'));
return;
}

$data = array(
'wp_ts' => time(),
);
$data['wp_signature_b64'] = $this->_sign_b64($data['wp_ts']);

// Activation redirect
$param = array(
'site_url' => home_url(),
'ver' => Core::VER,
'data' => $data,
'ref' => get_admin_url(null, 'admin.php?page=litespeed'),
);
wp_redirect(self::CLOUD_SERVER_DASH . '/' . self::SVC_U_ENABLE_CDN . '?data=' . urlencode(Utility::arr2str($param)));
exit();
}

/**
* Encrypt data for cloud req
*
Expand Down Expand Up @@ -1550,6 +1580,10 @@ public function handler()
$this->link_qc();
break;

case self::TYPE_ENABLE_CDN:
$this->enable_cdn();
break;

case self::TYPE_SYNC_USAGE:
$this->sync_usage();

Expand Down
12 changes: 0 additions & 12 deletions tpl/cdn/qc.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@

defined('WPINC') || exit;

$this->form_action();
?>

<h3 class="litespeed-title-short">
<?php echo __('CDN Settings', 'litespeed-cache'); ?>
<?php Doc::learn_more('https://docs.litespeedtech.com/lscache/lscwp/cdn/'); ?>
</h3>

<h2>Here will show info html from QC carry-on.</h2>

<?php
$this->form_end();
?>
<div class="litespeed-dashboard-header">
<h3 class="litespeed-dashboard-title"><?php echo __('QUIC.cloud', 'litespeed-cache'); ?></h3>
Expand Down
7 changes: 6 additions & 1 deletion tpl/dash/dashboard.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,12 @@
<a href="https://www.quic.cloud/quic-cloud-services-and-features/litespeed-cache-service/" class="litespeed-title-right-icon" target="_blank"><?php echo __('Learn More', 'litespeed-cache'); ?></a>
</h3>
<p class="litespeed-top20 litespeed-text-bold litespeed-margin-bottom20">
<a href="https://www.quic.cloud/docs/onboarding/" class="" target="_blank"><?php echo __('Try QUIC.cloud CDN!', 'litespeed-cache'); ?></a>
<?php Doc::learn_more(
Utility::build_url(Router::ACTION_CLOUD, Cloud::TYPE_ENABLE_CDN),
__('Enable QUIC.cloud CDN', 'litespeed-cache'),
true,
'button litespeed-btn-success'
); ?>
</p>
<p class="litespeed-margin-y5">
<?php echo __('Best available WordPress performance', 'litespeed-cache'); ?>
Expand Down

0 comments on commit 510806c

Please sign in to comment.