Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic icon creation #840

Merged
merged 23 commits into from
Nov 18, 2016
Merged

Add dynamic icon creation #840

merged 23 commits into from
Nov 18, 2016

Conversation

juliushaertl
Copy link
Member

@juliushaertl juliushaertl commented Aug 11, 2016

So this basically addresses #218 and #378. With this change the theming app offers two new endpoints for getting themed icons.
Return a image with logo and colored background:
http://localhost:8080/index.php/apps/theming/favicon/appname
Return a svg icon replacing the default color with the themed one:
http://localhost:8080/index.php/apps/theming/img/appname/filepath

Results:
2016-08-11-231339_961x348_scrot
2016-08-11-234209_191x31_scrot

  • use theming logo instead of nextcloud if available
  • touch homescreen icons
  • search icons.css for classes like icon-folder to replace the icon with a themed one
  • Add caching
  • check if there are directory traversal issues
  • Unit tests
  • code cleanup

@mention-bot
Copy link

@juliushaertl, thanks for your PR! By analyzing the annotation information on this pull request, we identified @bartv2, @rullzer and @LukasReschke to be potential reviewers

@rullzer
Copy link
Member

rullzer commented Aug 14, 2016

Mmmm I guess we kind of have to at some point. But we should add a big cache and cache buster (changed only when the theme is updated!) to make sure this hits the server as few times as possible. Because we will setup a lot of stuff to server an icon.

awesome initiative @juliushaertl!

@juliushaertl
Copy link
Member Author

I'm still trying to figure out how caching could be implemented. I think having the files on the file system makes the most sense.

For now I think I'll just store them into the data/ folder, like it is currently happening with the logo and background image, but this will become a huge mess due to number of icons.
Therefore #136 looks promising.

@rullzer
Copy link
Member

rullzer commented Aug 15, 2016

@juliushaertl no the point is that right now all icons are serverd by the webserver. No PHP is involved etc.

We can easily add proper caching headers. Just let me know if you need help.

@jancborchardt
Copy link
Member

Awesome @juliushaertl! :) Only thing is that the favicon logo is black whereas the normal logo is white. The favicon should be the same as the chosen logo. :)

@juliushaertl
Copy link
Member Author

@jancborchardt ah right, I'll remove that.

I should have some time later today to finish this.

@juliushaertl
Copy link
Member Author

OK, i'll need some more time, as testing the Imagemagick stuff will be a bit harder. But I'm on it. 😄

@juliushaertl juliushaertl force-pushed the theming-icon-endpoint branch 2 times, most recently from 86bcc4a to 6fcd411 Compare August 30, 2016 07:50
@juliushaertl juliushaertl added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Aug 30, 2016
@juliushaertl
Copy link
Member Author

Finally ready for review! @nextcloud/theming

@rullzer It would be great if you could have a look if the caching is fine. (apps/theming/lib/Controller/IconController.php)

It would also be good if someone could have a look if there are any problems with directory traversal. The route Icon#getThemedIcon accepts paths within the image parameter to allow getting images inside a subdirectory ( like mimetypes/folder.svg to get /core/img/mimetypes/folder.svg).
It seems like those are already prevented, but it would be good to have someone
check that as well. @nextcloud/security

@LukasReschke LukasReschke self-assigned this Aug 30, 2016
@MorrisJobke
Copy link
Member

Tested and works in Firefox. Opera, Safari, Chrome, Edge, IE11 and IE10 🙌 👍

$response->cacheFor(86400);
$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
$response->addHeader('Pragma', 'cache');
return $response;
Copy link
Member

Choose a reason for hiding this comment

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

You don't store the colored svg anywhere?
If you have a themed instance with 50K users you will still have to do this for 50K users.

Also if you have a file that you server we could use #1121. you could set the ETag. That way if the file did not change the request is fast.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can easily add proper caching headers.

OK, maybe I misinterpreded your previous answer. I already thought that storing the generated icons in the filesystem would make sense. Do you have any hint how I could implement that?

We can't store it in the user-folders as these are also required for public/login page. I guess we should not just put them inside the data folder. That is why I thought that #136 might be important. Or is it possible to use a simple memory cache for these icons, as the number of those generated icons will stay quite low?

It would be great, if you could point me into the right direction.

Copy link
Member

Choose a reason for hiding this comment

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

Hehe. Well there are 2 things of course.

  1. We want to cache server side so serving is fast
  2. We want to cache client side so we don't have to request stuff from the server every time

They are two different optimizations but work towards the same goal of less request => less server load & faster loading

I'll see if we can make #136 happen sooner rather than later. because I don't really feel comfortable just dumping this all in the root data folder.

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be great. :)

@juliushaertl juliushaertl added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Sep 21, 2016
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Signed-off-by: Julius Haertl <jus@bitgrid.net>
@juliushaertl
Copy link
Member Author

@rullzer @LukasReschke @nextcloud/theming Changes are in. Ready for another review.

@MorrisJobke MorrisJobke merged commit faee255 into master Nov 18, 2016
@MorrisJobke
Copy link
Member

👍

@MorrisJobke MorrisJobke deleted the theming-icon-endpoint branch November 18, 2016 14:35
@jancborchardt
Copy link
Member

Good stuff @juliushaertl :) as always

@juliushaertl
Copy link
Member Author

🎉

@jancborchardt Thanks. I'm always glad to help. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants