summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-09-20 11:06:44 +0200
committerFlorian Pritz <bluewind@xinu.at>2015-09-20 11:09:03 +0200
commitf4c47ee5b72f6074827cc86b28d0ab4031be7237 (patch)
tree3ce69531ccc7d9a51bab738089a12adb5634518e /application
parent1c302ee79174818b996bd4bb4418bbd320e2a1d1 (diff)
API 2.1: Add thumbnail link to history
Also adjust test cases to check for the new value. API v1 does not change. Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r--application/controllers/api/v1/file.php3
-rw-r--r--application/service/files.php3
-rw-r--r--application/test/tests/test_api_v1.php12
-rw-r--r--application/test/tests/test_api_v2.php12
4 files changed, 26 insertions, 4 deletions
diff --git a/application/controllers/api/v1/file.php b/application/controllers/api/v1/file.php
index 4ffc8ed48..dae053db2 100644
--- a/application/controllers/api/v1/file.php
+++ b/application/controllers/api/v1/file.php
@@ -59,6 +59,9 @@ class file extends \controllers\api\api_controller {
{
$this->muser->require_access("apikey");
$history = \service\files::history($this->muser->get_userid());
+ foreach ($history['items'] as $key => $item) {
+ unset($history['items'][$key]['thumbnail']);
+ }
return $history;
}
diff --git a/application/service/files.php b/application/service/files.php
index 7cef73d97..adc62c7dc 100644
--- a/application/service/files.php
+++ b/application/service/files.php
@@ -24,6 +24,9 @@ class files {
->where('user', $user)
->get()->result_array();
foreach ($query as $key => $item) {
+ if (\libraries\Image::type_supported($item["mimetype"])) {
+ $item['thumbnail'] = site_url("file/thumbnail/".$item['id']);
+ }
$items[$item["id"]] = $item;
}
diff --git a/application/test/tests/test_api_v1.php b/application/test/tests/test_api_v1.php
index f0a2096d6..28b1576d0 100644
--- a/application/test/tests/test_api_v1.php
+++ b/application/test/tests/test_api_v1.php
@@ -323,7 +323,9 @@ class test_api_v1 extends \test\Test {
public function test_history_notEmptyAfterUpload()
{
$apikey = $this->createUserAndApikey();
- $this->uploadFile($apikey, "data/tests/small-file");
+ $uploadid = $this->uploadFile($apikey, "data/tests/small-file")['data']['ids'][0];
+ $uploadid_image = $this->uploadFile($apikey, "data/tests/black_white.png")['data']['ids'][0];
+ $expected_size = filesize("data/tests/small-file") + filesize("data/tests/black_white.png");
$ret = $this->CallEndpoint("POST", "file/history", array(
"apikey" => $apikey,
@@ -331,8 +333,14 @@ class test_api_v1 extends \test\Test {
$this->expectSuccess("history not empty after upload", $ret);
$this->t->ok(!empty($ret["data"]["items"]), "history not empty after upload (items)");
+ $this->t->is_deeply(array(
+ 'id', 'filename', 'mimetype', 'date', 'hash', 'filesize'
+ ), array_keys($ret['data']["items"][$uploadid]), "item info only lists correct keys");
+ $this->t->is_deeply(array(
+ 'id', 'filename', 'mimetype', 'date', 'hash', 'filesize'
+ ), array_keys($ret['data']["items"][$uploadid_image]), "item info for image does not list thumbnail in v1");
$this->t->ok(empty($ret["data"]["multipaste_items"]), "didn't upload multipaste");
- $this->t->is($ret["data"]["total_size"], filesize("data/tests/small-file"), "total_size == uploaded file");
+ $this->t->is($ret["data"]["total_size"], $expected_size, "total_size == uploaded files");
}
public function test_history_notSharedBetweenUsers()
diff --git a/application/test/tests/test_api_v2.php b/application/test/tests/test_api_v2.php
index 1886cdf7c..96deb382c 100644
--- a/application/test/tests/test_api_v2.php
+++ b/application/test/tests/test_api_v2.php
@@ -323,7 +323,9 @@ class test_api_v2 extends \test\Test {
public function test_history_notEmptyAfterUpload()
{
$apikey = $this->createUserAndApikey();
- $this->uploadFile($apikey, "data/tests/small-file");
+ $uploadid = $this->uploadFile($apikey, "data/tests/small-file")['data']['ids'][0];
+ $uploadid_image = $this->uploadFile($apikey, "data/tests/black_white.png")['data']['ids'][0];
+ $expected_size = filesize("data/tests/small-file") + filesize("data/tests/black_white.png");
$ret = $this->CallEndpoint("POST", "file/history", array(
"apikey" => $apikey,
@@ -331,8 +333,14 @@ class test_api_v2 extends \test\Test {
$this->expectSuccess("history not empty after upload", $ret);
$this->t->ok(!empty($ret["data"]["items"]), "history not empty after upload (items)");
+ $this->t->is_deeply(array(
+ 'id', 'filename', 'mimetype', 'date', 'hash', 'filesize'
+ ), array_keys($ret['data']["items"][$uploadid]), "item info only lists correct keys");
+ $this->t->is_deeply(array(
+ 'id', 'filename', 'mimetype', 'date', 'hash', 'filesize', 'thumbnail'
+ ), array_keys($ret['data']["items"][$uploadid_image]), "item info for image lists thumbnail too");
$this->t->ok(empty($ret["data"]["multipaste_items"]), "didn't upload multipaste");
- $this->t->is($ret["data"]["total_size"], filesize("data/tests/small-file"), "total_size == uploaded file");
+ $this->t->is($ret["data"]["total_size"], $expected_size, "total_size == uploaded files");
}
public function test_history_notSharedBetweenUsers()