Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

fix(covers): catch covers API timeouts and hardcode cache file extensions #123

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

defvs
Copy link
Collaborator

@defvs defvs commented Jun 19, 2020

Fixes #107

Regarding the file extension hardcode :
Other than grabbing the Content-Type header (which is cumbersome in the current scope), it is better for now to hardcode the file extension. Most file viewers today can recognize wrong extension and still read, for example, a png file disguised with a .jpg extension;

Fixes #107 ("Cover loading times out very often")
Other than grabbing the Content-Type header (which is cumbersome in the current scope), it is better for now to hardcode the file extension. Most file viewers today can recognize wrong extension and still read, for example, a png file disguised with a .jpg extension;
At least now the cover cache files aren't a bunch of extension-less files anymore.
@defvs defvs requested a review from xeruf June 19, 2020 22:50
@defvs defvs self-assigned this Jun 19, 2020
@defvs
Copy link
Collaborator Author

defvs commented Jun 27, 2020

@xerus2000 same for this PR; needs a review

@@ -16,13 +16,16 @@ object Covers {
private fun coverCacheFile(coverUrl: String, size: Int): File {
coverCacheDir.mkdirs()
val newFile = coverCacheDir.resolve(coverUrl.substringBeforeLast('/').substringAfterLast('/').replaceIllegalFileChars())
Copy link
Owner

Choose a reason for hiding this comment

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

If the name of the coverUrl has changed, can't we simplify this? Otherwise, using split seems more sensible to me than two substring operations.

Copy link
Owner

Choose a reason for hiding this comment

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

Also, please write a test for this method. Should be easy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have not a single idea on how to write tests unfortunately.

Copy link
Owner

Choose a reason for hiding this comment

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

Then look into the existing ones :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Split usage 0f20221

src/main/xerus/monstercat/downloader/SongView.kt Outdated Show resolved Hide resolved
Comment on lines 24 to 28
fun getThumbnailImage(coverUrl: String, size: Number = 64, invalidate: Boolean = false) = try {
getCover(coverUrl, 64, invalidate).use { createImage(it, size) }
} catch (e: Exception) {
null
}
Copy link
Owner

Choose a reason for hiding this comment

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

Why swallow the exception here?

And if you have to, please document that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, there should be an error logging.

Copy link
Owner

@xeruf xeruf Jun 29, 2020

Choose a reason for hiding this comment

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

Why does this function have to catch the error at all, why not propagate it?
And you should almost never catch a blanket-Exception - this might swallow critical unexpected errors too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Better handling of exceptions with 81f8555

@@ -16,13 +16,16 @@ object Covers {
private fun coverCacheFile(coverUrl: String, size: Int): File {
coverCacheDir.mkdirs()
val newFile = coverCacheDir.resolve(coverUrl.substringBeforeLast('/').substringAfterLast('/').replaceIllegalFileChars())
return coverCacheDir.resolve("${newFile.nameWithoutExtension}x$size.${newFile.extension}")
return coverCacheDir.resolve("${newFile.nameWithoutExtension}x$size.jpg") // FIXME : Do not hardcode extension
Copy link
Owner

Choose a reason for hiding this comment

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

Why don't you use the extension of newFile anymore? If we don't know the extension, I would prefer to give the file no extension at all. If a reader is so versatile that it can recognize a png disguised as jpg, it can also handle files without extension. Besides, the cache is not for browsing anyways.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The extensions returned empty each time, because coverUrl (the HTTP url to the cover) doesn't have an extension anymore. Only some gibberish by AWS...

Let's remove the hardcode then and keep files without extensions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reverted in 14d34f5

@defvs defvs requested a review from xeruf November 20, 2020 12:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cover loading times out very often
2 participants