Skip to content

Commit df3fcf3

Browse files
authored
Update logger, moving from XML payload to json (#352)
* upgrade to nextcloud 31 Signed-off-by: Fabrice Meyer <meyer.fabrice@gmx.fr> * remove useless XMLResponse lib Signed-off-by: Fabrice Meyer <meyer.fabrice@gmx.fr> --------- Signed-off-by: Fabrice Meyer <meyer.fabrice@gmx.fr>
1 parent 971628d commit df3fcf3

5 files changed

Lines changed: 68 additions & 70 deletions

File tree

appinfo/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
['name' => 'CoAuthoring#command', 'url' => '/coauthoring/CommandService.ashx', 'verb' => 'POST'],
1414

15-
['name' => 'Convert#convert', 'url' => '/ConvertService.ashx', 'verb' => 'POST'],
15+
['name' => 'Convert#convert', 'url' => '/converter', 'verb' => 'POST'],
1616

1717
['name' => 'Static#webApps', 'url' => '/web-apps/{path}', 'verb' => 'GET', 'requirements' => ['path' => '.+']],
1818
['name' => 'Static#pluginsJSON', 'url' => '/plugins.json', 'verb' => 'GET'],

lib/Controller/CoAuthoringController.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@
2323

2424
namespace OCA\DocumentServer\Controller;
2525

26+
use OCP\AppFramework\Http\DataResponse;
2627
use OCA\DocumentServer\OnlyOffice\WebVersion;
2728
use OCP\AppFramework\Controller;
29+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
30+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
31+
use OCP\AppFramework\Http\Attribute\PublicPage;
2832

2933
class CoAuthoringController extends Controller {
30-
/**
31-
* @NoAdminRequired
32-
* @NoCSRFRequired
33-
* @PublicPage
34-
*/
34+
#[NoAdminRequired]
35+
#[NoCSRFRequired]
36+
#[PublicPage]
3537
public function command(string $c) {
3638
switch ($c) {
3739
case 'version':
3840
$webVersion = new WebVersion();
39-
40-
return ['version' => $webVersion->getWebUIVersion(), 'error' => 0];
41+
return new DataResponse(['version' => $webVersion->getWebUIVersion(), 'error' => 0]);
4142
default:
4243
return ['error' => 5];
4344
}

lib/Controller/ConvertController.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525

2626
use OCA\DocumentServer\Document\DocumentStore;
2727
use OCA\DocumentServer\OnlyOffice\URLDecoder;
28-
use OCA\DocumentServer\XMLResponse;
28+
use OCA\DocumentServer\JSONResponse;
2929
use OCP\AppFramework\Controller;
30+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
31+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
32+
use OCP\AppFramework\Http\Attribute\PublicPage;
3033
use OCP\IURLGenerator;
3134

3235
class ConvertController extends Controller {
@@ -41,14 +44,12 @@ public function __construct(DocumentStore $documentStore, URLDecoder $urlDecoder
4144
}
4245

4346

44-
/**
45-
* @NoAdminRequired
46-
* @NoCSRFRequired
47-
* @PublicPage
48-
*/
47+
#[NoAdminRequired]
48+
#[NoCSRFRequired]
49+
#[PublicPage]
4950
public function convert(bool $async, string $url, string $outputtype, string $filetype, string $title, string $key) {
5051
if ($outputtype === $filetype) {
51-
return new XMLResponse([
52+
return new JSONResponse([
5253
'FileUrl' => $url,
5354
'Percent' => "100",
5455
'EndConvert' => "True",
@@ -66,7 +67,7 @@ public function convert(bool $async, string $url, string $outputtype, string $fi
6667
]
6768
);
6869

69-
return new XMLResponse([
70+
return new JSONResponse([
7071
'FileUrl' => $url,
7172
'Percent' => "100",
7273
'EndConvert' => "True",

lib/Controller/DocumentController.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
use OCA\DocumentServer\XHRCommand\UnlockDocument;
4141
use OCA\DocumentServer\XHRCommand\OpenDocument;
4242
use OCP\AppFramework\Http\DataResponse;
43+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
44+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
45+
use OCP\AppFramework\Http\Attribute\PublicPage;
4346
use OCP\IRequest;
4447
use OCP\IURLGenerator;
4548
use OCP\Security\ISecureRandom;
@@ -115,20 +118,17 @@ protected function getIdleHandlerClasses(): array {
115118
return self::IDLE_HANDLERS;
116119
}
117120

118-
/**
119-
* @NoAdminRequired
120-
* @NoCSRFRequired
121-
* @PublicPage
122-
*/
121+
#[NoAdminRequired]
122+
#[NoCSRFRequired]
123+
#[PublicPage]
123124
public function healthCheck() {
124-
return true;
125+
return new DataResponse(true);
126+
//return true;
125127
}
126128

127-
/**
128-
* @NoAdminRequired
129-
* @NoCSRFRequired
130-
* @PublicPage
131-
*/
129+
#[NoAdminRequired]
130+
#[NoCSRFRequired]
131+
#[PublicPage]
132132
public function documentFile(int $docId, string $path, ?bool $download) {
133133
$file = $this->documentStore->openDocumentFile($docId, $path);
134134

@@ -146,11 +146,9 @@ public function documentFile(int $docId, string $path, ?bool $download) {
146146
return $response;
147147
}
148148

149-
/**
150-
* @NoAdminRequired
151-
* @NoCSRFRequired
152-
* @PublicPage
153-
*/
149+
#[NoAdminRequired]
150+
#[NoCSRFRequired]
151+
#[PublicPage]
154152
public function upload(int $docId, string $index) {
155153
$content = fopen('php://input', 'r');
156154
$mime = $this->request->getHeader('Content-Type');
@@ -170,11 +168,9 @@ public function upload(int $docId, string $index) {
170168
]);
171169
}
172170

173-
/**
174-
* @NoAdminRequired
175-
* @NoCSRFRequired
176-
* @PublicPage
177-
*/
171+
#[NoAdminRequired]
172+
#[NoCSRFRequired]
173+
#[PublicPage]
178174
public function download(int $docId, string $cmd) {
179175
$cmd = json_decode($cmd, true);
180176
$content = fopen('php://input', 'r');
Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,37 @@
2626
use OC\AppFramework\Http;
2727
use OCP\AppFramework\Http\Response;
2828

29-
class XMLResponse extends Response {
30-
31-
/**
32-
* response data
33-
*
34-
* @var array|object
35-
*/
36-
protected $data;
37-
38-
public function __construct($data = [], $statusCode = Http::STATUS_OK) {
39-
parent::__construct();
40-
41-
$this->data = $data;
42-
$this->setStatus($statusCode);
43-
$this->addHeader('Content-Type', 'application/xml; charset=utf-8');
44-
}
45-
46-
public function render() {
47-
$xml = new \SimpleXMLElement('<root/>');
48-
$data = array_flip($this->data);
49-
array_walk_recursive($data, [$xml, 'addChild']);
50-
return $xml->asXML();
51-
}
52-
53-
public function setData($data) {
54-
$this->data = $data;
55-
56-
return $this;
57-
}
58-
59-
public function getData() {
60-
return $this->data;
61-
}
29+
30+
class JSONResponse extends Response {
31+
32+
/**
33+
* response data
34+
*
35+
* @var array|object
36+
*/
37+
protected $data;
38+
39+
public function __construct($data = [], $statusCode = Http::STATUS_OK) {
40+
parent::__construct();
41+
42+
$this->data = $data;
43+
$this->setStatus($statusCode);
44+
$this->addHeader('Content-Type', 'application/json; charset=utf-8');
45+
}
46+
47+
public function render() {
48+
// Convert the data to JSON format and return it
49+
$data = array_flip($this->data);
50+
return json_encode($this->data);
51+
}
52+
53+
public function setData($data) {
54+
$this->data = $data;
55+
56+
return $this;
57+
}
58+
59+
public function getData() {
60+
return $this->data;
61+
}
6262
}

0 commit comments

Comments
 (0)