Skip to content

Commit 2e961fb

Browse files
author
li-guohao
committed
optimize: skip exists attachment save.
1 parent b731438 commit 2e961fb

5 files changed

Lines changed: 47 additions & 39 deletions

File tree

console/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
*.d.ts

console/src/views/AListControl.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<script setup lang="ts">
2+
import { ref } from "vue"
3+
4+
const alistPath = ref("/")
25
</script>
36

47
<template>
58
<div class="ik-plugin-alist-container">
69
<h3>AList 插件操作</h3>
710
<hr />
811
<form name="form" method="post" action="#">
9-
<input name="path" placeholder="请输入需要导入的相对路径路径" required>
12+
<input name="path" placeholder="请输入需要导入的相对路径路径" required v-model="alistPath">
1013
<input type="submit" name="submit" value="提交导入">
14+
{{alistPath}}
1115
</form>
1216
</div>
1317
</template>

console/vite.config.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
import { defineConfig } from 'vite'
2-
import { fileURLToPath, URL } from "url";
1+
import {defineConfig} from 'vite'
2+
import {fileURLToPath, URL} from "url";
33
import Vue from "@vitejs/plugin-vue";
44
import VueJsx from "@vitejs/plugin-vue-jsx";
55

66
// Current plugin entry name value must eq plugin.yaml name value.
77
const pluginEntryName = "PluginAList";
88
// https://vitejs.dev/config/
99
export default defineConfig({
10-
define: {
11-
'process.env': {},
12-
},
13-
plugins: [Vue(), VueJsx()],
14-
resolve: {
15-
alias: {
16-
"@": fileURLToPath(new URL("./src", import.meta.url)),
10+
define: {
11+
'process.env': {},
1712
},
18-
},
19-
build: {
20-
outDir: fileURLToPath(
21-
new URL("../src/main/resources/console", import.meta.url)
22-
),
23-
emptyOutDir: true,
24-
lib: {
25-
entry: "src/index.ts",
26-
name: pluginEntryName,
27-
formats: ["iife"],
28-
fileName: () => "index.js",
13+
plugins: [
14+
Vue(),
15+
VueJsx(),
16+
],
17+
resolve: {
18+
alias: {
19+
"@": fileURLToPath(new URL("./src", import.meta.url)),
20+
},
21+
},
22+
build: {
23+
outDir: fileURLToPath(
24+
new URL("../src/main/resources/console", import.meta.url)
25+
),
26+
emptyOutDir: true,
27+
lib: {
28+
entry: "src/index.ts",
29+
name: pluginEntryName,
30+
formats: ["iife"],
31+
fileName: () => "index.js",
32+
},
2933
},
30-
},
3134
})

src/main/java/run/ikaros/plugin/alist/AListAttachment.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import lombok.Data;
44

5-
import java.time.LocalDateTime;
65
import java.util.List;
7-
import java.util.Map;
86

97
@Data
108
public class AListAttachment {

src/main/java/run/ikaros/plugin/alist/AListClient.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import run.ikaros.api.store.enums.AttachmentType;
2626
import run.ikaros.plugin.alist.AListConst.ConfigMapKey;
2727

28-
import java.net.URLDecoder;
29-
import java.nio.charset.StandardCharsets;
3028
import java.time.Duration;
3129
import java.time.LocalDateTime;
3230
import 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

Comments
 (0)