FAForever/faf-java-api

Enhance avatar urls on upload (encode url)

Closed this issue · 8 comments

Also make the base path configurable.

Example url: http://content.faforever.com/faf/avatars/Tier 1 League King Season 3.png

  1. Store filename only
  2. Add base url from config
  3. urlencode everything

This seems like some overhaul needs to be done in https://github.com/FAForever/faf-java-api/blob/develop/src/main/java/com/faforever/api/avatar/AvatarController.java

Additionally the base url to be injected using properties file(will look at that file).

Any thoughts?

You are on the right track. 👍

Need few more inputs. This is how it translates at the code level:

  1. In AvatarService.java, remove this line where URL is stored https://github.com/FAForever/faf-java-api/blob/develop/src/main/java/com/faforever/api/avatar/AvatarService.java#L54

  2. Where exactly in this service do I URL encode?

Also I assume I have to use the config property instead of Properties. Any thoughts on how I could translate this to code?

The URL is currently part of the database model and also in the JPA entity:
http://faforever.github.io/db/tables/avatars_list.html

Example values are:
https://content.faforever.com/faf/avatars/donator.png
https://content.faforever.com/faf/avatars/mod.png

So what we want to achieve here is that the database should only store the filename e.g. donator.png (fixing it with a one time db migration) and that we can define the base url in the FafApiProperties. Doing that we can make the url a @transient attribute of the data model being built on demand. And in the code that concacts the the base url path and the filename we should urlencode the result.

Thanks for the explanation. This is what I understood:

  • Create a new @column for filename in JPA
  • Change @column for url in model to transient
  • Concat with new property and URL encode this line:

String url = String.format(properties.getAvatar().getDownloadUrlFormat(), normalizedAvatarFileName);

Assume further tweaking is in order for AvatarServiceTest.java

Send me an email (alexander.von.trostorff@gmail.com) and I will invite you to Zulip(chat service similar to Slack). In case u want that...

Btw the lobby server reads avatars directly from the database. So changing what is stored in the tables will break the avatar responses there.

Closed with #397