public async Task <ActionResult <IEnumerable <IFileStoreEntry> > > GetFolders(string path) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageMedia)) { return(Forbid()); } if (string.IsNullOrEmpty(path)) { path = ""; } if (await _mediaFileStore.GetDirectoryInfoAsync(path) == null) { return(NotFound()); } var content = (await _mediaFileStore.GetDirectoryContentAsync(path)).Where(x => x.IsDirectory); var allowed = new List <IFileStoreEntry>(); foreach (var entry in content) { if ((await _authorizationService.AuthorizeAsync(User, Permissions.ManageAttachedMediaFieldsFolder, (object)entry.Path))) { allowed.Add(entry); } } return(allowed.ToArray()); }
public async Task <IActionResult> DeleteFolder(string path) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageOwnMedia)) { return(Unauthorized()); } if (string.IsNullOrEmpty(path)) { return(StatusCode(StatusCodes.Status403Forbidden, T["Cannot delete root media folder"])); } var mediaFolder = await _mediaFileStore.GetDirectoryInfoAsync(path); if (mediaFolder != null && !mediaFolder.IsDirectory) { return(StatusCode(StatusCodes.Status403Forbidden, T["Cannot delete path because it is not a directory"])); } if (await _mediaFileStore.TryDeleteDirectoryAsync(path) == false) { return(NotFound()); } return(Ok()); }
public async Task ActivatedAsync() { if (_shellSettings.State != Environment.Shell.Models.TenantState.Uninitialized) { var tempDir = _attachedMediaFieldFileService.MediaFieldsTempSubFolder; if (await _fileStore.GetDirectoryInfoAsync(tempDir) == null) { return; } var contents = await _fileStore.GetDirectoryContentAsync(tempDir); foreach (var c in contents) { var result = c.IsDirectory ? await _fileStore.TryDeleteDirectoryAsync(c.Path) : await _fileStore.TryDeleteFileAsync(c.Path); if (!result) { _logger.LogWarning("Temporary entry {0} could not be deleted.", c.Path); } } } }
public override IDisplayResult Display(AtlasPart part, BuildPartDisplayContext context) { return(Initialize <AtlasPartViewModel>("AtlasPart", async model => { var pager = new PagerParameters() { Page = 1, PageSize = part.PageSize }; await context.Updater.TryUpdateModelAsync(pager); var count = (pager.Page - 1) * pager.PageSize; int totalCount = 0; if (await _mediaFileStore.GetDirectoryInfoAsync(part.Path) != null) { var files = _mediaFileStore.GetDirectoryContentAsync(part.Path); totalCount = await files.Where(x => !x.IsDirectory).CountAsync(); model.Medias = await files.Reverse() .Where(x => !x.IsDirectory) .Skip(Math.Max(0, count.Value)) .Take(pager.PageSize.Value) .Select(x => new Media() { Name = x.Name, Path = x.Path }) .ToListAsync(); } model.Cover = part.Cover; model.Path = part.Path; model.Name = part.Name; model.PageSize = part.PageSize; model.UseAtlas = part.UseAtlas; model.Description = part.Description; model.ContentItem = part.ContentItem; model.Pager = (await context.New.Pager(pager)).TotalItemCount(totalCount); }).Location("Detail", "Content:2")); }
public async Task ActivatedAsync() { if (_shellSettings.State == TenantState.Running) { try { var tempDir = _attachedMediaFieldFileService.MediaFieldsTempSubFolder; if (await _fileStore.GetDirectoryInfoAsync(tempDir) == null) { return; } await foreach (var c in _fileStore.GetDirectoryContentAsync(tempDir)) { var result = c.IsDirectory ? await _fileStore.TryDeleteDirectoryAsync(c.Path) : await _fileStore.TryDeleteFileAsync(c.Path); if (!result) { _logger.LogWarning("Temporary entry {Path} could not be deleted.", c.Path); } } } catch (Exception e) { _logger.LogError(e, "An error occurred while cleaning temporary media folder."); } } }
private async Task DeleteDirIfEmptyAsync(string previousDirPath) { if (await _fileStore.GetDirectoryInfoAsync(previousDirPath) == null) { return; } if (!(await _fileStore.GetDirectoryContentAsync(previousDirPath)).Any()) { await _fileStore.TryDeleteDirectoryAsync(previousDirPath); } }
public async Task <ActionResult <IEnumerable <IFileStoreEntry> > > GetFolders(string path) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageMedia)) { return(Forbid()); } if (string.IsNullOrEmpty(path)) { path = ""; } if (await _mediaFileStore.GetDirectoryInfoAsync(path) == null) { return(NotFound()); } // create default folders if not exist if (await _authorizationService.AuthorizeAsync(User, Permissions.ManageOwnMedia) && await _mediaFileStore.GetDirectoryInfoAsync(_mediaFileStore.Combine(_mediaOptions.AssetsUsersFolder, _userAssetFolderNameProvider.GetUserAssetFolderName(User))) == null) { await _mediaFileStore.TryCreateDirectoryAsync(_mediaFileStore.Combine(_mediaOptions.AssetsUsersFolder, _userAssetFolderNameProvider.GetUserAssetFolderName(User))); } var allowed = _mediaFileStore.GetDirectoryContentAsync(path) .WhereAwait(async e => e.IsDirectory && await _authorizationService.AuthorizeAsync(User, Permissions.ManageMediaFolder, (object)e.Path)); return(Ok(await allowed.ToListAsync())); }
public async Task <IActionResult> GetFolders(string path) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageOwnMedia)) { return(Unauthorized()); } if (string.IsNullOrEmpty(path)) { path = ""; } if (await _mediaFileStore.GetDirectoryInfoAsync(path) == null) { return(NotFound()); } var content = (await _mediaFileStore.GetDirectoryContentAsync(path)).Where(x => x.IsDirectory); return(Json(content.ToArray())); }
public async Task <ActionResult <IEnumerable <IFileStoreEntry> > > GetFolders(string path) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageMedia)) { return(Forbid()); } if (string.IsNullOrEmpty(path)) { path = ""; } if (await _mediaFileStore.GetDirectoryInfoAsync(path) == null) { return(NotFound()); } var allowed = _mediaFileStore.GetDirectoryContentAsync(path) .WhereAwait(async e => e.IsDirectory && await _authorizationService.AuthorizeAsync(User, Permissions.ManageAttachedMediaFieldsFolder, (object)e.Path)); return(Ok(await allowed.ToListAsync())); }