@@ -62,7 +62,7 @@ public Mono<Void> doImportFilesFromAListPath(List<String> paths) {
6262 // 获取导入的父目录ID,不存在则创建
6363 .switchIfEmpty (attachmentOperate .createDirectory (AttachmentConst .ROOT_DIRECTORY_ID , AListConst .Attachment .DEFAULT_PARENT_NAME ))
6464 .map (Attachment ::getId )
65- .flatMap (rootParentId -> mkdirByLastPath (paths , rootParentId ))
65+ .flatMap (rootParentId -> mkdirByLastPath (new ArrayList <>( paths ) , rootParentId ))
6666 .flatMap (parentId -> createAttachmentRecursively (paths , parentId ));
6767 }
6868
@@ -124,6 +124,7 @@ public AListAttachment[] fetchAttachments(List<String> paths) {
124124 ApiResult apiResult = responseEntity .getBody ();
125125 if (apiResult != null && apiResult .getCode () == 200 ) {
126126 Object content = apiResult .getData ().get ("content" );
127+ if (content == null ) return new AListAttachment [0 ];
127128 return JsonUtils .obj2Arr (content , new TypeReference <AListAttachment []>() {
128129 });
129130 } else {
@@ -136,16 +137,27 @@ public AListAttachment[] fetchAttachments(List<String> paths) {
136137 return new AListAttachment [0 ];
137138 }
138139
139- private Mono <Long > mkdirByLastPath (List <String > paths , Long parentId ) {
140- String dirName = paths .get (paths .size () - 1 );
140+ private Mono <Attachment > mkdirWithNameAndParentId (String dirName , Long parentId ) {
141141 if (dirName .startsWith ("/" )) dirName = dirName .substring (1 );
142142 if (dirName .endsWith ("/" )) dirName = dirName .substring (0 , dirName .length () - 1 );
143143 return attachmentOperate .findByTypeAndParentIdAndName (AttachmentType .Directory , parentId , dirName )
144144 .switchIfEmpty (attachmentOperate .createDirectory (parentId , dirName ))
145145 .flatMap (attachment -> attachmentOperate .findByTypeAndParentIdAndName (
146146 attachment .getType (), attachment .getParentId (), attachment .getName ()
147- ))
148- .map (Attachment ::getId );
147+ ));
148+ }
149+
150+ private Mono <Long > mkdirByLastPath (List <String > paths , Long parentId ) {
151+ final int size = paths .size ();
152+ String name = paths .remove (0 );
153+ if (size > 1 ) {
154+ return mkdirWithNameAndParentId (name , parentId )
155+ .map (Attachment ::getId )
156+ .flatMap (id -> mkdirByLastPath (paths , id ));
157+ } else {
158+ return mkdirWithNameAndParentId (name , parentId )
159+ .map (Attachment ::getId );
160+ }
149161 }
150162
151163 private Mono <AListAttachment > saveAListAttachment (AListAttachment aListAttachment ) {
0 commit comments