Skip to content

Commit

Permalink
feat: fix paths
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina20 committed Sep 6, 2023
1 parent 0835b77 commit adbfd6d
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.crowdin.cli.commands.NewAction;
import com.crowdin.cli.commands.Outputter;
import com.crowdin.cli.properties.ProjectProperties;
import com.crowdin.cli.utils.Utils;
import com.crowdin.cli.utils.console.ConsoleSpinner;
import com.crowdin.client.screenshots.model.AddScreenshotRequest;
import com.crowdin.client.screenshots.model.Screenshot;
Expand Down Expand Up @@ -75,14 +76,16 @@ public void act(Outputter out, ProjectProperties properties, ClientScreenshot cl
request.setBranchId(branch.getId());
}
if (nonNull(pathToSourceFile)) {
final String normalizedPath = convertSlashesToUnix(Utils.sepAtStart(pathToSourceFile));
FileInfo fileInfo = project.getFileInfos().stream()
.filter(f -> pathToSourceFile.equals(f.getPath())).findFirst()
.filter(f -> normalizedPath.equals(f.getPath())).findFirst()
.orElseThrow(() -> new RuntimeException(String.format(RESOURCE_BUNDLE.getString("error.file_not_exists"), pathToSourceFile)));
request.setFileId(fileInfo.getId());
}
if (nonNull(directoryPath)) {
final String normalizedPath = convertSlashesToUnix(Utils.sepAtStart(directoryPath));
Directory directory = project.getDirectories().values().stream()
.filter(d -> directoryPath.equals(d.getPath())).findFirst()
.filter(d -> normalizedPath.equals(d.getPath())).findFirst()
.orElseThrow(() -> new RuntimeException(String.format(RESOURCE_BUNDLE.getString("error.dir_not_exists"), directoryPath)));
request.setDirectoryId(directory.getId());
}
Expand Down Expand Up @@ -117,4 +120,8 @@ private Long uploadToStorage(File fileToUpload) {
}
return storageId;
}

private String convertSlashesToUnix(String input) {
return input.replace("\\", "/");
}
}

0 comments on commit adbfd6d

Please sign in to comment.