generated from liuyiwuqing/halo-plugin-template
-
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.
1. 对接兰空图床 2. 对接smms图床 3. 支持图片上传 4. 支持图片删除
- Loading branch information
1 parent
3dfbe7f
commit 643b5ba
Showing
48 changed files
with
2,550 additions
and
244 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# plugin-starter | ||
# plugin-picture-bed | ||
|
||
Halo 2.0 插件开发快速开始模板。 | ||
|
||
|
@@ -16,15 +16,15 @@ Halo 2.0 插件开发快速开始模板。 | |
克隆项目: | ||
|
||
```bash | ||
git clone [email protected]:halo-sigs/plugin-starter.git | ||
git clone [email protected]:halo-sigs/plugin-picture-bed.git | ||
|
||
# 或者当你 fork 之后 | ||
|
||
git clone [email protected]:{your_github_id}/plugin-starter.git | ||
git clone [email protected]:{your_github_id}/plugin-picture-bed.git | ||
``` | ||
|
||
```bash | ||
cd path/to/plugin-starter | ||
cd path/to/plugin-picture-bed | ||
``` | ||
|
||
### 运行方式 1(推荐) | ||
|
@@ -70,7 +70,7 @@ halo: | |
plugin: | ||
runtime-mode: development | ||
fixedPluginPath: | ||
- "/path/to/plugin-starter" | ||
- "/path/to/plugin-picture-bed" | ||
``` | ||
最后重启 Halo 项目即可。 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
version=1.0.0-SNAPSHOT | ||
version=1.0.0-beta |
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 was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
src/main/java/site/muyin/picturebed/PictureBedEndpoint.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,108 @@ | ||
package site.muyin.picturebed; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.springdoc.webflux.core.fn.SpringdocRouteBuilder; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.codec.multipart.Part; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.reactive.function.server.RouterFunction; | ||
import org.springframework.web.reactive.function.server.ServerRequest; | ||
import org.springframework.web.reactive.function.server.ServerResponse; | ||
import reactor.core.publisher.Mono; | ||
import run.halo.app.core.extension.endpoint.CustomEndpoint; | ||
import run.halo.app.extension.GroupVersion; | ||
import site.muyin.picturebed.query.CommonQuery; | ||
import site.muyin.picturebed.service.PictureBedService; | ||
import site.muyin.picturebed.vo.ResultsVO; | ||
|
||
import static org.springdoc.core.fn.builders.apiresponse.Builder.responseBuilder; | ||
import static org.springdoc.core.fn.builders.content.Builder.contentBuilder; | ||
import static org.springdoc.core.fn.builders.requestbody.Builder.requestBodyBuilder; | ||
import static org.springdoc.core.fn.builders.schema.Builder.schemaBuilder; | ||
import static org.springframework.web.reactive.function.server.RequestPredicates.contentType; | ||
|
||
/** | ||
* @author: lywq | ||
* @date: 2024/04/14 19:44 | ||
* @version: v1.0.0 | ||
* @description: | ||
**/ | ||
@Component | ||
@AllArgsConstructor | ||
public class PictureBedEndpoint implements CustomEndpoint { | ||
|
||
private final PictureBedService pictureBedService; | ||
|
||
@Override | ||
public RouterFunction<ServerResponse> endpoint() { | ||
final var tag = "picturebed.muyin.site/v1alpha1/PictureBed"; | ||
return SpringdocRouteBuilder.route() | ||
.GET("albums", this::getAlbumList, | ||
builder -> builder.operationId("albums") | ||
.description("albums").tag(tag)) | ||
.GET("images", this::getImageList, | ||
builder -> builder.operationId("images") | ||
.description("images").tag(tag)) | ||
.GET("deleteImage", this::deleteImage, | ||
builder -> builder.operationId("deleteImage") | ||
.description("deleteImage").tag(tag)) | ||
.POST("uploadImage", contentType(MediaType.MULTIPART_FORM_DATA), | ||
this::uploadImage, builder -> builder.operationId("uploadImage") | ||
.description("uploadImage") | ||
.tag(tag) | ||
.requestBody(requestBodyBuilder() | ||
.required(true) | ||
.content(contentBuilder() | ||
.mediaType(MediaType.MULTIPART_FORM_DATA_VALUE) | ||
.schema(schemaBuilder()) | ||
)) | ||
.response(responseBuilder().implementation(ResultsVO.class)) | ||
) | ||
.build(); | ||
} | ||
|
||
private Mono<ServerResponse> uploadImage(ServerRequest serverRequest) { | ||
CommonQuery query = new CommonQuery(serverRequest.exchange()); | ||
Mono<MultiValueMap<String, Part>> multiValueMapMono = serverRequest.multipartData(); | ||
return multiValueMapMono.flatMap(multiValueMap -> { | ||
return pictureBedService.uploadImage(query, multiValueMap).flatMap(resultsVO -> { | ||
if (resultsVO.getCode() == 200) { | ||
return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).bodyValue(resultsVO); | ||
} else { | ||
return ServerResponse.badRequest().contentType(MediaType.APPLICATION_JSON_UTF8).bodyValue(resultsVO); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
private Mono<ServerResponse> getAlbumList(ServerRequest serverRequest) { | ||
CommonQuery query = new CommonQuery(serverRequest.exchange()); | ||
return pictureBedService.getAlbumList(query).flatMap(albumVOList -> { | ||
return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).bodyValue(albumVOList); | ||
}); | ||
} | ||
|
||
private Mono<ServerResponse> getImageList(ServerRequest serverRequest) { | ||
CommonQuery query = new CommonQuery(serverRequest.exchange()); | ||
return pictureBedService.getImageList(query).flatMap(pageResult -> { | ||
return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).bodyValue(pageResult); | ||
}); | ||
} | ||
|
||
private Mono<ServerResponse> deleteImage(ServerRequest serverRequest) { | ||
CommonQuery query = new CommonQuery(serverRequest.exchange()); | ||
return pictureBedService.deleteImage(query).flatMap(result -> { | ||
if (result) { | ||
return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).bodyValue(result); | ||
} else { | ||
return ServerResponse.badRequest().contentType(MediaType.APPLICATION_JSON_UTF8).bodyValue(result); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public GroupVersion groupVersion() { | ||
return GroupVersion.parseAPIVersion("picturebed.muyin.site/v1alpha1"); | ||
} | ||
} |
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,29 @@ | ||
package site.muyin.picturebed; | ||
|
||
import org.springframework.stereotype.Component; | ||
import run.halo.app.plugin.BasePlugin; | ||
import run.halo.app.plugin.PluginContext; | ||
|
||
/** | ||
* @author: lywq | ||
* @date: 2024/04/14 19:43 | ||
* @version: v1.0.0 | ||
* @description: | ||
**/ | ||
@Component | ||
public class PictureBedPlugin extends BasePlugin { | ||
|
||
public PictureBedPlugin(PluginContext pluginContext) { | ||
super(pluginContext); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
System.out.println("插件启动成功!"); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
System.out.println("插件停止!"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/site/muyin/picturebed/annotation/GroupName.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,18 @@ | ||
package site.muyin.picturebed.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* 配置组名 | ||
* | ||
* @author lywq | ||
* @date 2023/05/10 11:50 | ||
**/ | ||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface GroupName { | ||
String value() default ""; | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/site/muyin/picturebed/config/PictureBedConfig.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,35 @@ | ||
package site.muyin.picturebed.config; | ||
|
||
import lombok.Data; | ||
import lombok.experimental.Accessors; | ||
import site.muyin.picturebed.annotation.GroupName; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author: lywq | ||
* @date: 2024/05/21 11:50 | ||
* @version: v1.0.0 | ||
* @description: | ||
**/ | ||
@Data | ||
@Accessors(chain = true) | ||
@GroupName("basic") | ||
public class PictureBedConfig { | ||
|
||
public static final String CONFIG_MAP_NAME = "picture-bed-config"; | ||
|
||
private Map slots; | ||
|
||
private List<PictureBed> pictureBeds; | ||
|
||
@Data | ||
@Accessors(chain = true) | ||
public class PictureBed { | ||
private Boolean pictureBedEnabled; | ||
private String pictureBedType; | ||
private String pictureBedUrl; | ||
private String pictureBedToken; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/site/muyin/picturebed/constant/CommonConstant.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,15 @@ | ||
package site.muyin.picturebed.constant; | ||
|
||
/** | ||
* @author: lywq | ||
* @date: 2024/04/18 10:43 | ||
* @version: v1.0.0 | ||
* @description: | ||
**/ | ||
public class CommonConstant { | ||
|
||
public static class PictureBedType { | ||
public static final String LSKY = "lsky"; | ||
public static final String SMMS = "smms"; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/site/muyin/picturebed/domain/LskyProAlbum.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,17 @@ | ||
package site.muyin.picturebed.domain; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author: lywq | ||
* @date: 2024/04/29 10:48 | ||
* @version: v1.0.0 | ||
* @description: 相册 | ||
**/ | ||
@Data | ||
public class LskyProAlbum { | ||
private Integer id; | ||
private String name; | ||
private String intro; | ||
private Integer image_num; | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/site/muyin/picturebed/domain/LskyProImage.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,38 @@ | ||
package site.muyin.picturebed.domain; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author: lywq | ||
* @date: 2024/04/29 10:55 | ||
* @version: v1.0.0 | ||
* @description: 图片 | ||
**/ | ||
@Data | ||
public class LskyProImage { | ||
private String key; | ||
private String name; | ||
private String origin_name; | ||
private String pathname; | ||
private Float size; | ||
private Integer width; | ||
private Integer height; | ||
private String intro; | ||
private String md5; | ||
private String sha1; | ||
private String mimetype; | ||
private String extension; | ||
private String humanDate; | ||
private String date; | ||
private ImageLink links; | ||
|
||
@Data | ||
public class ImageLink { | ||
private String url; | ||
private String thumbnail_url; | ||
private String html; | ||
private String bbcode; | ||
private String markdown; | ||
private String markdown_with_link; | ||
} | ||
} |
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,24 @@ | ||
package site.muyin.picturebed.domain; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author: lywq | ||
* @date: 2024/05/21 16:08 | ||
* @version: v1.0.0 | ||
* @description: | ||
**/ | ||
@Data | ||
public class SmmsImage { | ||
private Integer width; | ||
private Integer height; | ||
private String filename; | ||
private String storename; | ||
private Integer size; | ||
private String path; | ||
private String hash; | ||
private String created_at; | ||
private String url; | ||
private String delete; | ||
private String page; | ||
} |
Oops, something went wrong.