-
Notifications
You must be signed in to change notification settings - Fork 219
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
Decouples Cache and Download behaviour #493
Merged
AriaMoradi
merged 7 commits into
Suwayomi:master
from
akabhirav:cache-download-improvements
Feb 12, 2023
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4490bfb
Separate cache dir from download dir
akabhirav df9c8c1
Move downloader logic outside of caching/image download logic
akabhirav 290eef0
remove unnecessary method duplication
akabhirav 8e891ba
moved download logic inside download provider
akabhirav 50e2956
optimize and handle partial downloads
akabhirav 0226831
made code review changes
akabhirav fcb3c95
Merge branch 'master' into cache-download-improvements
akabhirav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
server/src/main/kotlin/suwayomi/tachidesk/manga/impl/ChapterDownloadHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package suwayomi.tachidesk.manga.impl | ||
|
||
import suwayomi.tachidesk.manga.impl.download.DownloadedFilesProvider | ||
import suwayomi.tachidesk.manga.impl.download.FolderProvider | ||
import java.io.InputStream | ||
|
||
object ChapterDownloadHelper { | ||
fun getImage(mangaId: Int, chapterId: Int, index: Int): Pair<InputStream, String> { | ||
return provider(mangaId, chapterId).getImage(index) | ||
} | ||
|
||
fun delete(mangaId: Int, chapterId: Int): Boolean { | ||
return provider(mangaId, chapterId).delete() | ||
} | ||
|
||
fun putImage(mangaId: Int, chapterId: Int, index: Int, image: InputStream): Boolean { | ||
return provider(mangaId, chapterId).putImage(index, image) | ||
} | ||
|
||
// return the appropriate provider based on how the download was saved. For the logic is simple but will evolve when new types of downloads are available | ||
private fun provider(mangaId: Int, chapterId: Int): DownloadedFilesProvider { | ||
return FolderProvider(mangaId, chapterId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/DownloadedFilesProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package suwayomi.tachidesk.manga.impl.download | ||
|
||
import java.io.InputStream | ||
|
||
/* | ||
* Base class for downloaded chapter files provider, example: Folder, Archive | ||
* */ | ||
abstract class DownloadedFilesProvider(val mangaId: Int, val chapterId: Int) { | ||
abstract fun getImage(index: Int): Pair<InputStream, String> | ||
|
||
abstract fun putImage(index: Int, image: InputStream): Boolean | ||
|
||
abstract fun delete(): Boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/FolderProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package suwayomi.tachidesk.manga.impl.download | ||
|
||
import suwayomi.tachidesk.manga.impl.Page.getPageName | ||
import suwayomi.tachidesk.manga.impl.util.getChapterDir | ||
import suwayomi.tachidesk.manga.impl.util.storage.ImageResponse | ||
import java.io.File | ||
import java.io.FileInputStream | ||
import java.io.InputStream | ||
|
||
/* | ||
* Provides downloaded files when pages were downloaded into folders | ||
* */ | ||
class FolderProvider(mangaId: Int, chapterId: Int) : DownloadedFilesProvider(mangaId, chapterId) { | ||
override fun getImage(index: Int): Pair<InputStream, String> { | ||
val chapterDir = getChapterDir(mangaId, chapterId) | ||
val folder = File(chapterDir) | ||
folder.mkdirs() | ||
val file = folder.listFiles()?.get(index) | ||
val fileType = file!!.name.substringAfterLast(".") | ||
return Pair(FileInputStream(file).buffered(), "image/$fileType") | ||
} | ||
|
||
override fun putImage(index: Int, image: InputStream): Boolean { | ||
val chapterDir = getChapterDir(mangaId, chapterId) | ||
val folder = File(chapterDir) | ||
folder.mkdirs() | ||
val fileName = getPageName(index) | ||
val filePath = "$chapterDir/$fileName" | ||
ImageResponse.saveImage(filePath, image) | ||
return true | ||
} | ||
|
||
override fun delete(): Boolean { | ||
val chapterDir = getChapterDir(mangaId, chapterId) | ||
return File(chapterDir).deleteRecursively() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
going to change this to download since we don't need a single put image here, we can just move the entire downlod logic here. Also, building an ArchiveProvider is proving difficult since appending to zip is not working for some reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this change in the latest commit