mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Guard getMedia finalize path from ids=M0 and make uploaded status save resilient on retry
This commit is contained in:
parent
5eeddbd9a3
commit
7f0aabf368
2 changed files with 26 additions and 3 deletions
|
|
@ -207,13 +207,25 @@ class MediaClient
|
|||
if (pages.isEmpty()) {
|
||||
Single.just(emptyList())
|
||||
} else {
|
||||
// If any pageId is invalid (0 or negative), avoid fetching entities like M0
|
||||
// and convert using a blank entity to prevent wbgetentities no-such-entity errors.
|
||||
if (pages.any { it.pageId() <= 0 }) {
|
||||
Single.just(
|
||||
pages.mapNotNull { page ->
|
||||
page.imageInfo()?.let { imageInfo ->
|
||||
mediaConverter.convert(page, Entities.Entity(), imageInfo)
|
||||
}
|
||||
},
|
||||
)
|
||||
} else {
|
||||
getEntities(pages.map { "$PAGE_ID_PREFIX${it.pageId()}" })
|
||||
.map {
|
||||
pages
|
||||
.zip(it.entities().values)
|
||||
.mapNotNull { (page, entity) ->
|
||||
page.imageInfo()?.let {
|
||||
mediaConverter.convert(page, entity, it)
|
||||
page.imageInfo()?.let { imageInfo ->
|
||||
mediaConverter.convert(page, entity, imageInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -618,8 +618,16 @@ class UploadWorker(
|
|||
private fun saveIntoUploadedStatus(contribution: Contribution) {
|
||||
contribution.contentUri?.let {
|
||||
val imageSha1 = contribution.imageSHA1.toString()
|
||||
val modifiedSha1 = fileUtilsWrapper.getSHA1(fileUtilsWrapper.getFileInputStream(contribution.localUri?.path))
|
||||
val modifiedSha1 = try {
|
||||
fileUtilsWrapper.getSHA1(
|
||||
fileUtilsWrapper.getFileInputStream(contribution.localUri?.path),
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e, "UploadedStatus: modified file missing/unreadable; falling back to original SHA1")
|
||||
imageSha1
|
||||
}
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
uploadedStatusDao.insertUploaded(
|
||||
UploadedStatus(
|
||||
imageSha1,
|
||||
|
|
@ -628,6 +636,9 @@ class UploadWorker(
|
|||
true,
|
||||
),
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e, "UploadedStatus: insert failed; continuing")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue