Skip to content

Commit 6162cb7

Browse files
Merge pull request #7 from JSON-ms/dev
merge dev into master
2 parents eb6751e + 97a9342 commit 6162cb7

File tree

6 files changed

+44
-7
lines changed

6 files changed

+44
-7
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.9",
2+
"version": "1.0.13",
33
"name": "jsonms/php",
44
"description": "A JSON.ms requests handler to install on your own server.",
55
"type": "library",

src/Controllers/DataController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace JSONms\Controllers;
44

55
use JSONms\Utils\ErrorHandler;
6+
use JSONms\Utils\Composer;
67

78
class DataController extends BaseController {
89

@@ -26,14 +27,14 @@ public function getAction(string $hash): void {
2627
"uploadMaxSize" => ini_get('upload_max_filesize'),
2728
"postMaxSize" => ini_get('post_max_size'),
2829
'publicUrl' => $this->publicUrl,
29-
'version' => 1,
30-
'features' => [
30+
'version' => Composer::getVersion(),
31+
'supportedFeatures' => [
3132
'data/get',
3233
'data/update',
33-
'data/history',
34-
'file/index',
34+
'file/list',
3535
'file/read',
3636
'file/upload',
37+
'file/delete',
3738
],
3839
],
3940
]);

src/Controllers/FileController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function uploadAction(string $hash) {
9595
$meta = [
9696
'size' => $fileSize,
9797
'type' => $fileType,
98+
'timestamp' => time(),
9899
'originalFileName' => $fileName,
99100
];
100101

@@ -139,7 +140,6 @@ public function uploadAction(string $hash) {
139140
});
140141
file_put_contents($fileListPath, json_encode(array_values($fileList)));
141142

142-
143143
// Return response
144144
http_response_code(200);
145145
echo json_encode([

src/Controllers/TestController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace JSONms\Controllers;
4+
5+
class TestController extends BaseController {
6+
7+
public function tryAction(): void {
8+
http_response_code(200);
9+
echo json_encode(true);
10+
exit;
11+
}
12+
}

src/Utils/Composer.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace JSONms\Utils;
4+
5+
class Composer {
6+
7+
public static function getVersion() {
8+
9+
$ds = DIRECTORY_SEPARATOR;
10+
$filePath = realpath(dirname(__FILE__) . $ds . '..' . $ds . '..' . $ds . 'composer.json');
11+
12+
if (!file_exists($filePath)) {
13+
return null;
14+
}
15+
16+
$jsonContent = file_get_contents($filePath);
17+
$composerData = json_decode($jsonContent, true);
18+
if (json_last_error() !== JSON_ERROR_NONE) {
19+
throw new Exception("Error decoding JSON: " . json_last_error_msg());
20+
}
21+
22+
return isset($composerData['version']) ? $composerData['version'] : null;
23+
}
24+
}

src/Utils/ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class ErrorHandler {
66

77
public static function throwError($code, $body) {
8-
http_response_code($code || 500);
8+
http_response_code($code ?? 500);
99
echo json_encode(['body' => $body]);
1010
exit;
1111
}

0 commit comments

Comments
 (0)