diff --git a/src/main/java/com/lion/lionwebsite/Service/GalleryManageService.java b/src/main/java/com/lion/lionwebsite/Service/GalleryManageService.java index 7fb0ffe..b6aac9d 100644 --- a/src/main/java/com/lion/lionwebsite/Service/GalleryManageService.java +++ b/src/main/java/com/lion/lionwebsite/Service/GalleryManageService.java @@ -108,9 +108,9 @@ public class GalleryManageService { //尝试下载本子,返回结果 try { gallery = GalleryUtil.parse(link, true, targetResolution); - if (gallery == null) { - log.error("创建任务: {},解析失败", link); - response.failure("任务解析失败,未知原因,请检查链接是否正常"); + if (gallery == null || !gallery.getStatus().equals("已提交")) { + log.error("创建任务失败: {},", link); + response.failure("提交任务失败,未知原因,请检查链接是否正常"); pushService.taskCreateReport(user.getUsername(), link, response); return response.toJSONString(); } else { diff --git a/src/main/java/com/lion/lionwebsite/Util/GalleryUtil.java b/src/main/java/com/lion/lionwebsite/Util/GalleryUtil.java index c79c30a..3a9f2d1 100644 --- a/src/main/java/com/lion/lionwebsite/Util/GalleryUtil.java +++ b/src/main/java/com/lion/lionwebsite/Util/GalleryUtil.java @@ -26,6 +26,10 @@ public class GalleryUtil { static String POST = "post"; static String GET = "get"; + static String FORM_DATA = "formData"; + + static String JSON = "json"; + public static ArrayList galleriesForDownload; static { @@ -69,13 +73,12 @@ public class GalleryUtil { //查找下载页面链接并初始化参数 String download_link = galleryDoc.select("#gd5 > p:nth-child(2) > a").attr("onclick").split("'")[1]; - HashMap extraProperties = new HashMap<>(); - extraProperties.put("origin", origin); - extraProperties.put("referer", download_link); - + HashMap headers = new HashMap<>(); + headers.put("origin", origin); + headers.put("referer", download_link); //访问下载页面,获取分辨率 - String downloadPage = requests(download_link, GET, extraProperties, null); + String downloadPage = requests(download_link, GET, headers, null); Document downloadDoc = Jsoup.parse(downloadPage); Elements resolutions = downloadDoc.select("#db > div > table > tbody > tr > td"); download_link = downloadDoc.select("#hathdl_form").attr("action"); @@ -101,10 +104,8 @@ public class GalleryUtil { } availableResolution.put("Original", tempResolutions.get("Original")); - gallery.setAvailableResolution(availableResolution); - //如果不是下载,则直接返回 if(!isDownload){ gallery.setStatus("等待确认下载"); @@ -123,8 +124,9 @@ public class GalleryUtil { //提交下载请求 HashMap body = new HashMap<>(); + body.put("payload", FORM_DATA); body.put("hathdl_xres", targetResolution.replace("x", "").replace("Original", "org")); - downloadPage = requests(download_link, POST, extraProperties, body); + downloadPage = requests(download_link, POST, headers, body); downloadDoc = Jsoup.parse(downloadPage); //判断下载请求是否提交成功 @@ -139,18 +141,6 @@ public class GalleryUtil { } - public static String queryUpdateLink(String link) throws IOException{ - String page = requests(link, GET, null, null); - Document document = Jsoup.parse(page); - - Elements select = document.select("#gnd"); - if(!select.isEmpty()) - return select.select("a").getFirst().attributes().get("href"); - - return null; - } - - /** * 验证链接 * @param url 链接 @@ -188,24 +178,27 @@ public class GalleryUtil { if(method.equals(GET)){ HttpGet httpGet = new HttpGet(url); - for (Map.Entry header: headers.entrySet()){ + for (Map.Entry header: headers.entrySet()) httpGet.addHeader(header.getKey(), header.getValue()); - } httpResponse = httpClient.execute(httpGet); } else { HttpPost httpPost = new HttpPost(url); - for (Map.Entry header: headers.entrySet()){ + for (Map.Entry header: headers.entrySet()) httpPost.addHeader(header.getKey(), header.getValue()); - } if(body != null) { - MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); - body.forEach(multipartEntityBuilder::addTextBody); -// EntityBuilder entityBuilder = EntityBuilder.create(); -// entityBuilder.setContentType(ContentType.APPLICATION_JSON); -// entityBuilder.setText(CustomUtil.objectMapper.writeValueAsString(body)); - httpPost.setEntity(multipartEntityBuilder.build()); + String payload; + if((payload = body.remove("payload")).equals(JSON)) { + EntityBuilder entityBuilder = EntityBuilder.create(); + entityBuilder.setContentType(ContentType.APPLICATION_JSON); + entityBuilder.setText(CustomUtil.objectMapper.writeValueAsString(body)); + httpPost.setEntity(entityBuilder.build()); + } else if(payload.equals(FORM_DATA)) { + MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); + body.forEach(multipartEntityBuilder::addTextBody); + httpPost.setEntity(multipartEntityBuilder.build()); + } } httpResponse = httpClient.execute(httpPost); }