Commit fb4f68d7 authored by Liang Ding's avatar Liang Ding

🎨 社区图床地址替换 #21

parent 012d0c46
...@@ -29,7 +29,7 @@ import java.util.concurrent.ThreadLocalRandom; ...@@ -29,7 +29,7 @@ import java.util.concurrent.ThreadLocalRandom;
* Image utilities. * Image utilities.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.2.0.0, Apr 30, 2020 * @version 1.2.0.1, May 15, 2020
* @since 2.7.0 * @since 2.7.0
*/ */
public final class Images { public final class Images {
...@@ -42,7 +42,7 @@ public final class Images { ...@@ -42,7 +42,7 @@ public final class Images {
/** /**
* Community file service URL. * Community file service URL.
*/ */
public static String COMMUNITY_FILE_URL = "https://img.hacpai.com"; public static String COMMUNITY_FILE_URL = "https://b3logdata.com";
/** /**
* Checks whether the specified URL has uploaded. * Checks whether the specified URL has uploaded.
...@@ -51,7 +51,7 @@ public final class Images { ...@@ -51,7 +51,7 @@ public final class Images {
* @return {@code true} if it has uploaded, returns {@code false} otherwise * @return {@code true} if it has uploaded, returns {@code false} otherwise
*/ */
public static boolean uploaded(final String url) { public static boolean uploaded(final String url) {
return StringUtils.startsWith(url, COMMUNITY_FILE_URL); return StringUtils.startsWith(url, COMMUNITY_FILE_URL) || StringUtils.startsWith(url, "https://img.hacpai.com");
} }
/** /**
...@@ -67,7 +67,7 @@ public final class Images { ...@@ -67,7 +67,7 @@ public final class Images {
for (final Element img : imgs) { for (final Element img : imgs) {
String imgSrc = img.attr("src"); String imgSrc = img.attr("src");
if (!StringUtils.startsWith(imgSrc, COMMUNITY_FILE_URL) || if (!uploaded(imgSrc) ||
StringUtils.contains(imgSrc, ".gif") || StringUtils.containsIgnoreCase(imgSrc, "imageView") || StringUtils.contains(imgSrc, ".gif") || StringUtils.containsIgnoreCase(imgSrc, "imageView") ||
StringUtils.containsIgnoreCase(imgSrc, "data:")) { StringUtils.containsIgnoreCase(imgSrc, "data:")) {
continue; continue;
...@@ -105,11 +105,9 @@ public final class Images { ...@@ -105,11 +105,9 @@ public final class Images {
final long max = System.currentTimeMillis(); final long max = System.currentTimeMillis();
final long delta = max - min; final long delta = max - min;
final long time = ThreadLocalRandom.current().nextLong(0, delta) + min; final long time = ThreadLocalRandom.current().nextLong(0, delta) + min;
return COMMUNITY_FILE_URL + "/bing/" + DateFormatUtils.format(time, "yyyyMMdd") + ".jpg"; return COMMUNITY_FILE_URL + "/bing/" + DateFormatUtils.format(time, "yyyyMMdd") + ".jpg";
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, "Generates random image URL failed", e); LOGGER.log(Level.ERROR, "Generates random image URL failed", e);
return COMMUNITY_FILE_URL + "/bing/20171104.jpg"; return COMMUNITY_FILE_URL + "/bing/20171104.jpg";
} }
} }
...@@ -122,7 +120,6 @@ public final class Images { ...@@ -122,7 +120,6 @@ public final class Images {
*/ */
public static List<String> randomImages(final int n) { public static List<String> randomImages(final int n) {
final List<String> ret = new ArrayList<>(); final List<String> ret = new ArrayList<>();
int i = 0; int i = 0;
while (i < n * 5) { while (i < n * 5) {
final String url = randImage(); final String url = randImage();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment