2525import run .ikaros .api .store .enums .AttachmentType ;
2626import run .ikaros .plugin .alist .AListConst .ConfigMapKey ;
2727
28- import java .net .URLDecoder ;
29- import java .nio .charset .StandardCharsets ;
3028import java .time .Duration ;
3129import java .time .LocalDateTime ;
3230import java .util .*;
@@ -142,18 +140,22 @@ private Mono<Long> mkdirByLastPath(List<String> paths, Long parentId) {
142140 }
143141
144142 private Mono <AListAttachment > saveAListAttachment (AListAttachment aListAttachment ) {
145- return attachmentOperate .save (
143+ AttachmentType type = aListAttachment .getIs_dir () ? AttachmentType .Directory : AttachmentType .File ;
144+ return attachmentOperate .existsByTypeAndParentIdAndName (type ,
145+ aListAttachment .getParentId (), aListAttachment .getName ())
146+ .filter (exists -> !exists )
147+ .flatMap (exists -> attachmentOperate .save (
146148 Attachment .builder ()
147149 .parentId (aListAttachment .getParentId ())
148150 .name (aListAttachment .getName ())
149151 .updateTime (LocalDateTime .now ())
150- .type (aListAttachment . getIs_dir () ? AttachmentType . Directory : AttachmentType . File )
152+ .type (type )
151153 .size (aListAttachment .getSize ())
152154 .url (aListAttachment .getRaw_url ())
153155 .fsPath (getPathByPathArr (aListAttachment .getPaths ()))
154- .build ())
155- .flatMap ( attachment -> attachmentOperate .findByTypeAndParentIdAndName (
156- attachment . getType (), attachment .getParentId (), attachment .getName ()
156+ .build ()))
157+ .then ( attachmentOperate .findByTypeAndParentIdAndName (
158+ type , aListAttachment .getParentId (), aListAttachment .getName ()
157159 ))
158160 .map (attachment -> {
159161 aListAttachment .setParentId (attachment .getParentId ());
@@ -179,8 +181,8 @@ public Mono<AListToken> refreshToken() {
179181 @ Retryable
180182 public Mono <AListToken > refreshToken (boolean refresh ) {
181183 if (StringUtils .isBlank (token .getUrl ())
182- || StringUtils .isBlank (token .getUsername ())
183- || StringUtils .isBlank (token .getPassword ())) {
184+ || StringUtils .isBlank (token .getUsername ())
185+ || StringUtils .isBlank (token .getPassword ())) {
184186 log .warn ("token url or username or password is null or empty for token: {}" ,
185187 JsonUtils .obj2Json (token ));
186188 return Mono .empty ();
@@ -228,7 +230,7 @@ public Mono<AListToken> refreshToken(boolean refresh) {
228230
229231 private String getPathByPathArr (List <String > paths ) {
230232 StringBuilder path = new StringBuilder ("/" );
231- for (String p : paths ) {
233+ for (String p : paths ) {
232234 path .append (p ).append ("/" );
233235 }
234236 String pStr = path .toString ();
@@ -295,13 +297,13 @@ public AListToken cm2token(ConfigMap cm) {
295297 token .setPassword (cmd .get (ConfigMapKey .apiPassword ));
296298 token .setEnableAutoTokenRefresh (
297299 Boolean .parseBoolean (
298- StringUtils .isNotBlank (cmd .get (ConfigMapKey .enableAutoTokenRefresh ))
299- ? cmd .get (ConfigMapKey .enableAutoTokenRefresh ) : "false"
300- ));
300+ StringUtils .isNotBlank (cmd .get (ConfigMapKey .enableAutoTokenRefresh ))
301+ ? cmd .get (ConfigMapKey .enableAutoTokenRefresh ) : "false"
302+ ));
301303 token .setToken (cmd .get (ConfigMapKey .apiToken ));
302304 token .setExpire (
303305 StringUtils .isNotBlank (cmd .get (ConfigMapKey .apiExpire ))
304- ? Long .parseLong (cmd .get (ConfigMapKey .apiExpire )) : 0
306+ ? Long .parseLong (cmd .get (ConfigMapKey .apiExpire )) : 0
305307 );
306308 // log.debug("token: {}", token);
307309 return token ;
@@ -351,7 +353,7 @@ public Mono<Void> initAListToken() {
351353 @ EventListener (PluginConfigMapUpdateEvent .class )
352354 public Mono <Void > onConfigMapUpdated (PluginConfigMapUpdateEvent updateEvent ) throws Exception {
353355 // log.debug("afterPropertiesSet PluginConfigMapUpdateEvent for event: {}", new ObjectMapper().writeValueAsString(updateEvent));
354- if (Objects .isNull (updateEvent .getConfigMap ()) || !AListPlugin .NAME .equals (updateEvent .getConfigMap ().getName ())) {
356+ if (Objects .isNull (updateEvent .getConfigMap ()) || !AListPlugin .NAME .equals (updateEvent .getConfigMap ().getName ())) {
355357 return Mono .empty ();
356358 }
357359 return updateOperateByToken ().then ();
0 commit comments