diff --git a/lib/Database.php b/lib/Database.php index a69d246..77af92c 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -776,7 +776,9 @@ class Database { * - "updated": The date and time at which the newsfeed was last updated in the database * - "edited": The date and time at which the newsfeed was last modified by its authors * - "modified": The date and time at which the subscription properties were last changed by the user + * - "next_fetch": The date and time and which the feed will next be fetched * - "unread": The number of unread articles associated with the subscription + * - "etag": The ETag header-field in the last fetch response * * @param string $user The user whose subscriptions are to be listed * @param integer|null $folder The identifier of the folder under which to list subscriptions; by default the root folder is used @@ -792,10 +794,11 @@ class Database { "SELECT s.id as id, s.feed as feed, - f.url,source,folder,pinned,err_count,err_msg,order_type,added,keep_rule,block_rule, + f.url,source,folder,pinned,err_count,err_msg,order_type,added,keep_rule,block_rule,f.etag,s.scrape, f.updated as updated, f.modified as edited, s.modified as modified, + f.next_fetch, i.id as icon_id, i.url as icon_url, t.top as top_folder, diff --git a/lib/REST/Miniflux/V1.php b/lib/REST/Miniflux/V1.php index f048e79..c1bc8e5 100644 --- a/lib/REST/Miniflux/V1.php +++ b/lib/REST/Miniflux/V1.php @@ -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)));