Skip to content

Commit

Permalink
v1.0.0-beta
Browse files Browse the repository at this point in the history
1. 对接兰空图床
2. 对接smms图床
3. 支持图片上传
4. 支持图片删除
  • Loading branch information
liuyiwuqing committed May 22, 2024
1 parent 3dfbe7f commit 643b5ba
Show file tree
Hide file tree
Showing 48 changed files with 2,550 additions and 244 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# plugin-starter
# plugin-picture-bed

Halo 2.0 插件开发快速开始模板。

Expand All @@ -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(推荐)
Expand Down Expand Up @@ -70,7 +70,7 @@ halo:
plugin:
runtime-mode: development
fixedPluginPath:
- "/path/to/plugin-starter"
- "/path/to/plugin-picture-bed"
```
最后重启 Halo 项目即可。
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id "run.halo.plugin.devtools" version "0.0.7"
}

group 'run.halo.starter'
group 'site.muyin.picturebed'
sourceCompatibility = JavaVersion.VERSION_17

repositories {
Expand All @@ -16,11 +16,12 @@ repositories {
}

dependencies {
implementation platform('run.halo.tools.platform:plugin:2.11.0-SNAPSHOT')
implementation platform('run.halo.tools.platform:plugin:2.14.0-SNAPSHOT')
compileOnly 'run.halo.app:api'

testImplementation 'run.halo.app:api'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'cn.hutool:hutool-all:5.8.16'

}

test {
Expand Down Expand Up @@ -52,5 +53,6 @@ build {
}

halo {
version = '2.11'
version = '2.15.2'
debug = true
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.0-SNAPSHOT
version=1.0.0-beta
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pluginManagement {
gradlePluginPortal()
}
}
rootProject.name = 'plugin-starter'
rootProject.name = 'plugin-picture-bed'

31 changes: 0 additions & 31 deletions src/main/java/run/halo/starter/StarterPlugin.java

This file was deleted.

108 changes: 108 additions & 0 deletions src/main/java/site/muyin/picturebed/PictureBedEndpoint.java
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");
}
}
29 changes: 29 additions & 0 deletions src/main/java/site/muyin/picturebed/PictureBedPlugin.java
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 src/main/java/site/muyin/picturebed/annotation/GroupName.java
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 src/main/java/site/muyin/picturebed/config/PictureBedConfig.java
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 src/main/java/site/muyin/picturebed/constant/CommonConstant.java
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 src/main/java/site/muyin/picturebed/domain/LskyProAlbum.java
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 src/main/java/site/muyin/picturebed/domain/LskyProImage.java
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;
}
}
24 changes: 24 additions & 0 deletions src/main/java/site/muyin/picturebed/domain/SmmsImage.java
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;
}
Loading

0 comments on commit 643b5ba

Please sign in to comment.