Exemplo n.º 1
0
        public async Task DownloadFile(FileViewInfo info, string path)
        {
            try
            {
                //if (info.IsFolder == "Visible")
                //{
                //    string folderNamePath = Path.GetDirectoryName(info.OriginalPath);
                //    if (!string.IsNullOrEmpty(folderNamePath))
                //    {
                //        //var strArray = folderNamePath.Split('\\');
                //        //for (int i = 0; i < strArray.Length; i++)
                //        //{
                //        //    if (lstFile.Exists(f => f.Level == i && f.FileName == strArray[i]))
                //        //    {
                //        //        continue;
                //        //    }
                //        //}
                //        if (!Directory.Exists(folderNamePath))
                //        {
                //            string pathString = System.IO.Path.Combine(path, folderNamePath);
                //            //var dirInfo = Directory.CreateDirectory(Path.Combine(path, folderNamePath));
                //            System.IO.Directory.CreateDirectory(pathString);
                //        }
                //    }
                //    return;
                //}
                BlobClient blob       = _blobContainer.GetBlobClient(info.OriginalPath);
                string     input      = info.OriginalPath;
                string     namefile   = "";
                string     pathfolder = "";
                var        leng       = input.Length;
                int        index      = input.LastIndexOf("/");
                if (index > 0)
                {
                    namefile   = input.Substring(index + 1, leng - (index + 1));
                    pathfolder = input.Substring(0, (index + 1));
                }
                string pathString = System.IO.Path.Combine(path, pathfolder).Replace("/", "\\");
                //var dirInfo = Directory.CreateDirectory(Path.Combine(path, folderNamePath));
                System.IO.Directory.CreateDirectory(pathString);

                Stream file = File.OpenWrite(Path.Combine(pathString, namefile.Length == 0 ? info.OriginalPath : namefile));
                await blob.DownloadToAsync(file);

                file.Close();
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(string shareId)
        {
            if (string.IsNullOrWhiteSpace(shareId))
            {
                return(NotFound());
            }

            ShareName = shareId;

            (ShareHelper.AccessStatus allowed, Share share) = await ShareHelper.CanAccess(HttpContext, database, shareId);

            if (share != null && !share.DontTrack)
            {
                database.Visits.Add(new()
                {
                    Access    = allowed,
                    Date      = DateTime.Now,
                    IP        = Request.Headers["X-Forwarded-For"],
                    UserAgent = Request.Headers["User-Agent"],
                    Share     = share,
                    User      = userManager.GetUser(HttpContext)
                });
                await database.SaveChangesAsync();
            }

            if (allowed == ShareHelper.AccessStatus.Denied)
            {
                await database.SaveChangesAsync();

                return(NotFound());
            }

            share.LastAccessed = DateTime.Now;

            await database.SaveChangesAsync();

            IsOwner = allowed == ShareHelper.AccessStatus.Owner;

            FileId  = share.File.Id;
            ShareId = share.Id;

            FileViewInfo = new FileViewInfo()
            {
                FileName   = share.File.Filename + "." + share.File.Extension,
                SourcePath = "/d/" + shareId
            };
            return(Page());
        }
Exemplo n.º 3
0
        public IActionResult OnGet(string fileId)
        {
            Models.File file = userManager.GetUser(HttpContext).Files.FirstOrDefault(f => f.Identifier == fileId);
            if (file is null)
            {
                return(NotFound());
            }
            FileIdentifier = fileId;
            FileId         = file.Id;

            FileViewInfo = new FileViewInfo()
            {
                FileName   = file.Filename + "." + file.Extension,
                SourcePath = "/Account/Files/d/" + fileId
            };

            return(Page());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnGet(string fileId)
        {
            Models.File file = await database.Files.FirstOrDefaultAsync(f => f.Identifier == fileId);

            if (file is null)
            {
                return(NotFound());
            }
            FileIdentifier = fileId;
            FileId         = file.Id;

            FileViewInfo = new FileViewInfo()
            {
                FileName   = file.Filename + "." + file.Extension,
                SourcePath = "/Account/Files/d/" + fileId
            };

            return(Page());
        }