mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-07-04 06:17:26 +00:00
[Change] 将'Proxy', 'CookieStore'转移到BotGlobal类;
This commit is contained in:
@ -4,7 +4,6 @@ import com.google.common.base.Strings;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.gson.*;
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import net.lamgc.cgj.Main;
|
||||
import net.lamgc.cgj.bot.boot.BotGlobal;
|
||||
import net.lamgc.cgj.bot.cache.*;
|
||||
import net.lamgc.cgj.bot.event.BufferMessageEvent;
|
||||
@ -37,9 +36,10 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
@SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter", "SameParameterValue"})
|
||||
public class BotCommandProcess {
|
||||
|
||||
private final static PixivDownload pixivDownload = new PixivDownload(Main.cookieStore, Main.proxy);
|
||||
private final static PixivDownload pixivDownload =
|
||||
new PixivDownload(BotGlobal.getGlobal().getCookieStore(), BotGlobal.getGlobal().getProxy());
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(BotCommandProcess.class.getName());
|
||||
private final static Logger log = LoggerFactory.getLogger(BotCommandProcess.class);
|
||||
|
||||
private final static File imageStoreDir = new File(BotGlobal.getGlobal().getDataStoreDir(), "data/image/cgj/");
|
||||
private final static Gson gson = new GsonBuilder()
|
||||
|
@ -18,6 +18,9 @@ public final class ApplicationBoot {
|
||||
*/
|
||||
public static void initialApplication(String[] args) {
|
||||
ArgumentsProperties argsProp = new ArgumentsProperties(args);
|
||||
if(!PropertiesUtils.getSettingToSysProp(argsProp, "proxy", null)) {
|
||||
PropertiesUtils.getEnvSettingToSysProp("CGJ_PROXY", "proxy", null);
|
||||
}
|
||||
if(!PropertiesUtils.getSettingToSysProp(argsProp, "botDataDir", "./") &&
|
||||
!PropertiesUtils.getEnvSettingToSysProp("CGJ_BOT_DATA_DIR", "botDataDir", "./")) {
|
||||
log.warn("未设置botDataDir, 当前运行目录将作为酷Q机器人所在目录.");
|
||||
|
@ -1,11 +1,16 @@
|
||||
package net.lamgc.cgj.bot.boot;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
public final class BotGlobal {
|
||||
|
||||
@ -29,6 +34,10 @@ public final class BotGlobal {
|
||||
|
||||
private final File dataStoreDir;
|
||||
|
||||
private final HttpHost proxy;
|
||||
|
||||
private CookieStore cookieStore;
|
||||
|
||||
private BotGlobal() {
|
||||
this.redisUri = URI.create("redis://" + System.getProperty("cgj.redisAddress"));
|
||||
this.redisServer = new JedisPool(
|
||||
@ -37,6 +46,19 @@ public final class BotGlobal {
|
||||
String dataStoreDirPath = System.getProperty("cgj.botDataDir");
|
||||
this.dataStoreDir = new File((!dataStoreDirPath.endsWith("/") || !dataStoreDirPath.endsWith("\\")) ?
|
||||
dataStoreDirPath + System.getProperty("file.separator") : dataStoreDirPath);
|
||||
|
||||
String proxyAddress = System.getProperty("cgj.proxy");
|
||||
HttpHost temp = null;
|
||||
if(!Strings.isNullOrEmpty(proxyAddress)) {
|
||||
try {
|
||||
URL proxyUrl = new URL(proxyAddress);
|
||||
temp = new HttpHost(proxyUrl.getHost(), proxyUrl.getPort());
|
||||
log.info("已启用Http协议代理:{}", temp.toHostString());
|
||||
} catch (MalformedURLException e) {
|
||||
log.error("Proxy地址解析失败, 代理将不会启用.", e);
|
||||
}
|
||||
}
|
||||
this.proxy = temp;
|
||||
}
|
||||
|
||||
public URI getRedisUri() {
|
||||
@ -53,4 +75,17 @@ public final class BotGlobal {
|
||||
public JedisPool getRedisServer() {
|
||||
return redisServer;
|
||||
}
|
||||
|
||||
public HttpHost getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
||||
public CookieStore getCookieStore() {
|
||||
return cookieStore;
|
||||
}
|
||||
|
||||
public void setCookieStore(CookieStore cookieStore) {
|
||||
this.cookieStore = cookieStore;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.lamgc.cgj.bot.cache;
|
||||
|
||||
import net.lamgc.cgj.Main;
|
||||
import net.lamgc.cgj.bot.boot.BotGlobal;
|
||||
import net.lamgc.cgj.bot.cache.exception.HttpRequestException;
|
||||
import net.lamgc.cgj.pixiv.PixivURL;
|
||||
import net.lamgc.cgj.util.URLs;
|
||||
@ -22,9 +22,11 @@ import java.util.Set;
|
||||
|
||||
public class ImageCacheHandler implements EventHandler {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(ImageCacheHandler.class.getName());
|
||||
private final static Logger log = LoggerFactory.getLogger(ImageCacheHandler.class);
|
||||
|
||||
private final static HttpClient httpClient = HttpClientBuilder.create().setProxy(Main.proxy).build();
|
||||
private final static HttpClient httpClient = HttpClientBuilder.create()
|
||||
.setProxy(BotGlobal.getGlobal().getProxy())
|
||||
.build();
|
||||
|
||||
private final static Set<ImageCacheObject> cacheQueue = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
|
Reference in New Issue
Block a user