-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorage.php
More file actions
169 lines (146 loc) · 4.54 KB
/
Copy pathStorage.php
File metadata and controls
169 lines (146 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
declare(strict_types=1);
namespace Stack0\Integrations;
use Stack0\Concerns\BuildsQueryParams;
use Stack0\Http\HttpClient;
class Storage
{
use BuildsQueryParams;
public function __construct(
private readonly HttpClient $http,
) {}
// =========================================================================
// Files
// =========================================================================
/**
* List files in a connection, optionally filtered by folder.
*
* @param array{
* connectionId: string,
* folderId?: string,
* cursor?: string,
* limit?: int,
* } $params
* @return array<string, mixed>
*/
public function listFiles(array $params): array
{
$query = $this->buildQuery([
'connectionId' => $params['connectionId'],
'folderId' => $params['folderId'] ?? null,
'cursor' => $params['cursor'] ?? null,
'limit' => $params['limit'] ?? null,
]);
return $this->http->get('/integrations/storage/files' . $query);
}
/**
* Get a single file.
*
* @return array<string, mixed>
*/
public function getFile(string $connectionId, string $id): array
{
$query = $this->buildQuery(['connectionId' => $connectionId]);
return $this->http->get("/integrations/storage/files/{$id}" . $query);
}
/**
* Upload a file.
*
* @param array{
* connectionId: string,
* name: string,
* mimeType: string,
* data: string,
* folderId?: string,
* } $params
* @return array<string, mixed>
*/
public function uploadFile(array $params): array
{
return $this->http->post('/integrations/storage/files', [
'connectionId' => $params['connectionId'],
'name' => $params['name'],
'mimeType' => $params['mimeType'],
'data' => $params['data'],
'folderId' => $params['folderId'] ?? null,
]);
}
/**
* Delete a file.
*
* @return array<string, mixed>
*/
public function deleteFile(string $connectionId, string $id): array
{
$query = $this->buildQuery(['connectionId' => $connectionId]);
return $this->http->delete("/integrations/storage/files/{$id}" . $query);
}
/**
* Download a file (returns base64-encoded data).
*
* @return array{data: string, mimeType: string, filename: string}
*/
public function downloadFile(string $connectionId, string $id): array
{
$query = $this->buildQuery(['connectionId' => $connectionId]);
return $this->http->get("/integrations/storage/files/{$id}/download" . $query);
}
// =========================================================================
// Folders
// =========================================================================
/**
* List folders for a connection, optionally filtered by parent.
*
* @param array{
* connectionId: string,
* parentId?: string,
* cursor?: string,
* limit?: int,
* } $params
* @return array<string, mixed>
*/
public function listFolders(array $params): array
{
$query = $this->buildQuery([
'connectionId' => $params['connectionId'],
'parentId' => $params['parentId'] ?? null,
'cursor' => $params['cursor'] ?? null,
'limit' => $params['limit'] ?? null,
]);
return $this->http->get('/integrations/storage/folders' . $query);
}
/**
* Get a single folder.
*
* @return array<string, mixed>
*/
public function getFolder(string $connectionId, string $id): array
{
$query = $this->buildQuery(['connectionId' => $connectionId]);
return $this->http->get("/integrations/storage/folders/{$id}" . $query);
}
/**
* Create a folder.
*
* @param array{
* connectionId: string,
* name: string,
* parentId?: string,
* } $params
* @return array<string, mixed>
*/
public function createFolder(array $params): array
{
return $this->http->post('/integrations/storage/folders', $params);
}
/**
* Delete a folder.
*
* @return array<string, mixed>
*/
public function deleteFolder(string $connectionId, string $id): array
{
$query = $this->buildQuery(['connectionId' => $connectionId]);
return $this->http->delete("/integrations/storage/folders/{$id}" . $query);
}
}