优化获取ptach
This commit is contained in:
@@ -18,8 +18,12 @@ public class CheckPatchController {
|
||||
DiffPathService diffPathService;
|
||||
|
||||
@GetMapping("/android/check_patch")
|
||||
public Result checkPatch(@RequestParam("pkg") String pkg, @RequestParam(value = "version_code") Long versionCode) {
|
||||
PatchFileInfo patchFileInfo = diffPathService.getPatchInfo(pkg, versionCode);
|
||||
return Result.success(patchFileInfo);
|
||||
public Result checkPatch(@RequestParam("pkg") String pkg, @RequestParam(value = "version_code") Long versionCode, @RequestParam(value = "md5") String oldMd5) {
|
||||
PatchFileInfo patchFileInfo = diffPathService.getPatchInfo(pkg, versionCode, oldMd5);
|
||||
if (patchFileInfo == null) {
|
||||
return Result.notFound();
|
||||
} else {
|
||||
return Result.success(patchFileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.mir4updater.backend.controller.apk;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mir4updater.backend.config.FilePath;
|
||||
import com.mir4updater.backend.entity.ApkInfo;
|
||||
import com.mir4updater.backend.entity.PatchFileInfo;
|
||||
import com.mir4updater.backend.entity.XapkManifest;
|
||||
import com.mir4updater.backend.result.Result;
|
||||
import com.mir4updater.backend.service.ApkInfoService;
|
||||
import com.mir4updater.backend.service.DiffPathService;
|
||||
import com.mir4updater.backend.utils.ApkUtils;
|
||||
import com.mir4updater.backend.utils.HashUtils;
|
||||
import com.mir4updater.backend.utils.PatchUtils;
|
||||
@@ -36,6 +38,9 @@ public class CreateDiffPatchFileController {
|
||||
@Autowired
|
||||
private ApkInfoService apkInfoService;
|
||||
|
||||
@Autowired
|
||||
DiffPathService diffPathService;
|
||||
|
||||
@PostMapping("/android/create_patch")
|
||||
public Result uploadApk(@RequestParam("old_id") int oldId, @RequestParam("new_id") int newId) throws Exception {
|
||||
String projectPath = System.getProperty("user.dir");
|
||||
@@ -112,6 +117,7 @@ public class CreateDiffPatchFileController {
|
||||
String sha256 = HashUtils.calculateSHA256(tempFile);
|
||||
logger.info("tempFile sha256 = " + sha256);
|
||||
|
||||
|
||||
if (ApkUtils.isAPK(tempFile)) {
|
||||
logger.info("tempFile type is apk");
|
||||
|
||||
@@ -129,6 +135,10 @@ public class CreateDiffPatchFileController {
|
||||
|
||||
String packageName = apkMeta.getPackageName();
|
||||
long versionCode = apkMeta.getVersionCode();
|
||||
PatchFileInfo patchFileInfo = diffPathService.getPatchInfo(packageName, versionCode, md5);
|
||||
if (patchFileInfo != null) {
|
||||
return Result.error("patch文件存在,请直接下载");
|
||||
}
|
||||
|
||||
List<ApkInfo> apkInfoList = apkInfoService.getApkInfo(packageName);
|
||||
Optional<ApkInfo> apkInfoOptional = apkInfoList.stream().max(new Comparator<ApkInfo>() {
|
||||
@@ -173,6 +183,7 @@ public class CreateDiffPatchFileController {
|
||||
return Result.error().setMessage(packageName + " 没有上传其他版本");
|
||||
}
|
||||
} else if (ApkUtils.isXAPK(tempFile)) {
|
||||
//一般不会出现这种情况
|
||||
logger.info("tempFile type is xapk");
|
||||
try (ZipFile zipFile = new ZipFile(tempFile)) {
|
||||
// 遍历ZIP文件中的所有条目
|
||||
|
||||
@@ -23,25 +23,25 @@ public class PatchFileInfo implements Serializable {
|
||||
long oldVersion;
|
||||
|
||||
@Column(name = "old_md5", nullable = false)
|
||||
String old_md5;
|
||||
String oldMd5;
|
||||
|
||||
@Column(name = "old_sha1", nullable = false)
|
||||
String old_sha1;
|
||||
String oldSha1;
|
||||
|
||||
@Column(name = "old_sha256", nullable = false)
|
||||
String old_sha256;
|
||||
String oldSha256;
|
||||
|
||||
@Column(name = "new_version", nullable = false)
|
||||
long newVersion;
|
||||
|
||||
@Column(name = "new_md5", nullable = false)
|
||||
String new_md5;
|
||||
String newMd5;
|
||||
|
||||
@Column(name = "new_sha1", nullable = false)
|
||||
String new_sha1;
|
||||
String newSha1;
|
||||
|
||||
@Column(name = "new_sha256", nullable = false)
|
||||
String new_sha256;
|
||||
String newSha256;
|
||||
|
||||
@Column(name = "patch_file_path", nullable = false)
|
||||
String patch_file_path;
|
||||
|
||||
@@ -4,6 +4,6 @@ import com.mir4updater.backend.entity.PatchFileInfo;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PatchInfoRepository extends JpaRepository<PatchFileInfo, Long> {
|
||||
public PatchFileInfo findPatchFileInfoByPackageNameAndOldVersion(String packageName, Long version);
|
||||
public PatchFileInfo findPatchFileInfoByPackageNameAndOldVersionAndOldMd5(String packageName, Long oldVersion, String oldMd5);
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ public class DiffPathService {
|
||||
@Autowired
|
||||
PatchInfoRepository patchInfoRepository;
|
||||
|
||||
public PatchFileInfo getPatchInfo(String packageName, Long oldVersion) {
|
||||
return patchInfoRepository.findPatchFileInfoByPackageNameAndOldVersion(packageName, oldVersion);
|
||||
public PatchFileInfo getPatchInfo(String packageName, Long oldVersion, String oldMd5) {
|
||||
return patchInfoRepository.findPatchFileInfoByPackageNameAndOldVersionAndOldMd5(packageName, oldVersion, oldMd5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user