Exemplo n.º 1
0
        public async Task <IActionResult> DeleteFolder(string path)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageMedia) ||
                !await _authorizationService.AuthorizeAsync(User, Permissions.ManageAttachedMediaFieldsFolder, (object)path))
            {
                return(Forbid());
            }

            if (string.IsNullOrEmpty(path))
            {
                return(StatusCode(StatusCodes.Status403Forbidden, S["Cannot delete root media folder"]));
            }

            var mediaFolder = await _mediaFileStore.GetDirectoryInfoAsync(path);

            if (mediaFolder != null && !mediaFolder.IsDirectory)
            {
                return(StatusCode(StatusCodes.Status403Forbidden, S["Cannot delete path because it is not a directory"]));
            }

            if (await _mediaFileStore.TryDeleteDirectoryAsync(path) == false)
            {
                return(NotFound());
            }

            return(Ok());
        }
Exemplo n.º 2
0
        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);
                    }
                }
            }
        }
Exemplo n.º 3
0
        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.");
                }
            }
        }
 /// <summary>
 /// Removes the assets attached to a content item through an attached media field.
 /// </summary>
 /// <remarks>
 /// To be used by content handlers when the content item is deleted
 /// </remarks>
 public Task DeleteContentItemFolderAsync(ContentItem contentItem)
 {
     return(_fileStore.TryDeleteDirectoryAsync(GetContentItemFolder(contentItem)));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Removes the assets attached to a content item through an attached media field.
 /// </summary>
 /// <remarks>
 /// To be used by content handlers when the content item is deleted
 /// </remarks>
 public async Task DeleteContentItemFolder(ContentItem contentItem)
 {
     await _fileStore.TryDeleteDirectoryAsync(GetContentItemFolder(contentItem));
 }