Пример #1
0
        /// <summary>
        /// 获取文件信息
        /// </summary>
        /// <param name="md5">md5</param>
        /// <returns></returns>
        public IResponseOutput GetFile(string md5)
        {
            var sysFile = _sysFileManager.GetForMd5(md5);
            var result  = _mapper.Map <SysFileOutputDto>(sysFile);

            return(Ok(result));
        }
Пример #2
0
        public IActionResult Download(string md5, string token)
        {
            if (!CheckReferer())
            {
                _logger.LogError($"非安全域名访问:{GetHost()}");
                return(new StatusCodeResult((int)HttpStatusCode.NotAcceptable));
            }

            var jwthandle = new JwtSecurityTokenHandler();

            if (string.IsNullOrEmpty(token) || !jwthandle.CanReadToken(token))
            {
                _logger.LogInformation($"非法下载:{md5}!");
                return(new StatusCodeResult((int)HttpStatusCode.NonAuthoritativeInformation));
            }

            var paramters = JwtHelper.GetParameters(_jwtConfig);

            jwthandle.ValidateToken(token, paramters, out SecurityToken sToekn);
            if (sToekn == null)
            {
                _logger.LogInformation($"非法下载:{md5}!");
                return(new StatusCodeResult((int)HttpStatusCode.NonAuthoritativeInformation));
            }

            var file = _sysFileManager.GetForMd5(md5);

            if (file == null)
            {
                _logger.LogError($"文件不存在:{md5}!");
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }
            var path = Path.Combine(_appConfig.FilePath, file.FileDate, file.CreatedUserId.ToString(), $"{md5}{Path.GetExtension(file.FileName)}");

            if (!IoFile.Exists(path))
            {
                _logger.LogError($"文件不存在:{md5}!");
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }
            new FileExtensionContentTypeProvider().Mappings.TryGetValue(Path.GetExtension(path), out var contenttype);
            var stream = IoFile.OpenRead(path);

            return(File(stream, contenttype ?? "application/octet-stream", file.FileName));
        }