File tree Expand file tree Collapse file tree 6 files changed +44
-7
lines changed
Expand file tree Collapse file tree 6 files changed +44
-7
lines changed Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 33namespace JSONms \Controllers ;
44
55use JSONms \Utils \ErrorHandler ;
6+ use JSONms \Utils \Composer ;
67
78class 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 ]);
Original file line number Diff line number Diff 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 ([
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 55class 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 }
You can’t perform that action at this time.
0 commit comments