-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
完成项目基本功能,后续进行代码重构和测试 ```release-note None ```
- Loading branch information
Showing
29 changed files
with
2,956 additions
and
1,932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=1.0.0-SNAPSHOT | ||
version=1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package run.halo.alist.config; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* AList 存储策略配置 | ||
* | ||
* @author <a href="https://roozen.top">Roozen</a> | ||
* @version 1.0 | ||
* 2024/7/8 | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class AListProperties { | ||
/** | ||
* AList 站点地址. | ||
*/ | ||
private String site; | ||
/** | ||
* AList 挂载路径. | ||
*/ | ||
private String path; | ||
/** | ||
* Secret name. | ||
*/ | ||
private String secretName; | ||
|
||
/** | ||
* 获取 token key. | ||
* | ||
* @return token key | ||
*/ | ||
public String getTokenKey() { | ||
return site + secretName; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/run/halo/alist/controller/PolicyConfigValidationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package run.halo.alist.controller; | ||
|
||
import java.util.Objects; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
import run.halo.alist.endpoint.AListAttachmentHandler; | ||
import run.halo.alist.config.AListProperties; | ||
import run.halo.alist.dto.AListResult; | ||
import run.halo.alist.dto.response.AListStorageListRes; | ||
import run.halo.alist.exception.AListIllegalArgumentException; | ||
import run.halo.app.plugin.ApiVersion; | ||
|
||
/** | ||
* 存储策略验证控制器 | ||
* | ||
* @author <a href="https://roozen.top">Roozen</a> | ||
* @version 1.0 | ||
* 2024/7/10 | ||
*/ | ||
@ApiVersion("alist.storage.halo.run/v1alpha1") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class PolicyConfigValidationController { | ||
private final AListAttachmentHandler handler; | ||
|
||
@PostMapping("/configs/-/verify") | ||
public Mono<Void> validatePolicyConfig(@RequestBody AListProperties properties) { | ||
return handler.removeTokenCache(properties) | ||
.then( | ||
handler.auth(properties) | ||
.flatMap(token -> handler.getWebClients() | ||
.get(properties.getSite()) | ||
.get() | ||
.uri("/api/admin/storage/list") | ||
.header("Authorization", token) | ||
.retrieve() | ||
.bodyToMono( | ||
new ParameterizedTypeReference<AListResult<AListStorageListRes>>() { | ||
}) | ||
.flatMap(response -> { | ||
if (response.getCode().equals("200")) { | ||
return Flux.fromIterable(response.getData().getContent()) | ||
.filter(volume -> Objects.equals(volume.getMountPath(), | ||
properties.getPath())) | ||
.switchIfEmpty(Mono.error(new AListIllegalArgumentException( | ||
"The mount path does not exist"))) | ||
.all(volume -> !volume.isDisabled()) | ||
.filter(isValid -> isValid) | ||
.switchIfEmpty(Mono.error(new AListIllegalArgumentException( | ||
"The storage is disabled"))) | ||
.then(); | ||
} | ||
return Mono.error(new AListIllegalArgumentException( | ||
"Wrong Username Or Password")); | ||
})) | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package run.halo.alist.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* AList 接口返回结果 | ||
* @author <a href="https://roozen.top">Roozen</a> | ||
* @version 1.0 | ||
* 2024/7/8 | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class AListResult <T>{ | ||
private String code; | ||
private String message; | ||
private T data; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/run/halo/alist/dto/request/AListGetFileInfoReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package run.halo.alist.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* @author <a href="https://roozen.top">Roozen</a> | ||
* @version 1.0 | ||
* 2024/7/10 | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class AListGetFileInfoReq { | ||
private String path; | ||
private String password; | ||
private int page; | ||
private int perPage; | ||
private boolean refresh; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/run/halo/alist/dto/request/AListLoginReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package run.halo.alist.dto.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
/** | ||
* @author <a href="https://roozen.top">Roozen</a> | ||
* @version 1.0 | ||
* 2024/7/8 | ||
*/ | ||
@Data | ||
@Builder | ||
public class AListLoginReq { | ||
private String password; | ||
private String username; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/run/halo/alist/dto/request/AListRemoveFileReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package run.halo.alist.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import java.util.List; | ||
|
||
/** | ||
* @author <a href="https://roozen.top">Roozen</a> | ||
* @version 1.0 | ||
* 2024/7/10 | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class AListRemoveFileReq { | ||
private String dir; | ||
private List<String> names; | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/run/halo/alist/dto/response/AListGetFileInfoRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package run.halo.alist.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.time.OffsetDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* @author <a href="https://roozen.top">Roozen</a> | ||
* @version 1.0 | ||
* 2024/7/10 | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class AListGetFileInfoRes { | ||
private String name; | ||
private long size; | ||
private boolean isDir; | ||
private OffsetDateTime modified; | ||
private OffsetDateTime created; | ||
private String sign; | ||
private String thumb; | ||
private int type; | ||
@JsonProperty("raw_url") | ||
private String rawUrl; | ||
private String readme; | ||
private String header; | ||
private String provider; | ||
private Object related; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/run/halo/alist/dto/response/AListLoginRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package run.halo.alist.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* @author <a href="https://roozen.top">Roozen</a> | ||
* @version 1.0 | ||
* 2024/7/8 | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class AListLoginRes { | ||
private String token; | ||
} |
Oops, something went wrong.