コード例 #1
0
        public async Task <IActionResult> Open(OpenAddressModel model)
        {
            var site = await _siteRepo.GetSiteByName(model.SiteName);

            if (site == null)
            {
                return(NotFound());
            }
            if (!site.OpenToDownload)
            {
                _tokenEnsurer.Ensure(model.PBToken, "Download", model.SiteName, model.FolderNames);
            }
            var(folders, fileName) = _folderSplitter.SplitToFoldersAndFile(model.FolderNames);
            try
            {
                var siteRoot = await _folderRepo.GetFolderFromId(site.RootFolderId);

                var folder = await _folderRepo.GetFolderFromPath(folders, siteRoot, false);

                if (folder == null)
                {
                    return(NotFound());
                }
                var file = await _fileRepo.GetFileInFolder(folder, fileName);

                if (file == null)
                {
                    return(NotFound());
                }
                var path      = _storageProvider.GetFilePath(file.HardwareId);
                var extension = _storageProvider.GetExtension(file.FileName);
                if (ControllerContext.ActionDescriptor.AttributeRouteInfo.Name == "File")
                {
                    return(this.WebFile(path, "do-not-open"));
                }
                else if (ControllerContext.ActionDescriptor.AttributeRouteInfo.Name == "Video")
                {
                    return(VideoPlayerWithFile(
                               probeLocator.GetProbeOpenAddress(model.SiteName, folders, fileName),
                               model.PBToken,
                               fileName));
                }
                else if (file.FileName.IsStaticImage() && Image.DetectFormat(path) != null)
                {
                    return(await FileWithImageCompressor(path, extension));
                }
                else
                {
                    return(this.WebFile(path, extension));
                }
            }
            catch (AiurAPIModelException e) when(e.Code == ErrorType.NotFound)
            {
                return(NotFound());
            }
        }
コード例 #2
0
        public async Task <IActionResult> DeleteFile(DeleteFileAddressModel model)
        {
            var(folders, fileName) = _folderSplitter.SplitToFoldersAndFile(model.FolderNames);
            var folder = await _folderRepo.GetFolderAsOwner(model.AccessToken, model.SiteName, folders);

            if (folder == null)
            {
                return(this.Protocol(ErrorType.NotFound, "Locate folder failed!"));
            }
            var file = await _fileRepo.GetFileInFolder(folder, fileName);

            if (file == null)
            {
                return(this.Protocol(ErrorType.NotFound, "The file cannot be found. Maybe it has been deleted."));
            }
            await _fileRepo.DeleteFile(file.Id);

            return(this.Protocol(ErrorType.Success, $"Successfully deleted the file '{file.FileName}'"));
        }