1+ <?php
2+ namespace OpenApi \classes ;
3+ class Uploader extends OpenApiBase {
4+
5+ /**
6+ * @param string $token Il token da utilizzare per il collegamento
7+ * @param array $scopes Array con la lista degli scope per cui il token è abilitato
8+ * @param object $cache Classe che gestisce la cahce, deve essere una classe che estende {@see OpenApi\clasess\utility\DummyCache} o comunque compatibile con essa (stessi metodi)
9+ */
10+ function __construct (string $ token , array $ scopes , object $ cache , string $ prefix ){
11+ parent ::__construct ($ token , $ scopes , $ cache , $ prefix );
12+ $ this ->basePath = "https://uploader.altravia.com " ;
13+ }
14+
15+ function newCollection (){
16+
17+ return new \OpenApi \classes \utility \Uploader \Collection ([$ this , 'connect ' ]);
18+ }
19+
20+ function gateway (){
21+
22+ $ endpoint = isset ($ _GET ['endpoint ' ])?$ _GET ['endpoint ' ]:null ;
23+ if ($ endpoint == NULL ){
24+ throw new \OpenApi \classes \exception \OpenApiUploaderException ("No endpoint GET " ,40018 );
25+ }
26+
27+ $ method = $ _SERVER ['REQUEST_METHOD ' ];
28+ $ data = null ;
29+ if ($ method != "GET " && $ method != "DELETE " ){
30+ $ data = file_get_contents ("php://input " );
31+ $ data = json_decode ($ data );
32+ }
33+ $ data = $ this ->connect ($ endpoint , $ method ,$ data );
34+ header ("Content-Type: " ,$ this ->parsedHEader ['Content-Type ' ]);
35+ if (isset ($ this ->parsedHEader ['Content-Type ' ]) && strtolower ($ this ->parsedHEader ['Content-Type ' ]) == "application/json " ) {
36+ echo json_encode ($ data );
37+ }else {
38+ echo $ data ;
39+ }
40+ }
41+
42+ function createCollection ($ outputFormat , $ outputSize = null , $ inputTypes = null , $ inputCount = null , $ public = null , $ watermark = null , $ watermarkPosition = NULL , $ expireTimestamp = null ) {
43+ $ collection = new \OpenApi \classes \utility \Uploader \Collection ([$ this , 'connect ' ]);
44+ $ collection ->setOutput ($ outputFormat );
45+ $ collection ->setOutputSize ($ outputSize );
46+ $ collection ->setInputTypes ($ inputTypes );
47+ $ collection ->setInputCount ($ inputCount );
48+ $ collection ->setPublic ($ public );
49+ $ collection ->setWaterMark ($ watermark );
50+ $ collection ->setWaterMarkPosition ($ watermarkPosition );
51+ $ collection ->setExpireTimestamp ($ expireTimestamp );
52+ $ collection ->save ();
53+ }
54+
55+ function getCollectionById ($ id ){
56+ $ coll = $ this ->connect ("collections/ $ id " ,"GET " );
57+ $ collection = new \OpenApi \classes \utility \Uploader \Collection ([$ this , 'connect ' ]);
58+ if (isset ($ coll ->data )){
59+ $ collection ->parseData ($ coll ->data );
60+ return $ collection ;
61+ }
62+ return null ;
63+ }
64+
65+ function deleteCollectionById ($ id ){
66+ return $ this ->connect ("collections/ $ id " ,"DELETE " );
67+ }
68+
69+ function getCollections (){
70+ $ collections = $ this ->connect ("collections " ,"GET " );
71+ foreach ($ collections ->data as $ d ){
72+ $ d ->id =$ d ->_id ->{'$oid ' };
73+ unset($ d ->_id );
74+ }
75+ return $ collections ;
76+ }
77+
78+ }
0 commit comments