public async Task DeleteAttachedMediaItem(string mediaPathUrl) { // var path = _fileStore.MapPathToPublicUrl(mediaPathPublicUrl); if (mediaPathUrl.ToLower().StartsWith("/media")) { //because IMediaFileStore has a prefix /media we need to remove it if its part of the path //strip out /media prefix mediaPathUrl = mediaPathUrl.ReplaceFirst("/media", ""); } await _fileStore.TryDeleteFileAsync(mediaPathUrl); //TryDeleteDirectoryAsync(GetContentItemFolder(contentItem)); }
// Files just uploaded and then immediately discarded. private async Task RemoveTemporaryAsync(List <EditMediaFieldItemInfo> items) { foreach (var item in items.Where(i => i.IsRemoved && i.IsNew)) { await _fileStore.TryDeleteFileAsync(item.Path); } }
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 async Task <IActionResult> DeleteMediaList(string[] paths) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageMedia)) { return(Unauthorized()); } foreach (var path in paths) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAttachedMediaFieldsFolder, (object)path)) { return(Unauthorized()); } } if (paths == null) { return(NotFound()); } foreach (var p in paths) { if (await _mediaFileStore.TryDeleteFileAsync(p) == false) { return(NotFound()); } } return(Ok()); }
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."); } } }
public async Task <IActionResult> DeleteMedia(string path) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageOwnMedia)) { return(Unauthorized()); } if (string.IsNullOrEmpty(path)) { return(NotFound()); } if (await _mediaFileStore.TryDeleteFileAsync(path) == false) { return(NotFound()); } return(Ok()); }
public async Task <IActionResult> DeleteMedia(string path) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageMedia) || !await _authorizationService.AuthorizeAsync(User, Permissions.ManageAttachedMediaFieldsFolder, (object)path)) { return(Forbid()); } if (string.IsNullOrEmpty(path)) { return(NotFound()); } if (await _mediaFileStore.TryDeleteFileAsync(path) == false) { return(NotFound()); } return(Ok()); }
public async Task <IActionResult> DeleteMedia(string path) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageOwnMedia)) { return(Unauthorized()); } if (string.IsNullOrEmpty(path)) { return(NotFound()); } var media = await _mediaFileStore.GetFileAsync(path); if (media == null || media.IsDirectory) { return(NotFound()); } await _mediaFileStore.TryDeleteFileAsync(path); return(Ok()); }
// Files just uploaded and then inmediately discarded. private void RemoveTemporary(List <EditMediaFieldItemInfo> items) { items.Where(x => x.IsRemoved && x.IsNew).ToList().ForEach(async x => await _fileStore.TryDeleteFileAsync(x.Path)); }