|
@@ -22,16 +22,16 @@ import com.qmth.teachcloud.common.enums.clientpackage.ClientPackageEnum;
|
|
|
import com.qmth.teachcloud.common.service.FileUploadService;
|
|
|
import com.qmth.teachcloud.common.util.FileUtil;
|
|
|
import com.qmth.teachcloud.common.util.Zip4jUtil;
|
|
|
+import okio.Buffer;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.io.*;
|
|
|
import java.util.Objects;
|
|
|
import java.util.StringJoiner;
|
|
|
import java.util.zip.ZipEntry;
|
|
@@ -81,8 +81,15 @@ public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, C
|
|
|
clientUpgrade.setInstallPath(JSON.toJSONString(filePathVo));
|
|
|
clientUpgrade.setInstallUploadTime(System.currentTimeMillis());
|
|
|
} else if (ClientPackageEnum.UPGRADE.equals(type)) {
|
|
|
+ // 升级包文件上传
|
|
|
+ parentDirVar = SystemConstant.getFileTempDirVar(SystemConstant.ZIP_PREFIX);
|
|
|
+// file.transferTo(parentDirVar);
|
|
|
+ FileUtils.copyToFile(file.getInputStream(), parentDirVar);
|
|
|
+ ZipReader zipReader1 = new ZipReader(parentDirVar);
|
|
|
+ String mainfestJson = "mainfest.json";
|
|
|
+
|
|
|
// 读取指定文件内容mainfest.josn
|
|
|
- String mainfestContent = readMainfest(file.getInputStream());
|
|
|
+ String mainfestContent = readMainfest(zipReader1.read(mainfestJson));
|
|
|
if (StringUtils.isBlank(mainfestContent)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("读取mainfest.json文件内容失败");
|
|
|
}
|
|
@@ -108,12 +115,8 @@ public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, C
|
|
|
clientUpgrade.setSupportMin(supportMin);
|
|
|
clientUpgrade.setUpgradePath(JSON.toJSONString(filePathVo));
|
|
|
|
|
|
- // 升级包文件上传
|
|
|
- parentDirVar = SystemConstant.getFileTempDirVar(SystemConstant.ZIP_PREFIX);
|
|
|
- file.transferTo(parentDirVar);
|
|
|
- ZipReader zipReader = new ZipReader(parentDirVar);
|
|
|
// 上传mainfest.json文件
|
|
|
- String mainfestJson = "mainfest.json";
|
|
|
+ ZipReader zipReader = new ZipReader(parentDirVar);
|
|
|
String mainfestPathName = buildPath(true, UploadFileEnum.UPGRADE.getTitle(), "update", platform, version, String.valueOf(build)) + mainfestJson;
|
|
|
FilePathVo mainfestPathVo = fileUploadService.uploadFile(zipReader.read(mainfestJson), UploadFileEnum.UPGRADE, mainfestPathName, DigestUtils.md5Hex(zipReader.read(mainfestJson)));
|
|
|
clientUpgrade.setMainfestPath(JSON.toJSONString(mainfestPathVo));
|
|
@@ -218,29 +221,19 @@ public class ClientUpgradeServiceImpl extends ServiceImpl<ClientUpgradeMapper, C
|
|
|
* @param inputStream 文件流
|
|
|
*/
|
|
|
private static String readMainfest(InputStream inputStream) {
|
|
|
- String jsonContent = null;
|
|
|
- try (ZipInputStream zipInputStream = new ZipInputStream(inputStream)) {
|
|
|
- ZipEntry zipEntry;
|
|
|
-
|
|
|
- while ((zipEntry = zipInputStream.getNextEntry()) != null) {
|
|
|
- String entryName = zipEntry.getName();
|
|
|
- if (entryName.equals(MAIN_FEST_JSON)) {
|
|
|
- // 读取目标文件的内容
|
|
|
- StringBuilder content = new StringBuilder();
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
- int length;
|
|
|
- while ((length = zipInputStream.read(buffer)) > 0) {
|
|
|
- content.append(new String(buffer, 0, length));
|
|
|
- }
|
|
|
- jsonContent = content.toString();
|
|
|
- break;
|
|
|
- }
|
|
|
- zipInputStream.closeEntry();
|
|
|
+ try {
|
|
|
+ // 读取目标文件的内容
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int length;
|
|
|
+ while ((length = inputStream.read(buffer)) > 0) {
|
|
|
+ content.append(new String(buffer, 0, length));
|
|
|
}
|
|
|
+ return content.toString();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return jsonContent;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|