1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Query Miniflux categories

This commit is contained in:
J. King 2020-12-11 13:31:35 -05:00
parent 4b73698381
commit 2e6c5d2ad2
4 changed files with 39 additions and 24 deletions

View file

@ -128,7 +128,7 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
$data = @json_decode((string) $req->getBody(), true); $data = @json_decode((string) $req->getBody(), true);
if (json_last_error() !== \JSON_ERROR_NONE) { if (json_last_error() !== \JSON_ERROR_NONE) {
// if the body could not be parsed as JSON, return "400 Bad Request" // if the body could not be parsed as JSON, return "400 Bad Request"
return new ErrorResponse(["invalidBodyJSON", json_last_error_msg()], 400); return new ErrorResponse(["InvalidBodyJSON", json_last_error_msg()], 400);
} }
$data = $this->normalizeBody((array) $data); $data = $this->normalizeBody((array) $data);
if ($data instanceof ResponseInterface) { if ($data instanceof ResponseInterface) {
@ -215,7 +215,7 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
if (!isset($body[$k])) { if (!isset($body[$k])) {
$body[$k] = null; $body[$k] = null;
} elseif (gettype($body[$k]) !== $t) { } elseif (gettype($body[$k]) !== $t) {
return new ErrorResponse(["invalidInputType", 'field' => $k, 'expected' => $t, 'actual' => gettype($body[$k])]); return new ErrorResponse(["InvalidInputType", 'field' => $k, 'expected' => $t, 'actual' => gettype($body[$k])]);
} }
} }
return $body; return $body;
@ -260,10 +260,10 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
$list = Feed::discoverAll((string) $data['url'], (string) $data['username'], (string) $data['password']); $list = Feed::discoverAll((string) $data['url'], (string) $data['username'], (string) $data['password']);
} catch (FeedException $e) { } catch (FeedException $e) {
$msg = [ $msg = [
10502 => "fetch404", 10502 => "Fetch404",
10506 => "fetch403", 10506 => "Fetch403",
10507 => "fetch401", 10507 => "Fetch401",
][$e->getCode()] ?? "fetchOther"; ][$e->getCode()] ?? "FetchOther";
return new ErrorResponse($msg, 500); return new ErrorResponse($msg, 500);
} }
$out = []; $out = [];
@ -299,6 +299,19 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
return new Response($this->listUsers([Arsse::$user->id], false)[0] ?? new \stdClass); return new Response($this->listUsers([Arsse::$user->id], false)[0] ?? new \stdClass);
} }
protected function getCategories(array $path, array $query, array $data) {
$out = [];
$meta = Arsse::$user->propertiesGet(Arsse::$user->id, false);
// add the root folder as a category
$out[] = ['id' => 1, 'title' => $meta['root_folder_name'] ?? Arsse::$lang->msg("API.Miniflux.DefaultCategoryName"), 'user_id' => $meta['num']];
// add other top folders as categories
foreach (Arsse::$db->folderList(Arsse::$user->id, null, false) as $f) {
// always add 1 to the ID since the root folder will always be 1 instead of 0.
$out[] = ['id' => $f['id'] + 1, 'title' => $f['name'], 'user_id' => $meta['num']];
}
return new Response($out);
}
public static function tokenGenerate(string $user, string $label): string { public static function tokenGenerate(string $user, string $label): string {
// Miniflux produces tokens in base64url alphabet // Miniflux produces tokens in base64url alphabet
$t = str_replace(["+", "/"], ["-", "_"], base64_encode(random_bytes(self::TOKEN_LENGTH))); $t = str_replace(["+", "/"], ["-", "_"], base64_encode(random_bytes(self::TOKEN_LENGTH)));

View file

@ -25,6 +25,7 @@ class User {
'gestures' => V::T_BOOL, 'gestures' => V::T_BOOL,
'stylesheet' => V::T_STRING, 'stylesheet' => V::T_STRING,
'reading_time' => V::T_BOOL, 'reading_time' => V::T_BOOL,
'root_folder_name' => V::T_STRING,
]; ];
public const PROPERTIES_LARGE = ["stylesheet"]; public const PROPERTIES_LARGE = ["stylesheet"];

View file

@ -7,15 +7,16 @@ return [
'CLI.Auth.Success' => 'Authentication successful', 'CLI.Auth.Success' => 'Authentication successful',
'CLI.Auth.Failure' => 'Authentication failed', 'CLI.Auth.Failure' => 'Authentication failed',
'API.Miniflux.DefaultCategoryName' => "All",
'API.Miniflux.Error.401' => 'Access Unauthorized', 'API.Miniflux.Error.401' => 'Access Unauthorized',
'API.Miniflux.Error.403' => 'Access Forbidden', 'API.Miniflux.Error.403' => 'Access Forbidden',
'API.Miniflux.Error.404' => 'Resource Not Found', 'API.Miniflux.Error.404' => 'Resource Not Found',
'API.Miniflux.Error.invalidBodyJSON' => 'Invalid JSON payload: {0}', 'API.Miniflux.Error.InvalidBodyJSON' => 'Invalid JSON payload: {0}',
'API.Miniflux.Error.invalidInputType' => 'Input key "{field}" of type {actual} was expected as {expected}', 'API.Miniflux.Error.InvalidInputType' => 'Input key "{field}" of type {actual} was expected as {expected}',
'API.Miniflux.Error.fetch404' => 'Resource not found (404), this feed doesn\'t exists anymore, check the feed URL', 'API.Miniflux.Error.Fetch404' => 'Resource not found (404), this feed doesn\'t exists anymore, check the feed URL',
'API.Miniflux.Error.fetch401' => 'You are not authorized to access this resource (invalid username/password)', 'API.Miniflux.Error.Fetch401' => 'You are not authorized to access this resource (invalid username/password)',
'API.Miniflux.Error.fetch403' => 'Unable to fetch this resource (Status Code = 403)', 'API.Miniflux.Error.Fetch403' => 'Unable to fetch this resource (Status Code = 403)',
'API.Miniflux.Error.fetchOther' => 'Unable to fetch this resource', 'API.Miniflux.Error.FetchOther' => 'Unable to fetch this resource',
'API.TTRSS.Category.Uncategorized' => 'Uncategorized', 'API.TTRSS.Category.Uncategorized' => 'Uncategorized',
'API.TTRSS.Category.Special' => 'Special', 'API.TTRSS.Category.Special' => 'Special',

View file

@ -163,7 +163,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
} }
public function testRejectBadlyTypedData(): void { public function testRejectBadlyTypedData(): void {
$exp = new ErrorResponse(["invalidInputType", 'field' => "url", 'expected' => "string", 'actual' => "integer"], 400); $exp = new ErrorResponse(["InvalidInputType", 'field' => "url", 'expected' => "string", 'actual' => "integer"], 400);
$this->assertMessage($exp, $this->req("POST", "/discover", ['url' => 2112])); $this->assertMessage($exp, $this->req("POST", "/discover", ['url' => 2112]));
} }
@ -175,7 +175,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
$this->assertMessage($exp, $this->req("POST", "/discover", ['url' => "http://localhost:8000/Feed/Discovery/Valid"])); $this->assertMessage($exp, $this->req("POST", "/discover", ['url' => "http://localhost:8000/Feed/Discovery/Valid"]));
$exp = new Response([]); $exp = new Response([]);
$this->assertMessage($exp, $this->req("POST", "/discover", ['url' => "http://localhost:8000/Feed/Discovery/Invalid"])); $this->assertMessage($exp, $this->req("POST", "/discover", ['url' => "http://localhost:8000/Feed/Discovery/Invalid"]));
$exp = new ErrorResponse("fetch404", 500); $exp = new ErrorResponse("Fetch404", 500);
$this->assertMessage($exp, $this->req("POST", "/discover", ['url' => "http://localhost:8000/Feed/Discovery/Missing"])); $this->assertMessage($exp, $this->req("POST", "/discover", ['url' => "http://localhost:8000/Feed/Discovery/Missing"]));
} }