|
|
@ -22,6 +22,7 @@ use Psr\Http\Message\ServerRequestInterface; |
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
|
|
use Laminas\Diactoros\Response\EmptyResponse; |
|
|
|
use Laminas\Diactoros\Response\JsonResponse as Response; |
|
|
|
use Laminas\Diactoros\Uri; |
|
|
|
|
|
|
|
class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { |
|
|
|
public const VERSION = "2.0.26"; |
|
|
@ -590,6 +591,52 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { |
|
|
|
return new EmptyResponse(204); |
|
|
|
} |
|
|
|
|
|
|
|
protected function getFeeds(): ResponseInterface { |
|
|
|
$meta = Arsse::$user->propertiesGet(Arsse::$user->id, false); |
|
|
|
$tr = Arsse::$db->begin(); |
|
|
|
$out = []; |
|
|
|
// compile the list of folders; the feed list includes folder names |
|
|
|
$folders = [0 => ['id' => 1, 'title' => $meta['root_folder_name'] ?? Arsse::$lang->msg("API.Miniflux.DefaultCategoryName"), 'user_id' => $meta['num']]]; |
|
|
|
foreach(Arsse::$db->folderList(Arsse::$user->id, null, false) as $r) { |
|
|
|
$folders[(int) $r['id']] = [ |
|
|
|
'id' => ((int) $r['id']) + 1, |
|
|
|
'title' => $r['name'], |
|
|
|
'user_id' => $meta['num'], |
|
|
|
]; |
|
|
|
} |
|
|
|
// next compile the list of feeds |
|
|
|
foreach (Arsse::$db->subscriptionList(Arsse::$user->id) as $r) { |
|
|
|
$url = new Uri($r['url']); |
|
|
|
$out = [ |
|
|
|
'id' => (int) $r['id'], |
|
|
|
'user_id' => $meta['num'], |
|
|
|
'feed_url' => $url->withUserInfo(""), |
|
|
|
'site_url' => $r['source'], |
|
|
|
'title' => $r['title'], |
|
|
|
'checked_at' => Date::transform($r['updated'], "iso8601", "sql"), |
|
|
|
'next_check_at' => Date::transform($r['next_fetch'], "iso8601", "sql") ?? "0001-01-01T00:00:00Z", |
|
|
|
'etag_header' => $r['etag'] ?? "", |
|
|
|
'last_modified_header' => (string) Date::transform($r['edited'], "http", "sql"), |
|
|
|
'parsing_error_message' => (string) $r['err_msg'], |
|
|
|
'parsing_error_count' => (int) $r['err_count'], |
|
|
|
'scraper_rules' => "", |
|
|
|
'rewrite_rules' => "", |
|
|
|
'crawler' => (bool) $r['scrape'], |
|
|
|
'blocklist_rules' => (string) $r['block_rule'], |
|
|
|
'keeplist_rules' => (string) $r['keep_rule'], |
|
|
|
'user_agent' => "", |
|
|
|
'username' => explode(":", $url->getUserInfo(), 2)[0] ?? "", |
|
|
|
'password' => explode(":", $url->getUserInfo(), 2)[1] ?? "", |
|
|
|
'disabled' => false, |
|
|
|
'ignore_http_cache' => false, |
|
|
|
'fetch_via_proxy' => false, |
|
|
|
'category' => $folders[$r['top_folder']], |
|
|
|
'icon' => $r['icon_id'] ? ['feed_id' => (int) $r['id'], 'icon_id' => (int) $r['icon_id']] : null, |
|
|
|
]; |
|
|
|
return new Response($out); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static function tokenGenerate(string $user, string $label): string { |
|
|
|
// Miniflux produces tokens in base64url alphabet |
|
|
|
$t = str_replace(["+", "/"], ["-", "_"], base64_encode(random_bytes(self::TOKEN_LENGTH))); |
|
|
|