mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Implement NextCloud News version detection
- Improves #47 - Still needs wrapping to actually output to clients
This commit is contained in:
parent
20abd277eb
commit
536fa5c4fd
6 changed files with 66 additions and 8 deletions
|
@ -1,11 +1,25 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace JKingWeb\NewsSync\REST\NextCloudNews;
|
||||
use JKingWeb\NewsSync\REST\Response;
|
||||
|
||||
class Versions implements \JKingWeb\NewsSync\REST\Handler {
|
||||
function __construct(\JKingWeb\NewsSync\RuntimeData $data) {
|
||||
}
|
||||
|
||||
function dispatch(\JKingWeb\NewsSync\REST\Request $req): \JKingWeb\NewsSync\REST\Response {
|
||||
$path = $req->url;
|
||||
$query = "";
|
||||
if(strpos($path, "?") !== false) {
|
||||
list($path, $query) = explode("?", $path);
|
||||
}
|
||||
if($req->method != "GET") {
|
||||
return new Response(405);
|
||||
}
|
||||
if(preg_match("<^/?$>",$path)) {
|
||||
return new Response(200, ['v1-2']);
|
||||
} else {
|
||||
return new Response(404);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,17 +3,19 @@ declare(strict_types=1);
|
|||
namespace JKingWeb\NewsSync\REST;
|
||||
|
||||
class Request {
|
||||
public $method;
|
||||
public $url;
|
||||
public $type;
|
||||
public $stream;
|
||||
public $method = "GET";
|
||||
public $url = "";
|
||||
public $type ="";
|
||||
public $stream = "php://input";
|
||||
|
||||
function __construct(string $method = null, string $url = null, string $bodyStream = null, string $contentType = null) {
|
||||
if(is_null($method)) $method = $_SERVER['REQUEST_METHOD'];
|
||||
if(is_null($url)) $url = $_SERVER['REQUEST_URI'];
|
||||
if(is_null($bodyStream)) $bodyStream = "php://input";
|
||||
if(is_null($contentType)) $contentType = $_SERVER['HTTP_CONTENT_TYPE'];
|
||||
$this->method = method;
|
||||
if(is_null($contentType)) {
|
||||
if(isset($_SERVER['HTTP_CONTENT_TYPE'])) $contentType = $_SERVER['HTTP_CONTENT_TYPE'];
|
||||
}
|
||||
$this->method = strtoupper($method);
|
||||
$this->url = $url;
|
||||
$this->stream = $bodyStream;
|
||||
$this->type = $contentType;
|
||||
|
|
|
@ -3,5 +3,20 @@ declare(strict_types=1);
|
|||
namespace JKingWeb\NewsSync\REST;
|
||||
|
||||
class Response {
|
||||
// stub
|
||||
const T_JSON = "application/json";
|
||||
const T_XML = "application/xml";
|
||||
const T_TEXT = "text/plain";
|
||||
|
||||
public $code;
|
||||
public $payload;
|
||||
public $type;
|
||||
public $fields;
|
||||
|
||||
|
||||
function __construct(int $code, $payload = null, string $type = self::T_JSON, array $extraFields = []) {
|
||||
$this->code = $code;
|
||||
$this->payload = $payload;
|
||||
$this->type = $type;
|
||||
$this->fields = $extraFields;
|
||||
}
|
||||
}
|
|
@ -74,7 +74,7 @@ create table newssync_articles(
|
|||
modified datetime not null default CURRENT_TIMESTAMP, -- date when article properties were last modified
|
||||
url_title_hash varchar(64), -- hash of URL + title; used when checking for updates and for identification if there is no guid.
|
||||
url_content_hash varchar(64), -- hash of URL + content, enclosure URL, & content type; used when checking for updates and for identification if there is no guid.
|
||||
title_content_hash varchar(64), -- hash of title + content, enclosure URL, & content type; used when checking for updates and for identification if there is no guid.
|
||||
title_content_hash varchar(64) -- hash of title + content, enclosure URL, & content type; used when checking for updates and for identification if there is no guid.
|
||||
);
|
||||
|
||||
-- enclosures associated with articles
|
||||
|
|
23
tests/REST/NextCloudNews/TestNCNVersionDiscovery.php
Normal file
23
tests/REST/NextCloudNews/TestNCNVersionDiscovery.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace JKingWeb\NewsSync;
|
||||
use JKingWeb\NewsSync\Rest\Request;
|
||||
use JKingWeb\NewsSync\Rest\Response;
|
||||
|
||||
|
||||
class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase {
|
||||
use Test\Tools;
|
||||
|
||||
function setUp() {
|
||||
$conf = new Conf();
|
||||
$this->data = new Test\RuntimeData($conf);
|
||||
}
|
||||
|
||||
function testVersionList() {
|
||||
$exp = new Response(200, ['v1-2']);
|
||||
$req = new Request("GET", "/");
|
||||
$h = new Rest\NextCloudNews\Versions($this->data);
|
||||
$res = $h->dispatch($req);
|
||||
$this->assertEquals($exp, $res);
|
||||
}
|
||||
}
|
|
@ -35,4 +35,8 @@
|
|||
<file>Db/SQLite3/TestDbUpdateSQLite3.php</file>
|
||||
</testsuite>
|
||||
|
||||
<testsuite name="NextCloud News API">
|
||||
<file>REST/NextCloudNews/TestNCNVersionDiscovery.php</file>
|
||||
</testsuite>
|
||||
|
||||
</phpunit>
|
Loading…
Reference in a new issue