Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adapt NON-ADMIN users #7

Merged
merged 9 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ AList 存储库插件,支持创建 AList 类型的存储库
![](docs/img/4.png)
根据提示填写以下信息
![](docs/img/5.png)
注意:这里建议填写 `ADMIN` 用户的用户名和密码,因为部分 AList 接口只有 `ADMIN` 用户才能访问,否则将验证失败
![](docs/img/6.png)
如果你确信你的配置完全正确,并且你填写的非 `ADMIN` 用户至少拥有以下权限,尽管无法完成验证,但是并不影响使用
![](docs/img/9.png)
![](docs/img/10.png)
`ADMIN` 用户可以正常验证
![](docs/img/7.png)

## 注意事项
Expand All @@ -26,6 +31,7 @@ AList 存储库插件,支持创建 AList 类型的存储库
client_max_body_size 0;
```
![](docs/img/8.png)
3. 修改用户状态后需要重新验证来刷新缓存,如:修改用户密码
## 开发环境

插件开发的详细文档请查阅:<https://docs.halo.run/developer-guide/plugin/introduction>
Expand Down Expand Up @@ -55,14 +61,6 @@ cd path/to/plugin-alist

> 此方式需要本地安装 Docker

```bash
# macOS / Linux
./gradlew pnpmInstall

# Windows
./gradlew.bat pnpmInstall
```

```bash
# macOS / Linux
./gradlew haloServer
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tasks.withType(JavaCompile).configureEach {
}

halo {
version = '2.17'
version = '2.18'
superAdminUsername = 'admin'
superAdminPassword = 'admin'
externalUrl = 'http://localhost:8090'
Expand Down
Binary file added docs/img/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.0
version=1.0.1
4 changes: 4 additions & 0 deletions src/main/java/run/halo/alist/config/AListProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class AListProperties {
* AList 挂载路径.
*/
private String path;
/**
* AList 基本路径.
*/
private String basePath;
/**
* Secret name.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -39,7 +40,7 @@ public Mono<Void> validatePolicyConfig(@RequestBody AListProperties properties)
.get(properties.getSite())
.get()
.uri("/api/admin/storage/list")
.header("Authorization", token)
.header(HttpHeaders.AUTHORIZATION, token)
Roozenlz marked this conversation as resolved.
Show resolved Hide resolved
.retrieve()
.bodyToMono(
new ParameterizedTypeReference<AListResult<AListStorageListRes>>() {
Expand All @@ -56,6 +57,9 @@ public Mono<Void> validatePolicyConfig(@RequestBody AListProperties properties)
.switchIfEmpty(Mono.error(new AListIllegalArgumentException(
"The storage is disabled")))
.then();
} else if (response.getCode().equals("403")) {
return Mono.error(new AListIllegalArgumentException(
"You are not an admin"));
}
return Mono.error(new AListIllegalArgumentException(
"Wrong Username Or Password"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,13 @@ public Mono<URI> getPermalink(Attachment attachment, Policy policy, ConfigMap co
return Mono.error(new AListRequestErrorException(response.getMessage()));
}))
.map(response -> UriComponentsBuilder.fromHttpUrl(properties.getSite())
.path("/d/{path}/{name}")
.path("/d{path}{basePath}/{name}")
.queryParamIfPresent("sign",
Optional.ofNullable(response.getData().getSign()).filter(s -> !s.isEmpty()))
.buildAndExpand(
UriUtils.encodePath(properties.getPath(), StandardCharsets.UTF_8),
UriUtils.encodePath(response.getData().getName(), StandardCharsets.UTF_8)
properties.getPath(),
properties.getBasePath(),
response.getData().getName()
)
.toUri());
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/extensions/policy-template-alist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ spec:
label: 挂载路径
validation: required
help: AList 存储中的挂载路径,必须以 / 开头,如 /aliyun
- $formkit: text
name: basePath
label: 基本路径
help: 所填用户的基本路径,可在 AList 管理 -> 用户 查看,必须以 / 开头,如 /aliyun,为 / 时留空即可
- $formkit: secret
name: secretName
required: true
Expand Down