2023-09-25 15:28:13 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class FreshExtension_kagiSummarizer_Controller extends Minz_ActionController {
|
|
|
|
public function summarizeAction() {
|
2023-09-25 16:25:04 -05:00
|
|
|
$this->view->_layout(false);
|
2023-09-25 16:40:22 -05:00
|
|
|
|
|
|
|
$kagi_token = FreshRSS_Context::$user_conf->kagi_token;
|
|
|
|
|
|
|
|
if ($kagi_token === null || trim($kagi_token) ==='') {
|
|
|
|
echo json_encode(array(
|
|
|
|
'response' => array(
|
|
|
|
'output_text' => 'No Kagi token configured.',
|
|
|
|
'error' => 'configuration'),
|
|
|
|
'status' => 200));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-25 16:25:04 -05:00
|
|
|
$entry_id = Minz_Request::param('id');
|
|
|
|
$entry_dao = FreshRSS_Factory::createEntryDao();
|
|
|
|
$entry = $entry_dao->searchById($entry_id);
|
|
|
|
|
|
|
|
if ($entry === null) {
|
|
|
|
echo json_encode(array('status' => 404));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$entry_link = urlencode($entry->link());
|
|
|
|
$url = 'https://kagi.com/mother/summary_labs?summary_type=summary&url=' . $entry_link;
|
|
|
|
|
|
|
|
$curl = curl_init();
|
|
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
|
|
|
'Content-Type: application/json; charset=UTF-8',
|
2023-09-25 16:40:22 -05:00
|
|
|
'Authorization: ' . $kagi_token
|
2023-09-25 16:25:04 -05:00
|
|
|
));
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($curl, CURLOPT_HEADER, true);
|
|
|
|
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
|
|
|
|
$response_body = substr($response, $header_size);
|
|
|
|
|
2023-09-25 16:26:14 -05:00
|
|
|
echo json_encode(array(
|
2023-09-25 16:25:04 -05:00
|
|
|
'response' => json_decode($response_body),
|
|
|
|
'status' => curl_getinfo($curl, CURLINFO_HTTP_CODE)
|
|
|
|
));
|
2023-09-25 15:28:13 -05:00
|
|
|
}
|
|
|
|
}
|