fix: validate asset edits before deleting the cached file (#6190)

Reject duplicate names and empty names or URLs before invalidating the existing asset cache. Previously a rejected save left the stored source unchanged but deleted its downloaded file.

Preserve the validation messages and their order, duplicate-name exclusion by asset ID, and successful-save behavior. Renames still invalidate the old filename before updating the asset record.
This commit is contained in:
eliotcougar authored and nerpa committed 2026-09-14 16:53:35 +03:00
1 parent 01f3cb8046
commit 5b99841f06
1 file changed
+14 -14
@@ -81,6 +81,20 @@ class UserAssetUrlActivity : BaseComponentActivity() {
}
private fun saveServer(remarks: String, url: String): Boolean {
val assetList = MmkvManager.decodeAssetUrls()
if (assetList.any { it.assetUrl.remarks == remarks && it.guid != editAssetId }) {
toast(R.string.msg_remark_is_duplicate)
return false
}
if (TextUtils.isEmpty(remarks)) {
toast(R.string.sub_setting_remarks)
return false
}
if (TextUtils.isEmpty(url)) {
toast(R.string.title_url)
return false
}
var assetItem = MmkvManager.decodeAsset(editAssetId)
var assetId = editAssetId
if (assetItem != null) {
@@ -100,20 +114,6 @@ class UserAssetUrlActivity : BaseComponentActivity() {
assetItem.remarks = remarks
assetItem.url = url
val assetList = MmkvManager.decodeAssetUrls()
if (assetList.any { it.assetUrl.remarks == assetItem.remarks && it.guid != assetId }) {
toast(R.string.msg_remark_is_duplicate)
return false
}
if (TextUtils.isEmpty(assetItem.remarks)) {
toast(R.string.sub_setting_remarks)
return false
}
if (TextUtils.isEmpty(assetItem.url)) {
toast(R.string.title_url)
return false
}
MmkvManager.encodeAsset(assetId, assetItem)
toastSuccess(R.string.toast_success)
finish()