public async Task <IActionResult> CopyFile(CopyFileAddressModel model) { var(sourceFolders, sourceFileName) = _folderSplitter.SplitToFoldersAndFile(model.FolderNames); var targetFolders = _folderSplitter.SplitToFolders(model.TargetFolderNames); var sourceFolder = await _folderRepo.GetFolderAsOwner(model.AccessToken, model.SiteName, sourceFolders); var targetFolder = await _folderRepo.GetFolderAsOwner(model.AccessToken, model.TargetSiteName, targetFolders, true); if (sourceFolder == null) { return(this.Protocol(ErrorType.NotFound, "Locate source folder failed!")); } if (targetFolder == null) { return(this.Protocol(ErrorType.NotFound, "Locate target folder failed!")); } var file = sourceFolder.Files.SingleOrDefault(t => t.FileName == sourceFileName); if (file == null) { return(this.Protocol(ErrorType.NotFound, "The file cannot be found. Maybe it has been deleted.")); } var fileName = _folderSplitter.GetValidFileName(targetFolder.Files.Select(t => t.FileName), file.FileName); await _fileRepo.CopyFile(fileName, file.FileSize, targetFolder.Id, file.HardwareId); var filePath = _probeLocator.GetProbeFullPath(model.TargetSiteName, string.Join('/', targetFolders), fileName); var internetPath = _probeLocator.GetProbeOpenAddress(filePath); return(Ok(new UploadFileViewModel { InternetPath = internetPath, SiteName = model.TargetSiteName, FilePath = filePath, FileSize = file.FileSize, Code = ErrorType.Success, Message = "Successfully copied your file." })); }