Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117877639
D5136.1775338515.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
D5136.1775338515.diff
View Options
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
@@ -136,7 +136,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 +149,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 +351,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 +391,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 +451,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 +494,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 +569,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 +677,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 +704,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 +735,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 +756,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 +839,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 +1040,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 +1083,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
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 4, 9:35 PM (17 h, 21 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18831264
Default Alt Text
D5136.1775338515.diff (7 KB)
Attached To
Mode
D5136: Proper use of request parameters in Guzzle client
Attached
Detach File
Event Timeline