Page MenuHomePhorge

D5136.1775255077.diff
No OneTemporary

Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None

D5136.1775255077.diff

diff --git a/lib/drivers/kolabfiles/kolabfiles_file_storage.php b/lib/drivers/kolabfiles/kolabfiles_file_storage.php
--- a/lib/drivers/kolabfiles/kolabfiles_file_storage.php
+++ b/lib/drivers/kolabfiles/kolabfiles_file_storage.php
@@ -1,4 +1,5 @@
<?php
+
/*
+--------------------------------------------------------------------------+
| This file is part of the Kolab File API |
@@ -18,7 +19,7 @@
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
- | Author: Christian Mollekopf <mollekopf@apheleia-it.ch> |
+ | Author: Christian Mollekopf <mollekopf@apheleia-it.ch> |
+--------------------------------------------------------------------------+
*/
@@ -136,7 +137,7 @@
private function refreshClientAccessToken()
{
- //TODO use the refresh token if available instead of refreshing from scratch always.
+ // TODO use the refresh token if available instead of refreshing from scratch always.
rcube::write_log('kolabfiles', "Refreshing the access token");
$username = $_SESSION['username'];
$password = $this->rc->decrypt($_SESSION['password']);
@@ -149,10 +150,11 @@
'timeout' => 10,
]);
- $response = $client->request('POST', "auth/login?email=$username&password=" . urlencode($password));
+ $response = $client->request('POST', 'auth/login', ['json' => ['email' => $username, 'password' => $password]]);
if ($response->getStatusCode() != 200) {
- throw new Exception("Failed to authenticate $username:$password");
+ throw new Exception("Failed to authenticate $username");
}
+
$json = json_decode($response->getBody(), true);
$accessToken = $json['access_token'];
$_SESSION['access_token'] = $this->rc->encrypt($accessToken);
@@ -350,7 +352,7 @@
$data = $file['content'];
}
- $response = $this->client->request("POST", "v4/fs?name=$fn&parent=$repo_id", ['body' => $data]);
+ $response = $this->client->request('POST', 'v4/fs', ['query' => ['name' => $fn, 'parent' => $repo_id], 'body' => $data]);
$created = $response->getStatusCode() == 200;
if (!$created) {
@@ -390,7 +392,7 @@
$data = $file['content'];
}
- $response = $this->client->request("PATCH", "v4/fs/$file_id?media=content", ['body' => $data]);
+ $response = $this->client->request('PATCH', "v4/fs/{$file_id}", ['query' => ['media' => 'content'], 'body' => $data]);
if ($response->getStatusCode() != 200) {
rcube::raise_error(array(
@@ -450,7 +452,7 @@
// write to file pointer, send no headers
if ($fp) {
- $response = $this->client->request("GET", "v4/fs/{$file_id}?download=1");
+ $response = $this->client->request("GET", "v4/fs/{$file_id}", ['query' => ['download' => 1]]);
fwrite(fp, $request->getBody());
return;
@@ -493,13 +495,13 @@
// e.g. previewing images is not possible
// - pdf/odf viewers can't follow redirects for some reason (#4590)
if ($allow_redirects && !empty($params['force-download'])) {
- $response = $this->client->request("GET", "v4/fs/{$file_id}?downloadUrl=1");
+ $response = $this->client->request("GET", "v4/fs/{$file_id}", ['query' => ['downloadUrl' => 1]]);
$json = json_decode($response->getBody(), true);
$link = $json['downloadUrl'];
header("Location: $link");
}
else if ($fp = fopen('php://output', 'wb')) {
- $response = $this->client->request("GET", "v4/fs/{$file_id}?download=1");
+ $response = $this->client->request("GET", "v4/fs/{$file_id}", ['query' => ['download' => 1]]);
fwrite($fp, $response->getBody());
fclose($fp);
}
@@ -568,7 +570,7 @@
}
}
- $response = $this->client()->request('GET', "v4/fs?parent={$repo_id}&type=file");
+ $response = $this->client()->request('GET', 'v4/fs', ['query' => ['parent' => $repo_id, 'type' => 'file']]);
$json = json_decode($response->getBody(), true);
$entries = $json['list'];
@@ -676,7 +678,8 @@
list($dst_name, $dst_repo_id) = $this->find_collection($new_name);
$file_id = $this->find_file_id($src_name, $repo_id);
- $response = $this->client->request("PUT", "v4/fs/$file_id?name=$dst_name", ['headers' => ["X-Kolab-Parents" => $dst_repo_id]]);
+ $response = $this->client->request('PUT', "v4/fs/{$file_id}",
+ ['query' => ['name' => $dst_name], 'headers' => ["X-Kolab-Parents" => $dst_repo_id]]);
$success = $response->getStatusCode() == 200;
if (!$success) {
@@ -702,12 +705,14 @@
list($folder, $repo_id) = $this->find_collection($folder_name, true);
if (empty($repo_id)) {
- $response = $this->client->request("POST", "v4/fs?name=$folder_name&type=collection");
+ $request = ['name' => $folder_name, 'type' => 'collection'];
}
else {
- $response = $this->client->request("POST", "v4/fs?name=$folder&type=collection&parent={$repo_id}");
+ $request = ['name' => $folder, 'type' => 'collection', 'parent' => $repo_id];
}
+ $response = $this->client->request('POST', 'v4/fs', ['json' => $request]);
+
$success = $response->getStatusCode() == 200;
if (!$success) {
@@ -731,7 +736,7 @@
{
list($folder, $repo_id) = $this->find_collection($folder_name, true);
- $response = $this->client->request("DELETE", "v4/fs/$repo_id");
+ $response = $this->client->request('DELETE', "v4/fs/{$repo_id}");
$success = $response->getStatusCode() == 200;
if (!$success) {
@@ -752,7 +757,9 @@
list($folder_name, $repo_id, $collection) = $this->find_collection($folder_name, true);
list($dest_folder_name, $dest_repo_id) = $this->find_collection($new_name, true);
- $response = $this->client->request("PUT", "v4/fs/$repo_id?name=$dest_folder_name", ['headers' => ["X-Kolab-Parents" => $dest_repo_id]]);
+ $response = $this->client->request('PUT', "v4/fs/{$repo_id}",
+ ['query' => ['name' => $dest_folder_name], 'headers' => ["X-Kolab-Parents" => $dest_repo_id]]);
+
$success = $response->getStatusCode() == 200;
if (!$success) {
@@ -833,7 +840,7 @@
{
list($folder, $repo_id, $collection) = $this->find_collection($folder_name);
- $response = $this->client()->request('GET', "v4/fs/$repo_id");
+ $response = $this->client()->request('GET', "v4/fs/{$repo_id}");
$json = json_decode($response->getBody(), true);
if ($json['canUpdate']) {
return file_storage::ACL_READ | file_storage::ACL_WRITE;
@@ -1034,14 +1041,17 @@
//FIXME If we could just fetch all collections, we could assemble the tree after a single fetch.
if ($parent) {
$parentId = $parent['id'];
- $response = $this->client()->request('GET', "v4/fs?parent=$parentId&type=collection");
+ $request = ['parent' => $parentId, 'type' => 'collection'];
} else {
- $response = $this->client()->request('GET', "v4/fs?type=collection");
+ $request = ['type' => 'collection'];
}
+
+ $response = $this->client()->request('GET', 'v4/fs', ['query' => $request]);
+
//FIXME should we just always throw on request errors? Probably?
if ($response->getStatusCode() != 200) {
rcube::write_log('kolabfiles', "Failed to fetch collections from api, request status: " . $response->getStatusCode());
- throw new Exception("Get request was unsuccessful");
+ throw new Exception("GET request was unsuccessful");
}
$json = json_decode($response->getBody(), true);
// rcube::write_log('kolabfiles', var_export($json, true));
@@ -1074,7 +1084,7 @@
protected function find_file_id($file_name, $repo_id)
{
- $response = $this->client()->request('GET', "v4/fs?parent={$repo_id}&type=file");
+ $response = $this->client()->request('GET', 'v4/fs', ['query' => ['parent' => $repo_id, 'type' => 'file']]);
$json = json_decode($response->getBody(), true);
foreach ($json['list'] as $idx => $file) {
if ($file['name'] == $file_name) {

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 10:24 PM (7 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18827047
Default Alt Text
D5136.1775255077.diff (8 KB)

Event Timeline