| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 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<IActionResult> 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<string, string>
- {
- { ".apk","application/vnd.android.package-archive"},
- });
- var mime = provider.Mappings[fileExt];
- return File(stream, mime, Path.GetFileName(addrUrl));
- }
- }
- }
|