Ejemplo n.º 1
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.DeleteFileById(file.Id);

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