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
|
|
@ -206,14 +206,26 @@ class MediaClient
|
||||||
private fun mediaFromPageAndEntity(pages: List<MwQueryPage>): Single<List<Media>> =
|
private fun mediaFromPageAndEntity(pages: List<MwQueryPage>): Single<List<Media>> =
|
||||||
if (pages.isEmpty()) {
|
if (pages.isEmpty()) {
|
||||||
Single.just(emptyList())
|
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 {
|
} else {
|
||||||
getEntities(pages.map { "$PAGE_ID_PREFIX${it.pageId()}" })
|
getEntities(pages.map { "$PAGE_ID_PREFIX${it.pageId()}" })
|
||||||
.map {
|
.map {
|
||||||
pages
|
pages
|
||||||
.zip(it.entities().values)
|
.zip(it.entities().values)
|
||||||
.mapNotNull { (page, entity) ->
|
.mapNotNull { (page, entity) ->
|
||||||
page.imageInfo()?.let {
|
page.imageInfo()?.let { imageInfo ->
|
||||||
mediaConverter.convert(page, entity, it)
|
mediaConverter.convert(page, entity, imageInfo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -618,8 +618,16 @@ class UploadWorker(
|
||||||
private fun saveIntoUploadedStatus(contribution: Contribution) {
|
private fun saveIntoUploadedStatus(contribution: Contribution) {
|
||||||
contribution.contentUri?.let {
|
contribution.contentUri?.let {
|
||||||
val imageSha1 = contribution.imageSHA1.toString()
|
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 {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
uploadedStatusDao.insertUploaded(
|
uploadedStatusDao.insertUploaded(
|
||||||
UploadedStatus(
|
UploadedStatus(
|
||||||
imageSha1,
|
imageSha1,
|
||||||
|
|
@ -628,6 +636,9 @@ class UploadWorker(
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.w(e, "UploadedStatus: insert failed; continuing")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue