diff --git a/README.md b/README.md index 7dfa7e7..47dd08f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Notify Me -当有新评论、新文章、等待审核的评论、等待审核的文章时将消息推送到微信、企业微信、飞书、钉钉等12个应用 +当有新评论、新文章、等待审核的评论、等待审核的文章时将消息推送到微信、QQ、企业微信、飞书、钉钉等12个应用 - 使用了AnPush推送服务,有免费额度,个人博客够用 - 不够用可以多注册几个账号薅羊毛,但是不建议,多支持下开发者 @@ -10,8 +10,8 @@ 安装插件后,会在halo后台左侧生成一个"通知我"的菜单(往下拉),然后点击进入设置页面。 - 站点地址就是你的域名,比如:https://baidu.com - - API密钥 [在这里获取](https://anpush.com/ApPush) - - 通道ID [在这里获取](https://anpush.com/ApChannel) + - API密钥 [在这里获取](https://anpush.com/push/tool) + - 通道ID [在这里获取](https://anpush.com/push/setting) **注意** 如果你用的是微信公众号通道,请一定要勾选这个选项,其他通道不要勾选! diff --git a/gradle.properties b/gradle.properties index 111e0a5..8da3e7f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=1.0.2 +version=1.1.0 #org.gradle.java.home=/Users/mon/Library/Java/JavaVirtualMachines/corretto-17.0.9/Contents/Home diff --git a/src/main/java/org/xiqi/notifyme/domain/NotifyMe.java b/src/main/java/org/xiqi/notifyme/domain/NotifyMe.java index 8eac274..1c11acb 100644 --- a/src/main/java/org/xiqi/notifyme/domain/NotifyMe.java +++ b/src/main/java/org/xiqi/notifyme/domain/NotifyMe.java @@ -41,4 +41,7 @@ public class NotifyMe extends AbstractExtension { @Schema(defaultValue = "false") private Boolean postAuditsStatus; // 文章审核通知开关 + @Schema(defaultValue = "false") + private Boolean postDelStatus; // 文章删除通知开关 + } diff --git a/src/main/java/org/xiqi/notifyme/event/PushEventNotify.java b/src/main/java/org/xiqi/notifyme/event/PushEventNotify.java index 7ff3f3b..dd31130 100644 --- a/src/main/java/org/xiqi/notifyme/event/PushEventNotify.java +++ b/src/main/java/org/xiqi/notifyme/event/PushEventNotify.java @@ -25,6 +25,11 @@ public void onAdd(Extension extension) { eventPublisher.publishEvent(NotifyBaseEvent.getEx(this, extension)); } + @Override + public void onDelete(Extension extension) { + eventPublisher.publishEvent(NotifyBaseEvent.getEx(this, extension)); + } + @Override public void registerDisposeHook(Runnable dispose) { this.disposeHook = dispose; diff --git a/src/main/java/org/xiqi/notifyme/strategy/CommentStrategy.java b/src/main/java/org/xiqi/notifyme/strategy/CommentStrategy.java index aad0697..fd5bae8 100644 --- a/src/main/java/org/xiqi/notifyme/strategy/CommentStrategy.java +++ b/src/main/java/org/xiqi/notifyme/strategy/CommentStrategy.java @@ -21,7 +21,8 @@ public class CommentStrategy implements NotifyStrategy { public void process(NotifyBaseEvent event, NotifyMe setting) { Comment commentInfo = (Comment) event.getExtension(); Comment.CommentSpec commentSpec = commentInfo.getSpec(); - if (!commentSpec.getOwner().getName().equals("admin")) { + if (!commentSpec.getOwner().getName().equals("admin") && + commentInfo.getMetadata().getDeletionTimestamp() == null) { // 这里有点坑爹,删除文章了也发通知删除评论通知 // 不是管理员的话就推送通知 String postMetaName = commentSpec.getSubjectRef().getName(); Optional postInfo = client.fetch(Post.class, postMetaName); @@ -35,7 +36,6 @@ public void process(NotifyBaseEvent event, NotifyMe setting) { } } }); - } } diff --git a/src/main/java/org/xiqi/notifyme/strategy/PostStrategy.java b/src/main/java/org/xiqi/notifyme/strategy/PostStrategy.java index cbbc152..c6ed80b 100644 --- a/src/main/java/org/xiqi/notifyme/strategy/PostStrategy.java +++ b/src/main/java/org/xiqi/notifyme/strategy/PostStrategy.java @@ -24,8 +24,6 @@ public class PostStrategy implements NotifyStrategy { private final PushUtil pushUtil; - private Integer counter = 0; - @Override public void process(NotifyBaseEvent event, NotifyMe setting) { /* @@ -36,11 +34,19 @@ public void process(NotifyBaseEvent event, NotifyMe setting) { Extension extension = event.getExtension(); ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); executorService.schedule(() -> { + if (extension.getMetadata().getLabels().containsKey("content.halo.run/deleted") && + extension.getMetadata().getLabels().get("content.halo.run/deleted").equals("true") + ) { + //删除文章到这里就终止了 + delete((Post) extension, setting); + return; + } Optional postInfo = client.fetch(Post.class, extension.getMetadata().getName()); postInfo.ifPresent(post -> { if (post.getStatus().getPhase().equals("DRAFT") && !post.getSpec().getOwner() .equals("admin")) { // 管理员的不管 audits(post, setting); + return; } if (post.getStatus().getPhase().equals("PUBLISHED")) { publish(post, setting); @@ -54,9 +60,10 @@ public void process(NotifyBaseEvent event, NotifyMe setting) { private void publish(Post post, NotifyMe setting) { // 文章发布通知 if (setting.getPostStatus()) { String title = "有新文章发布"; - String content = "您的站点有新文章发布:" + String.format("[%s](%s)", + String content = String.format("您的站点有新文章发布:[%s](%s)\n\n %s", post.getSpec().getTitle(), - setting.getSiteUrl() + post.getStatus().getPermalink()); + setting.getSiteUrl() + post.getStatus().getPermalink(), + getExcerpt(post.getStatus().getExcerpt())); push(title, content, setting); } } @@ -64,8 +71,21 @@ private void publish(Post post, NotifyMe setting) { // 文章发布通知 private void audits(Post post, NotifyMe setting) { // 文章审核通知 if (setting.getPostAuditsStatus()) { String title = "有新文章待审核: " + post.getSpec().getTitle(); - String content = "您的站点有新文文章等待审核,\n\n " + String.format("[立刻审核](%s)", - setting.getSiteUrl() + "/console/posts"); + String content = + String.format("%s...\n\n%s", getExcerpt(post.getStatus().getExcerpt()), + String.format("[立刻审核](%s)", + setting.getSiteUrl() + "/console/posts")); + push(title, content, setting); + } + } + + private void delete(Post post, NotifyMe setting) { // 文章删除通知 + if (setting.getPostDelStatus()) { + String title = "文章被删除"; + String content = String.format("您的站点有新文章被删除:[%s](%s)\n\n %s", + post.getSpec().getTitle(), + setting.getSiteUrl() + post.getStatus().getPermalink(), + getExcerpt(post.getStatus().getExcerpt())); push(title, content, setting); } } @@ -76,5 +96,12 @@ private void push(String title, String content, NotifyMe setting) { // 推送 pushDo.setContent(content); pushUtil.sendRequest(pushDo, setting); } + + private String getExcerpt(String excerpt) { + if (excerpt.length() > 50) { + return excerpt.substring(0, 50) + "..."; + } + return excerpt; + } } diff --git a/src/main/resources/plugin.yaml b/src/main/resources/plugin.yaml index f50476e..36d036a 100644 --- a/src/main/resources/plugin.yaml +++ b/src/main/resources/plugin.yaml @@ -11,7 +11,7 @@ spec: logo: /notify.png homepage: https://github.com/monyuan/notify-me displayName: "通知我" - description: "当有评论时、新闻章时推送通知到微信、企业微信、飞书、钉钉、微信测试号、Slack等12个应用,使用了AnPush服务。" + description: "当有评论时、新闻章等事件时推送通知到微信、QQ、企业微信、飞书、钉钉、微信测试号、Slack等12个应用,使用了AnPush服务。" license: - name: "GPL-3.0" url: "https://raw.githubusercontent.com/monyuan/notify-me/main/LICENSE" diff --git a/ui/src/views/HomeView.vue b/ui/src/views/HomeView.vue index a197409..5738826 100644 --- a/ui/src/views/HomeView.vue +++ b/ui/src/views/HomeView.vue @@ -24,6 +24,7 @@ export default { wechatStatus: false, commentAuditsStatus: false, postAuditsStatus: false, + postDelStatus: false, apiVersion: "org.xiqi.notifyme/v1alpha1", kind: "NotifyMe", metadata: { @@ -154,7 +155,7 @@ export default {
- 🎈 通过AnPush的接口实现的通知推送, 免费套餐已足够博客使用。 获取密钥 >
根据官网描述可以推送至12个应用,我测试了微信、企业微信、微信测试号、飞书、钉钉都没有问题
@@ -252,28 +253,33 @@ export default { d="M2 12c0-.865.11-1.704.316-2.504A3 3 0 0 0 4.99 4.867a9.99 9.99 0 0 1 4.335-2.506a3 3 0 0 0 5.348 0a9.99 9.99 0 0 1 4.335 2.506a3 3 0 0 0 2.675 4.63c.206.8.316 1.638.316 2.503c0 .864-.11 1.703-.316 2.503a3 3 0 0 0-2.675 4.63a9.99 9.99 0 0 1-4.335 2.505a3 3 0 0 0-5.348 0a9.99 9.99 0 0 1-4.335-2.505a3 3 0 0 0-2.675-4.63C2.11 13.703 2 12.864 2 12Zm4.804 3c.63 1.091.81 2.346.564 3.524c.408.29.842.541 1.297.75A4.993 4.993 0 0 1 12 18c1.26 0 2.438.471 3.335 1.274c.455-.209.889-.46 1.297-.75A4.993 4.993 0 0 1 17.196 15a4.993 4.993 0 0 1 2.77-2.25a8.142 8.142 0 0 0 0-1.5A4.993 4.993 0 0 1 17.196 9a4.993 4.993 0 0 1-.564-3.524a7.991 7.991 0 0 0-1.297-.75A4.993 4.993 0 0 1 12 6a4.993 4.993 0 0 1-3.335-1.274a7.99 7.99 0 0 0-1.297.75A4.993 4.993 0 0 1 6.804 9a4.993 4.993 0 0 1-2.77 2.25a8.125 8.125 0 0 0 0 1.5A4.993 4.993 0 0 1 6.805 15ZM12 15a3 3 0 1 1 0-6a3 3 0 0 1 0 6Zm0-2a1 1 0 1 0 0-2a1 1 0 0 0 0 2Z"> - 功能设置 + 通知功能设置
- +
- +
- +
- + +
+
+ +