using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.StaticFiles; using Procurement.Enums; using Volo.Abp.AspNetCore.Mvc; using Procurement.ViewModel; using Procurement.Helpers; using Microsoft.AspNetCore.Hosting; using System.Runtime.InteropServices; namespace Procurement.Controllers { [Produces("application/json")] [Route("api/[controller]")] public class FileController : AbpController { private readonly IWebHostEnvironment _hostEnvironment; public FileController(IWebHostEnvironment hostEnvironment) { _hostEnvironment = hostEnvironment; } [Route("version")] [HttpGet] public async Task Get(string app = "sfm") { ResultCode code = ResultCode.Fail, subCode = ResultCode.Fail; string subMsg = ""; string contentRootPath = _hostEnvironment.ContentRootPath; string file = "version.txt"; string pathSymbol = "\\"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { pathSymbol = "//"; } var filePath = contentRootPath + pathSymbol + "release" + pathSymbol + app + pathSymbol + file; string version = "1.0.0"; try { if (System.IO.File.Exists(filePath)) { version = await System.IO.File.ReadAllTextAsync(filePath); code = ResultCode.Success; } } catch (Exception ex) { } ResultViewModel result = ResultHelper.CreateResult(code, version, subCode, subMsg); return Ok(result); } [Route("download")] [HttpGet] public FileResult downloadApk(string app = "sfm") { string contentRootPath = _hostEnvironment.ContentRootPath; string pathSymbol = "\\"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { pathSymbol = "//"; } string file = "app-" + app + "-release.apk"; var addrUrl = contentRootPath + pathSymbol + "release" + pathSymbol + app + pathSymbol + file; var stream = System.IO.File.OpenRead(addrUrl); string fileExt = Path.GetExtension(file); //获取文件的ContentType var provider = new FileExtensionContentTypeProvider(new Dictionary { { ".apk","application/vnd.android.package-archive"}, }); var mime = provider.Mappings[fileExt]; return File(stream, mime, Path.GetFileName(addrUrl)); } } }