最近的一些修改 #7
@@ -73,4 +73,9 @@ public class LinksController {
|
|||||||
public Response apply(@RequestBody() LinkApplyReq linkApplyReq) {
|
public Response apply(@RequestBody() LinkApplyReq linkApplyReq) {
|
||||||
return Response.success(partnerSiteService.apply(linkApplyReq));
|
return Response.success(partnerSiteService.apply(linkApplyReq));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/reapply")
|
||||||
|
public Response reapply(@RequestParam("key") String key) {
|
||||||
|
return Response.success(partnerSiteService.reapply(key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ public enum ResponseEnum {
|
|||||||
|
|
||||||
//其他
|
//其他
|
||||||
APPLY_LINK_NO_ADD_THIS_SITE(7200, "暂未在您的网站中抓取到本站链接"),
|
APPLY_LINK_NO_ADD_THIS_SITE(7200, "暂未在您的网站中抓取到本站链接"),
|
||||||
|
DATA_EXPIRED(7300, "数据过期"),
|
||||||
|
CANNOT_GET_DATA(7400, "暂无法获取到数据"),
|
||||||
|
|
||||||
//提交更新之前,没有获取数据/,
|
//提交更新之前,没有获取数据/,
|
||||||
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
||||||
|
|||||||
@@ -60,4 +60,6 @@ public interface PartnerSiteService {
|
|||||||
* @return linkApplyReq
|
* @return linkApplyReq
|
||||||
*/
|
*/
|
||||||
PartnerSite apply(LinkApplyReq linkApplyReq);
|
PartnerSite apply(LinkApplyReq linkApplyReq);
|
||||||
|
|
||||||
|
Object reapply(String key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import cn.celess.blog.mapper.PartnerMapper;
|
|||||||
import cn.celess.blog.service.MailService;
|
import cn.celess.blog.service.MailService;
|
||||||
import cn.celess.blog.service.PartnerSiteService;
|
import cn.celess.blog.service.PartnerSiteService;
|
||||||
import cn.celess.blog.util.HttpUtil;
|
import cn.celess.blog.util.HttpUtil;
|
||||||
|
import cn.celess.blog.util.JwtUtil;
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.RegexUtil;
|
import cn.celess.blog.util.RegexUtil;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -152,7 +153,9 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
}
|
}
|
||||||
// 抓取页面
|
// 抓取页面
|
||||||
String resp = HttpUtil.getAfterRendering(linkApplyReq.getLinkUrl());
|
String resp = HttpUtil.getAfterRendering(linkApplyReq.getLinkUrl());
|
||||||
assert resp != null;
|
if (resp == null) {
|
||||||
|
throw new MyException(ResponseEnum.CANNOT_GET_DATA);
|
||||||
|
}
|
||||||
PartnerSite ps = new PartnerSite();
|
PartnerSite ps = new PartnerSite();
|
||||||
if (resp.contains(SITE_URL)) {
|
if (resp.contains(SITE_URL)) {
|
||||||
//包含站点
|
//包含站点
|
||||||
@@ -183,4 +186,27 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
}
|
}
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public Object reapply(String key) {
|
||||||
|
if (!redisUtil.hasKey(key)) {
|
||||||
|
throw new MyException(ResponseEnum.DATA_EXPIRED);
|
||||||
|
}
|
||||||
|
String s = redisUtil.get(key);
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
LinkApplyReq linkApplyReq = mapper.readValue(s, LinkApplyReq.class);
|
||||||
|
if (linkApplyReq == null) {
|
||||||
|
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
|
}
|
||||||
|
SimpleMailMessage smm = new SimpleMailMessage();
|
||||||
|
smm.setSubject("友链申请");
|
||||||
|
smm.setText("有一条未抓取到信息的友链申请,[\n" + linkApplyReq.toString() + "\n]");
|
||||||
|
smm.setTo(SITE_EMAIL);
|
||||||
|
smm.setSentDate(new Date());
|
||||||
|
mailService.send(smm);
|
||||||
|
redisUtil.delete(key);
|
||||||
|
redisUtil.delete(linkApplyReq.getUrl());
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user