mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2025-12-16 20:33:03 +00:00
城通分享格式适配, 优化日志打印
This commit is contained in:
@@ -6,6 +6,8 @@ import io.vertx.codegen.format.CamelCase;
|
|||||||
import io.vertx.codegen.format.Case;
|
import io.vertx.codegen.format.Case;
|
||||||
import io.vertx.codegen.format.LowerCamelCase;
|
import io.vertx.codegen.format.LowerCamelCase;
|
||||||
import io.vertx.codegen.format.SnakeCase;
|
import io.vertx.codegen.format.SnakeCase;
|
||||||
|
import io.vertx.core.Future;
|
||||||
|
import io.vertx.core.Promise;
|
||||||
import io.vertx.jdbcclient.JDBCPool;
|
import io.vertx.jdbcclient.JDBCPool;
|
||||||
import io.vertx.sqlclient.templates.annotations.Column;
|
import io.vertx.sqlclient.templates.annotations.Column;
|
||||||
import io.vertx.sqlclient.templates.annotations.RowMapped;
|
import io.vertx.sqlclient.templates.annotations.RowMapped;
|
||||||
@@ -14,9 +16,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建表
|
* 创建表
|
||||||
@@ -161,17 +161,27 @@ public class CreateTable {
|
|||||||
return sql.substring(0, sql.length() - 1) + endStr;
|
return sql.substring(0, sql.length() - 1) + endStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createTable(JDBCPool pool, JDBCType type) {
|
public static Future<Void> createTable(JDBCPool pool, JDBCType type) {
|
||||||
Set<Class<?>> tableClassList = ReflectionUtil.getReflections().getTypesAnnotatedWith(Table.class);
|
Set<Class<?>> tableClassList = ReflectionUtil.getReflections().getTypesAnnotatedWith(Table.class);
|
||||||
if (tableClassList.isEmpty()) LOGGER.info("Table model class not fount");
|
if (tableClassList.isEmpty()) LOGGER.info("Table model class not fount");
|
||||||
|
List<Future<Object>> futures = new ArrayList<>();
|
||||||
tableClassList.forEach(clazz -> {
|
tableClassList.forEach(clazz -> {
|
||||||
String createTableSQL = getCreateTableSQL(clazz, type);
|
String createTableSQL = getCreateTableSQL(clazz, type);
|
||||||
|
Future<Object> future = pool.query(createTableSQL).execute().compose(rs -> {
|
||||||
pool.query(createTableSQL).execute().onSuccess(
|
LOGGER.info("table auto generate:\n" + createTableSQL);
|
||||||
rs -> LOGGER.info("table auto generate:\n" + createTableSQL)
|
return Future.succeededFuture();
|
||||||
).onFailure(e -> {
|
}).onFailure(e -> {
|
||||||
LOGGER.error(e.getMessage() + " SQL: \n" + createTableSQL);
|
LOGGER.error(e.getMessage() + " SQL: \n" + createTableSQL);
|
||||||
});
|
});
|
||||||
|
futures.add(future);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Promise<Void> promise = Promise.promise();
|
||||||
|
Future.all(futures).onSuccess(r -> {
|
||||||
|
LOGGER.info("create table success");
|
||||||
|
promise.complete();
|
||||||
|
}).onFailure(promise::fail);
|
||||||
|
|
||||||
|
return promise.future();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cn.qaiu.db.pool;
|
|||||||
import cn.qaiu.db.ddl.CreateTable;
|
import cn.qaiu.db.ddl.CreateTable;
|
||||||
import cn.qaiu.db.ddl.CreateDatabase;
|
import cn.qaiu.db.ddl.CreateDatabase;
|
||||||
import cn.qaiu.vx.core.util.VertxHolder;
|
import cn.qaiu.vx.core.util.VertxHolder;
|
||||||
|
import io.vertx.core.Future;
|
||||||
import io.vertx.core.Vertx;
|
import io.vertx.core.Vertx;
|
||||||
import io.vertx.core.json.JsonObject;
|
import io.vertx.core.json.JsonObject;
|
||||||
import io.vertx.jdbcclient.JDBCPool;
|
import io.vertx.jdbcclient.JDBCPool;
|
||||||
@@ -80,10 +81,10 @@ public class JDBCPoolInit {
|
|||||||
* init h2db<br>
|
* init h2db<br>
|
||||||
* 这个方法只允许调用一次
|
* 这个方法只允许调用一次
|
||||||
*/
|
*/
|
||||||
synchronized public void initPool() {
|
synchronized public Future<Void> initPool() {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
LOGGER.error("pool 重复初始化");
|
LOGGER.error("pool 重复初始化");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化数据库连接
|
// 初始化数据库连接
|
||||||
@@ -92,8 +93,8 @@ public class JDBCPoolInit {
|
|||||||
CreateDatabase.createDatabase(dbConfig);
|
CreateDatabase.createDatabase(dbConfig);
|
||||||
}
|
}
|
||||||
pool = JDBCPool.pool(vertx, dbConfig);
|
pool = JDBCPool.pool(vertx, dbConfig);
|
||||||
CreateTable.createTable(pool, type);
|
|
||||||
LOGGER.info("数据库连接初始化: URL=" + url);
|
LOGGER.info("数据库连接初始化: URL=" + url);
|
||||||
|
return CreateTable.createTable(pool, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,15 +9,25 @@ import io.vertx.core.json.JsonObject;
|
|||||||
import io.vertx.ext.web.client.HttpRequest;
|
import io.vertx.ext.web.client.HttpRequest;
|
||||||
import io.vertx.uritemplate.UriTemplate;
|
import io.vertx.uritemplate.UriTemplate;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <a href="https://www.ctfile.com">诚通网盘</a>
|
* <a href="https://www.ctfile.com">诚通网盘</a>
|
||||||
*/
|
*/
|
||||||
public class CtTool extends PanBase {
|
public class CtTool extends PanBase {
|
||||||
private static final String API_URL_PREFIX = "https://webapi.ctfile.com";
|
private static final String API_URL_PREFIX = "https://webapi.ctfile.com";
|
||||||
|
|
||||||
private static final String API1 = API_URL_PREFIX + "/getfile.php?path=file" +
|
// https://webapi.ctfile.com/getfile.php?path=f&f=55050874-1246660795-6464f6&
|
||||||
|
// passcode=7548&token=30wiijxs1fzhb6brw0p9m6&r=0.5885881231735761&
|
||||||
|
// ref=&url=https%3A%2F%2F474b.com%2Ff%2F55050874-1246660795-6464f6%3Fp%3D7548
|
||||||
|
private static final String API1 = API_URL_PREFIX + "/getfile.php?path={path}" +
|
||||||
"&f={shareKey}&passcode={pwd}&token={token}&r={rand}&ref=";
|
"&f={shareKey}&passcode={pwd}&token={token}&r={rand}&ref=";
|
||||||
|
|
||||||
|
//https://webapi.ctfile.com/get_file_url.php?uid=55050874&fid=1246660795&folder_id=0&
|
||||||
|
// file_chk=054bc20461f5c63ff82015b9e69fb7fc&mb=1&token=30wiijxs1fzhb6brw0p9m6&app=0&
|
||||||
|
// acheck=1&verifycode=&rd=0.965929071503574
|
||||||
private static final String API2 = API_URL_PREFIX + "/get_file_url.php?" +
|
private static final String API2 = API_URL_PREFIX + "/get_file_url.php?" +
|
||||||
"uid={uid}&fid={fid}&folder_id=0&file_chk={file_chk}&mb=0&token={token}&app=0&acheck=0&verifycode=" +
|
"uid={uid}&fid={fid}&folder_id=0&file_chk={file_chk}&mb=0&token={token}&app=0&acheck=0&verifycode=" +
|
||||||
"&rd={rand}";
|
"&rd={rand}";
|
||||||
@@ -49,8 +59,13 @@ public class CtTool extends PanBase {
|
|||||||
String[] split = shareKey.split("-");
|
String[] split = shareKey.split("-");
|
||||||
String uid = split[0], fid = split[1];
|
String uid = split[0], fid = split[1];
|
||||||
String token = RandomStringGenerator.generateRandomString();
|
String token = RandomStringGenerator.generateRandomString();
|
||||||
|
// 获取url path
|
||||||
|
int i1 = shareLinkInfo.getShareUrl().indexOf("com/");
|
||||||
|
int i2 = shareLinkInfo.getShareUrl().lastIndexOf("/");
|
||||||
|
String path = shareLinkInfo.getShareUrl().substring(i1 + 4, i2);
|
||||||
|
|
||||||
HttpRequest<Buffer> bufferHttpRequest1 = clientSession.getAbs(UriTemplate.of(API1))
|
HttpRequest<Buffer> bufferHttpRequest1 = clientSession.getAbs(UriTemplate.of(API1))
|
||||||
|
.setTemplateParam("path", path)
|
||||||
.setTemplateParam("shareKey", shareKey)
|
.setTemplateParam("shareKey", shareKey)
|
||||||
.setTemplateParam("pwd", shareLinkInfo.getSharePassword())
|
.setTemplateParam("pwd", shareLinkInfo.getSharePassword())
|
||||||
.setTemplateParam("token", token)
|
.setTemplateParam("token", token)
|
||||||
@@ -79,10 +94,10 @@ public class CtTool extends PanBase {
|
|||||||
}
|
}
|
||||||
}).onFailure(handleFail(bufferHttpRequest1.queryParams().toString()));
|
}).onFailure(handleFail(bufferHttpRequest1.queryParams().toString()));
|
||||||
} else {
|
} else {
|
||||||
fail("解析失败, 可能分享已失效: json: {} 字段 {} 不存在", resJson, "file_chk");
|
fail("解析失败, file_chk找不到, 可能分享已失效或者分享密码不对: {}", fileJson);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fail("解析失败, 可能分享已失效: json: {} 字段 {} 不存在", resJson, "file");
|
fail("解析失败, 文件信息为空, 可能分享已失效");
|
||||||
}
|
}
|
||||||
}).onFailure(handleFail(bufferHttpRequest1.queryParams().toString()));
|
}).onFailure(handleFail(bufferHttpRequest1.queryParams().toString()));
|
||||||
return promise.future();
|
return promise.future();
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import io.vertx.core.json.JsonArray;
|
|||||||
import io.vertx.core.json.JsonObject;
|
import io.vertx.core.json.JsonObject;
|
||||||
import io.vertx.core.json.jackson.DatabindCodec;
|
import io.vertx.core.json.jackson.DatabindCodec;
|
||||||
import io.vertx.core.shareddata.LocalMap;
|
import io.vertx.core.shareddata.LocalMap;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import static cn.qaiu.vx.core.util.ConfigConstant.LOCAL;
|
import static cn.qaiu.vx.core.util.ConfigConstant.LOCAL;
|
||||||
|
|
||||||
@@ -23,6 +25,8 @@ import static cn.qaiu.vx.core.util.ConfigConstant.LOCAL;
|
|||||||
*/
|
*/
|
||||||
public class AppMain {
|
public class AppMain {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(AppMain.class);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Deploy.instance().start(args, AppMain::exec);
|
Deploy.instance().start(args, AppMain::exec);
|
||||||
}
|
}
|
||||||
@@ -38,7 +42,13 @@ public class AppMain {
|
|||||||
DatabindCodec.mapper().registerModule(new JavaTimeModule());
|
DatabindCodec.mapper().registerModule(new JavaTimeModule());
|
||||||
// 数据库
|
// 数据库
|
||||||
if (jsonObject.getJsonObject(ConfigConstant.SERVER).getBoolean("enableDatabase")) {
|
if (jsonObject.getJsonObject(ConfigConstant.SERVER).getBoolean("enableDatabase")) {
|
||||||
JDBCPoolInit.builder().config(jsonObject.getJsonObject("dataSource")).build().initPool();
|
JDBCPoolInit.builder().config(jsonObject.getJsonObject("dataSource"))
|
||||||
|
.build()
|
||||||
|
.initPool().onSuccess(PreparedStatement -> {
|
||||||
|
LOGGER.info("数据库连接成功");
|
||||||
|
String addr = jsonObject.getJsonObject(ConfigConstant.SERVER).getString("domainName");
|
||||||
|
LOGGER.info("启动成功: \n本地服务地址: {}", addr);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// 缓存
|
// 缓存
|
||||||
if (jsonObject.containsKey(ConfigConstant.CACHE)) {
|
if (jsonObject.containsKey(ConfigConstant.CACHE)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user