@@ -145,7 +145,7 @@ public void upload(String channelId, UploadDTO uploadDTO) {
145
145
try (Stream <Path > paths = Files .walk (file .toPath ())) {
146
146
paths .forEach ((path -> {
147
147
File internalFile = path .toFile ();
148
- String relativePath = transformSeparators (StrUtil .subAfter (FileUtil .getCanonicalPath (internalFile ), FileUtil .getAbsolutePath (file .getParentFile ()), true ), separator );
148
+ String relativePath = transformFileSeparators (StrUtil .subAfter (FileUtil .getCanonicalPath (internalFile ), FileUtil .getAbsolutePath (file .getParentFile ()), true ), separator );
149
149
if (!relativePath .startsWith (separator )) {
150
150
relativePath = separator + relativePath ;
151
151
}
@@ -181,37 +181,13 @@ public static String separatorsToWindows(String path) {
181
181
return path != null && path .indexOf (47 ) != -1 ? path .replace ('/' , '\\' ) : path ;
182
182
}
183
183
184
- public static String transformSeparators (String path , String separators ) {
184
+ public static String transformFileSeparators (String path , String separators ) {
185
185
if (path == null ) {
186
186
return null ;
187
187
} else {
188
188
return separators .indexOf (92 ) != -1 ? separatorsToWindows (path ) : separatorsToUnix (path );
189
189
}
190
190
}
191
- /* public String convertSeparators(String path,String separator){
192
- PathUtils
193
-
194
- String s3=s2.indexOf(90) != -1?s2.replace(, '/'):;
195
- if(s2.indexOf(47) != -1 ){
196
- s3= s2.replace('\\', '/');
197
- }
198
- // 不是 Windows //
199
- if(path.indexOf(47) != -1 ){
200
- return path.replace('\\', '/') : path;
201
- }
202
-
203
- String tempPath=path;
204
- String tempSeparator=separator;
205
- if(path.indexOf(47) != -1 ){
206
- return path.replace('\\', '/') ;
207
- }else {
208
-
209
-
210
- }
211
-
212
-
213
-
214
- }*/
215
191
216
192
217
193
public void removeFile (String channelId , String path ) {
@@ -242,7 +218,7 @@ public void download(String channelId, String path,boolean isDirectory) {
242
218
FileManager fileManager = getFileManager (channelId );
243
219
if (isDirectory ){
244
220
fileManager .fileInfos (path ).forEach (fileInfo -> {
245
- String relativePath = transformSeparators (StrUtil .subAfter (fileInfo .path (),path , true ), File .separator );
221
+ String relativePath = transformFileSeparators (StrUtil .subAfter (fileInfo .path (),path , true ), File .separator );
246
222
String completePath = Path .of (savePath , relativePath ).toString ();
247
223
if (fileInfo .type () == FileType .DIRECTORY ) {
248
224
FileUtil .mkdir (completePath );
@@ -541,14 +517,17 @@ public TransferCountVO getTransferTaskCount(String channelId) {
541
517
}
542
518
543
519
520
+
521
+
544
522
public void openFile (String channelId , String path ) {
545
523
546
524
String fileName = FileUtil .getName (path );
547
- String savePath = Path .of (tempDir , fileName ).toString ();
548
525
549
526
TtyConnector tyConnector = getTyConnector (channelId );
550
527
FileManager fileManager = tyConnector .getFileManager ();
551
- String id = "%s-%s" .formatted (tyConnector .getSessionId (), path );
528
+
529
+ String id = "%s-%s" .formatted (tyConnector .getSessionId (), pathEncode (path ));
530
+ String savePath = Path .of (tempDir , id ).toString ();
552
531
553
532
tempFileInfoCache .remove (id );
554
533
long size = fileManager .getSize (path );
@@ -574,6 +553,7 @@ public void openFile(String channelId, String path) {
574
553
}
575
554
WebSocket .sendMsg (channelId , WebSocket .MsgType .OPEN_FILE_PROGRESS , objectMapper .writeValueAsString (new Progress (100.00 , channelId , fileName , TransferRecord .Status .COMPLETE , id )));
576
555
WebSocket .sendMsg (channelId , WebSocket .MsgType .OPEN_FILE , savePath );
556
+
577
557
tempFileInfoCache .put (id , new TempInfo (channelId , savePath , path ));
578
558
watchTempFile ();
579
559
} catch (IOException e ) {
@@ -622,4 +602,8 @@ public void onModify(WatchEvent<?> event, Path currentPath) {
622
602
public void deleteTempDir () {
623
603
FileUtil .del (tempDir );
624
604
}
605
+
606
+ public String pathEncode (String path ){
607
+ return path .indexOf (47 ) != -1 ? path .replace ('/' , '%' ) : path .replace ('\\' , '%' );
608
+ }
625
609
}
0 commit comments