|
@@ -1,6 +1,9 @@
|
|
|
using LJLib;
|
|
|
+using LJLib.Net.SPI.Com;
|
|
|
+using LJLib.Tools.Encry;
|
|
|
using LJProxy.LJLib.Net.SPI.Server;
|
|
|
using LJProxy.Models;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
@@ -9,26 +12,29 @@ using System.Threading.Tasks;
|
|
|
|
|
|
namespace LJProxy.Excutor
|
|
|
{
|
|
|
- public class GetUpdatePkgExcutor : ExcutorBase<GetUpdatePkgRequest, GetUpdatePkgResponse>
|
|
|
+ public class GetUpdatePkgExcutor : ExcutorBase<GetUpdatePkgRequest>
|
|
|
{
|
|
|
private static object _syncRoot = new object();
|
|
|
- protected override void ExcuteInternal(GetUpdatePkgRequest request, object state, GetUpdatePkgResponse rslt)
|
|
|
+
|
|
|
+
|
|
|
+ protected override IActionResult ExcuteInternal(GetUpdatePkgRequest request, object state)
|
|
|
{
|
|
|
+ GetUpdatePkgResponse rslt = new GetUpdatePkgResponse();
|
|
|
rslt.ErrCode = "0";
|
|
|
|
|
|
var apkDirs = @$"{AppDomain.CurrentDomain.BaseDirectory}apk\";
|
|
|
if (!Directory.Exists(apkDirs))
|
|
|
{
|
|
|
rslt.ErrMsg = "apk file folder not exists";
|
|
|
- return;
|
|
|
+ return new JsonResult(rslt);
|
|
|
}
|
|
|
|
|
|
//cache file version
|
|
|
- ApkInfo apkInfo = null;
|
|
|
+ GetUpdatePkgResponse apkInfo = null;
|
|
|
string cacheKey = "NewestApkData";
|
|
|
lock (_syncRoot)
|
|
|
{
|
|
|
- apkInfo = CacheHelper.DefaultCache.Get(cacheKey) as ApkInfo;
|
|
|
+ apkInfo = Cache.DefaultCache.Get(cacheKey) as GetUpdatePkgResponse;
|
|
|
if (apkInfo == null)
|
|
|
{
|
|
|
var dirinfo = new DirectoryInfo(apkDirs);
|
|
@@ -38,7 +44,7 @@ namespace LJProxy.Excutor
|
|
|
if (file == null)
|
|
|
{
|
|
|
rslt.ErrMsg = "can not found apk";
|
|
|
- return;
|
|
|
+ return new JsonResult(rslt);
|
|
|
}
|
|
|
|
|
|
byte[] apkData = null;
|
|
@@ -58,23 +64,22 @@ namespace LJProxy.Excutor
|
|
|
}
|
|
|
|
|
|
APKHelper apkHelper = new APKHelper();
|
|
|
+ var md5Helper = new MD5();
|
|
|
var clientVer = apkHelper.GetVersionName(apkData);
|
|
|
- apkInfo = new ApkInfo();
|
|
|
+ apkInfo = new GetUpdatePkgResponse();
|
|
|
apkInfo.Version = clientVer;
|
|
|
apkInfo.ApkData = apkData;
|
|
|
+ apkInfo.Checksum = md5Helper.GetMD5(apkData);
|
|
|
//TODO:文件夹缓存依赖不生效,待扩展
|
|
|
- CacheHelper.DefaultCache.Add(cacheKey, apkInfo, CacheHelper.CreateCacheItemPolicy(null, DateTime.Now.AddMinutes(30), new List<string>() { file.FullName }));
|
|
|
+ Cache.DefaultCache.Add(cacheKey, apkInfo, Cache.CreateCacheItemPolicy(null, DateTime.Now.AddMinutes(30), new List<string>() { file.FullName }));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
rslt.Version = apkInfo.Version;
|
|
|
rslt.ApkData = apkInfo.ApkData;
|
|
|
+ rslt.Checksum = apkInfo.Checksum;
|
|
|
+ return new JsonResult(rslt);
|
|
|
}
|
|
|
|
|
|
- public class ApkInfo
|
|
|
- {
|
|
|
- public string Version { get; set; }
|
|
|
- public byte[] ApkData { get; set; }
|
|
|
- }
|
|
|
}
|
|
|
}
|