Ejemplo n.º 1
0
        public async Task <IActionResult> ViewFiles(int id)//Bucket Id
        {
            var cuser = await GetCurrentUserAsync();

            var bucketInfo = await ApiService.ViewBucketDetailAsync(id);

            if (bucketInfo.BelongingAppId == null)
            {
                return(NotFound());
            }
            var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId);

            var files = await ApiService.ViewAllFilesAsync(await AppsContainer.AccessToken(app.AppId, app.AppSecret)(), id);

            var model = new ViewFilesViewModel(cuser)
            {
                BucketId   = files.BucketId,
                AllFiles   = files.AllFiles,
                AppId      = app.AppId,
                OpenToRead = bucketInfo.OpenToRead,
                BucketName = bucketInfo.BucketName
            };

            return(View(model));
        }
        public async Task <IActionResult> ViewFiles(string path, bool justHaveUpdated)
        {
            var user = await GetCurrentUserAsync();

            if (string.IsNullOrWhiteSpace(user.SiteName))
            {
                return(RedirectToAction(nameof(CreateSite)));
            }
            try
            {
                var data = await _foldersService.ViewContentAsync(await accesstoken, user.SiteName, path);

                var model = new ViewFilesViewModel(user)
                {
                    Folder          = data.Value,
                    Path            = path,
                    SiteName        = user.SiteName,
                    JustHaveUpdated = justHaveUpdated
                };
                return(View(model));
            }
            catch (AiurUnexceptedResponse e) when(e.Code == ErrorType.NotFound)
            {
                return(NotFound());
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> ViewFiles(string appId, string siteName, string path) // siteName
        {
            var user = await GetCurrentUserAsync();

            var app = await _dbContext.Apps.FindAsync(appId);

            if (app == null)
            {
                return(NotFound());
            }
            if (app.CreatorId != user.Id)
            {
                return(Unauthorized());
            }
            try
            {
                var token = await _appsContainer.AccessToken(app.AppId, app.AppSecret);

                var data = await _foldersService.ViewContentAsync(token, siteName, path);

                var model = new ViewFilesViewModel(user)
                {
                    Folder   = data.Value,
                    AppId    = appId,
                    SiteName = siteName,
                    Path     = path
                };
                return(View(model));
            }
            catch (AiurUnexceptedResponse e) when(e.Code == ErrorType.NotFound)
            {
                return(NotFound());
            }
        }
        public async Task <IActionResult> Files(string fileId = null)
        {
            var fileUrl = string.IsNullOrEmpty(fileId) ? null : await _FileService.GetFileUrl(Request.GetAbsoluteRootUri(), fileId);

            var model = new ViewFilesViewModel()
            {
                Files             = await _StoredFileRepository.GetFiles(),
                SelectedFileId    = string.IsNullOrEmpty(fileUrl) ? null : fileId,
                DirectFileUrl     = fileUrl,
                StorageConfigured = (await _SettingsRepository.GetSettingAsync <StorageSettings>()) != null
            };

            return(View(model));
        }
        public async Task <IActionResult> Files([FromQuery] string[] fileIds = null)
        {
            var model = new ViewFilesViewModel()
            {
                Files             = await _StoredFileRepository.GetFiles(),
                DirectUrlByFiles  = null,
                StorageConfigured = (await _SettingsRepository.GetSettingAsync <StorageSettings>()) != null
            };

            if (fileIds != null && fileIds.Length > 0)
            {
                bool allFilesExist = true;
                Dictionary <string, string> directUrlByFiles = new Dictionary <string, string>();
                foreach (string filename in fileIds)
                {
                    string fileUrl = await _FileService.GetFileUrl(Request.GetAbsoluteRootUri(), filename);

                    if (fileUrl == null)
                    {
                        allFilesExist = false;
                        break;
                    }
                    directUrlByFiles.Add(filename, fileUrl);
                }

                if (!allFilesExist)
                {
                    this.TempData.SetStatusMessageModel(new StatusMessageModel()
                    {
                        Message  = "Some of the files were not found",
                        Severity = StatusMessageModel.StatusSeverity.Warning,
                    });
                }
                else
                {
                    model.DirectUrlByFiles = directUrlByFiles;
                }
            }
            return(View(model));
        }