Skip to content

REST API for thumbnails - #11009

Merged
LukasReschke merged 1 commit into
masterfrom
tobiasKaminsky-route
Sep 16, 2014
Merged

LukasReschke merged 1 commit into
masterfrom
tobiasKaminsky-route

Conversation

@LukasReschke

Copy link
Copy Markdown
Contributor

This replaces #10805, changes:

  • Code style fixed
  • Exception thrown in case file is not found
  • Route does not use GET parameters anymore
  • Now REST instead of OCS

@georgehrke

@LukasReschke LukasReschke changed the title Tobias kaminsky route OCS route for thumbnails Sep 11, 2014
@LukasReschke
LukasReschke force-pushed the tobiasKaminsky-route branch 2 times, most recently from 976f39f to e6c30b6 Compare September 11, 2014 09:12
@LukasReschke

Copy link
Copy Markdown
Contributor Author

Also @PVince81 and @DeepDiver1975. Can be tested with a request like /ocs/v1.php/thumbnail/100/100/welcome.txt

@LukasReschke

Copy link
Copy Markdown
Contributor Author

Might also be interesting for the mobile client team

\cc @karlitschek @MTRichards

@karlitschek

Copy link
Copy Markdown
Contributor

Indeed very cool. 👍 Thanks

@MTRichards

Copy link
Copy Markdown
Contributor

@rperezb For the team...

@rperezb

rperezb commented Sep 11, 2014

Copy link
Copy Markdown

got it, thx!

@LukasReschke

Copy link
Copy Markdown
Contributor Author

@owncloud-bot Retest this please.

@ghost

ghost commented Sep 15, 2014

Copy link
Copy Markdown

🚀 Test Passed. 🚀
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org/job/pull-request-analyser/7334/

Comment thread lib/private/ocs/thumbnail.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this rather be 404 not found ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. This is OCS and not really REST. - I'd prefer to keep it this way.

@karlitschek What do you think? - You've written that specification, not me ;-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new stuff we should do real REST. So 404 is good. The old stuff has to stay backward compatible unfortunately

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good :-)

@LukasReschke

Copy link
Copy Markdown
Contributor Author

@PVince81 @karlitschek Migrated to REST now, accessible via http://localhost/core/index.php/apps/files/api/v1/thumbnail/100/100/welcome.txt.

CURL command:

curl -i -s -k  -X 'GET' \
    -H 'Authorization: Basic YWRtaW46YWRtaW4=' \
    'http://localhost/core/index.php/apps/files/api/v1/thumbnail/100/100/welcome.txt'

@LukasReschke LukasReschke changed the title OCS route for thumbnails REST API for thumbnails Sep 16, 2014
@LukasReschke

Copy link
Copy Markdown
Contributor Author

@tobiasKaminsky If you want to review this too: Go for it ;-) - I changed the route to use somewhat more REST instead of our OCS routes.

@DeepDiver1975

Copy link
Copy Markdown
Contributor

tested - works 👍

@georgehrke

Copy link
Copy Markdown
Contributor

works 👍, code looks good
@LukasReschke please squash :) Thx

Thumbnail generation

Removed Log

Added requested changes

Added requested changes.

- Fix code style
- Add exception if file does not exist
- Switch route styling

Replaces #10805

Fix codestyle

Fix codestyle

Migrate to appframework

Fix typo
@DeepDiver1975

Copy link
Copy Markdown
Contributor

squashed and rebased

@scrutinizer-notifier

Copy link
Copy Markdown

A new inspection was created.

@ghost

ghost commented Sep 16, 2014

Copy link
Copy Markdown

💣 Test Failed. 💣
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org/job/pull-request-analyser/7377/

@LukasReschke

Copy link
Copy Markdown
Contributor Author
.PHP Fatal error:  Call to a member function getGID() on a non-object in /var/lib/jenkins/jobs/pull-request-analyser/workspace/lib/private/group.php on line 202
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:176
PHP   5. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/TextUI/TestRunner.php:349
PHP   6. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:705
PHP   7. PHPUnit_Framework_TestSuite->runTest() /usr/share/php/PHPUnit/Framework/TestSuite.php:745
PHP   8. PHPUnit_Framework_TestCase->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:775
PHP   9. PHPUnit_Framework_TestResult->run() /usr/share/php/PHPUnit/Framework/TestCase.php:776
PHP  10. PHPUnit_Framework_TestCase->runBare() /usr/share/php/PHPUnit/Framework/TestResult.php:648
PHP  11. PHPUnit_Framework_TestCase->runTest() /usr/share/php/PHPUnit/Framework/TestCase.php:831
PHP  12. ReflectionMethod->invokeArgs() /usr/share/php/PHPUnit/Framework/TestCase.php:976
PHP  13. Test_Group->testMultiBackend() /usr/share/php/PHPUnit/Framework/TestCase.php:976
PHP  14. OC_Group::getGroups() /var/lib/jenkins/jobs/pull-request-analyser/workspace/tests/lib/group.php:165
Build step 'Execute shell' marked build as failure

@DeepDiver1975

@LukasReschke

Copy link
Copy Markdown
Contributor Author

@owncloud-bot Retest this please

@ghost

ghost commented Sep 16, 2014

Copy link
Copy Markdown

🚀 Test Passed. 🚀
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org/job/pull-request-analyser/7386/

LukasReschke added a commit that referenced this pull request Sep 16, 2014
@LukasReschke
LukasReschke merged commit 368391e into master Sep 16, 2014
@LukasReschke
LukasReschke deleted the tobiasKaminsky-route branch September 16, 2014 17:31
@LukasReschke

Copy link
Copy Markdown
Contributor Author

Nothing... Unexpected behaviour of routing. On it....

LukasReschke added a commit that referenced this pull request Sep 18, 2014
@tobiasKaminsky

Copy link
Copy Markdown
Contributor

Another "problem":
In the android app I am using GetMethod(String uri) to retrieve the thumbnail.
This uri has to be escaped via URLEncoder.encode(uri), otherwise I get "escaped absolute path not valid".
Unfortunately the route does not accept encoded urls (and I am not that into the routes that I could try fixing it by myself...)

@LukasReschke

Copy link
Copy Markdown
Contributor Author

This seems to be more a problem in the Android code and not a server-side one. Please give an example what the result of URLEncoder.encode(uri) is - I don't know the Android API.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

I am only encoding the remote path of the file:
thumbnail/100/100/folder/2.jpg --> thumbnail/100/100%2Ffolder%2F2.jpg
/ is replaced by %2F
ä --> %C3%A4

For more see here: http://www.w3schools.com/tags/ref_urlencode.asp --> URL Encoding Functions

In the previous version without the REST Api it had worked without a problem as normal PHP understands this encoded url also as a local path.

@LukasReschke

Copy link
Copy Markdown
Contributor Author

I'd really say here you should not urlencode the path here... - Decoding the values server-side seems like a major hack...

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

The problem is that GetMethod requires it...
I could manually replace certain special characters and leave "/" as it is. This is at least working, but it is not very safe as there are so many other special characters.

Is it not possible to just pass the urlencoded path as $file to $preview = new \OC\Preview('', 'files', $file, $x, $y, true)?

At least this is working:

# $file = '%2Ffolder%2F2.jpg'; # /folder/2.jpg
# $file = '%2Fordner%2F0%C3%BC1.jpg'; # /ordner/0ü1.jpg
$preview = new \OC\Preview('', 'files', urldecode($file), $x, $y, true);

But unfortunately the encoded path is not given to the function...

@LukasReschke

Copy link
Copy Markdown
Contributor Author

Ok - I'll think of this tomorrow.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

Great!
If I can help you, please let it me know.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

@LukasReschke I need a little bit of testing, but I guess I have solved it:

  1. urldecode($file) is needed ($preview = new \OC\Preview('', 'files', urldecode($file), $x, $y, true);)
  2. I encode everything but the "/" as this breaks the route.

This is working for all special characters and whitespaces in files and/or folders.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

@LukasReschke Do you think you can change the $preview line as suggested above?
Then I can rely on it and work on the android app with this rest api.

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

@LukasReschke As things are getting serious in owncloud/android#635 it would be great if you can change the $preview line as suggested?

@LukasReschke

Copy link
Copy Markdown
Contributor Author

@tobiasKaminsky Sorry - got caught up with other things and forgot about this. There we go now: #11675

@tobiasKaminsky

Copy link
Copy Markdown
Contributor

No problem.
Thank you for your very fast reply yesterday evening!

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants