光环助手V4.0.1-视频相关优化汇总(6,7)https://gitlab.ghzs.com/pm/halo-app-issues/-/issues/866
This commit is contained in:
@ -1,6 +1,13 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
@ -75,4 +82,61 @@ public class MD5Utils {
|
||||
return bigInt.toString(16);
|
||||
}
|
||||
|
||||
|
||||
public static boolean checkMD5(String md5, File updateFile) {
|
||||
if (TextUtils.isEmpty(md5) || updateFile == null) {
|
||||
Utils.log("MD5 string empty or updateFile null");
|
||||
return false;
|
||||
}
|
||||
|
||||
String calculatedDigest = calculateMD5(updateFile);
|
||||
if (calculatedDigest == null) {
|
||||
Utils.log("calculatedDigest null");
|
||||
return false;
|
||||
}
|
||||
|
||||
Utils.log("Calculated digest: " + calculatedDigest);
|
||||
Utils.log("Provided digest: " + md5);
|
||||
return calculatedDigest.equalsIgnoreCase(md5);
|
||||
}
|
||||
|
||||
public static String calculateMD5(File updateFile) {
|
||||
MessageDigest digest;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
} catch (Exception e) {
|
||||
Utils.log("Exception while getting digest", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream is;
|
||||
try {
|
||||
is = new FileInputStream(updateFile);
|
||||
} catch (Exception e) {
|
||||
Utils.log("Exception while getting FileInputStream", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[8192];
|
||||
int read;
|
||||
try {
|
||||
while ((read = is.read(buffer)) > 0) {
|
||||
digest.update(buffer, 0, read);
|
||||
}
|
||||
byte[] md5sum = digest.digest();
|
||||
BigInteger bigInt = new BigInteger(1, md5sum);
|
||||
String output = bigInt.toString(16);
|
||||
// Fill to 32 chars
|
||||
output = String.format("%32s", output).replace(' ', '0');
|
||||
return output;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to process file for MD5", e);
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (Exception e) {
|
||||
Utils.log("Exception on closing MD5 input stream", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ import com.gh.gamecenter.video.upload.UploadEntity;
|
||||
SignEntity.class,
|
||||
AnswerEntity.class,
|
||||
UploadEntity.class,
|
||||
CommentDraft.class}, version = 13, exportSchema = false)
|
||||
CommentDraft.class}, version = 14, exportSchema = false)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
|
||||
public abstract AnswerDao answerDao();
|
||||
@ -138,6 +138,13 @@ public abstract class AppDatabase extends RoomDatabase {
|
||||
}
|
||||
};
|
||||
|
||||
static final Migration MIGRATION_13_14 = new Migration(13, 14) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("Alter TABLE UploadEntity add fileMD5 TEXT");
|
||||
}
|
||||
};
|
||||
|
||||
private static AppDatabase buildDatabase(Context context) {
|
||||
return Room.databaseBuilder(context, AppDatabase.class, DATABASE_NAME)
|
||||
.addMigrations(
|
||||
@ -150,7 +157,8 @@ public abstract class AppDatabase extends RoomDatabase {
|
||||
MIGRATION_9_10,
|
||||
MIGRATION_10_11,
|
||||
MIGRATION_11_12,
|
||||
MIGRATION_12_13)
|
||||
MIGRATION_12_13,
|
||||
MIGRATION_13_14)
|
||||
// 不允许主线程查询
|
||||
.allowMainThreadQueries()
|
||||
// // 提供db升级的策略而不是强行销毁
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
package com.gh.gamecenter.room.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.*
|
||||
import com.gh.gamecenter.video.upload.UploadEntity
|
||||
|
||||
@Dao
|
||||
@ -14,4 +11,7 @@ interface UploadDao {
|
||||
|
||||
@Query("select * from UploadEntity where uploadFilePath = :uploadFilePath")
|
||||
fun getUploadByFilePath(uploadFilePath: String): UploadEntity?
|
||||
|
||||
@Query("delete from UploadEntity WHERE uploadFilePath = :uploadFilePath")
|
||||
fun deleteUploadByPath(uploadFilePath: String)
|
||||
}
|
||||
@ -9,6 +9,7 @@ import androidx.room.PrimaryKey
|
||||
data class UploadEntity(
|
||||
@PrimaryKey
|
||||
val uploadFilePath: String,
|
||||
val fileMD5: String?,
|
||||
val domain: String, // url = domain + key
|
||||
val key: String,
|
||||
var success: Boolean
|
||||
|
||||
@ -2,6 +2,7 @@ package com.gh.gamecenter.video.upload
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import com.alibaba.sdk.android.oss.common.OSSLog
|
||||
import com.gh.common.util.MD5Utils
|
||||
import com.gh.gamecenter.BuildConfig
|
||||
|
||||
import com.gh.gamecenter.entity.OssEntity
|
||||
@ -12,6 +13,7 @@ import com.halo.assistant.HaloApp
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
||||
@ -51,9 +53,10 @@ object UploadManager : OnUploadListener {
|
||||
fun createUploadTask(uploadFilePath: String, uploadListener: OnUploadListener) {
|
||||
mUploadListenerMap[uploadFilePath] = uploadListener
|
||||
|
||||
val fileMD5 = MD5Utils.calculateMD5(File(uploadFilePath))
|
||||
val uploadEntity = mUploadDao.getUploadByFilePath(uploadFilePath)
|
||||
|
||||
if (uploadEntity?.success == true) {
|
||||
if (uploadEntity?.success == true && fileMD5 == uploadEntity.fileMD5) {
|
||||
onUploadSuccess(uploadFilePath, uploadEntity.domain + uploadEntity.key)
|
||||
return
|
||||
}
|
||||
@ -73,7 +76,7 @@ object UploadManager : OnUploadListener {
|
||||
data.domain = uploadEntity.domain
|
||||
data.key = uploadEntity.key
|
||||
} else {
|
||||
mUploadDao.addUpload(UploadEntity(uploadFilePath, data.domain, data.key, false))
|
||||
mUploadDao.addUpload(UploadEntity(uploadFilePath, fileMD5, data.domain, data.key, false))
|
||||
}
|
||||
|
||||
val uploadThread = UploadThread(data, this@UploadManager)
|
||||
@ -97,4 +100,10 @@ object UploadManager : OnUploadListener {
|
||||
uploadThread?.cancel()
|
||||
mUploadThreadMap.remove(uploadFilePath)
|
||||
}
|
||||
|
||||
fun deleteUploadData(filePath: String?) {
|
||||
filePath?.let {
|
||||
mUploadDao.deleteUploadByPath(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,6 +219,7 @@ class UploadVideoActivity : ToolBarActivity() {
|
||||
NotificationHelper.showNotificationHintDialog(NotificationUgc.VIDEO)
|
||||
}, 1000)
|
||||
LogUtils.logVideoStreamingUpload("提交成功", mPath, mEntranceLink, it.data)
|
||||
UploadManager.deleteUploadData(mVideoFileEntity?.path)
|
||||
} else if (it.status == Status.ERROR) {
|
||||
ErrorHelper.handleError(this@UploadVideoActivity, it.exception?.response()?.errorBody()?.string())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user