城通分享格式适配, 优化日志打印

This commit is contained in:
QAIU
2025-03-28 17:59:28 +08:00
parent 74ed7475c9
commit 527dd0eeb4
4 changed files with 51 additions and 15 deletions

View File

@@ -6,6 +6,8 @@ import io.vertx.codegen.format.CamelCase;
import io.vertx.codegen.format.Case;
import io.vertx.codegen.format.LowerCamelCase;
import io.vertx.codegen.format.SnakeCase;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.jdbcclient.JDBCPool;
import io.vertx.sqlclient.templates.annotations.Column;
import io.vertx.sqlclient.templates.annotations.RowMapped;
@@ -14,9 +16,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* 创建表
@@ -161,17 +161,27 @@ public class CreateTable {
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);
if (tableClassList.isEmpty()) LOGGER.info("Table model class not fount");
List<Future<Object>> futures = new ArrayList<>();
tableClassList.forEach(clazz -> {
String createTableSQL = getCreateTableSQL(clazz, type);
pool.query(createTableSQL).execute().onSuccess(
rs -> LOGGER.info("table auto generate:\n" + createTableSQL)
).onFailure(e -> {
Future<Object> future = pool.query(createTableSQL).execute().compose(rs -> {
LOGGER.info("table auto generate:\n" + createTableSQL);
return Future.succeededFuture();
}).onFailure(e -> {
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();
}
}

View File

@@ -3,6 +3,7 @@ package cn.qaiu.db.pool;
import cn.qaiu.db.ddl.CreateTable;
import cn.qaiu.db.ddl.CreateDatabase;
import cn.qaiu.vx.core.util.VertxHolder;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.jdbcclient.JDBCPool;
@@ -80,10 +81,10 @@ public class JDBCPoolInit {
* init h2db<br>
* 这个方法只允许调用一次
*/
synchronized public void initPool() {
synchronized public Future<Void> initPool() {
if (pool != null) {
LOGGER.error("pool 重复初始化");
return;
return null;
}
// 初始化数据库连接
@@ -92,8 +93,8 @@ public class JDBCPoolInit {
CreateDatabase.createDatabase(dbConfig);
}
pool = JDBCPool.pool(vertx, dbConfig);
CreateTable.createTable(pool, type);
LOGGER.info("数据库连接初始化: URL=" + url);
return CreateTable.createTable(pool, type);
}
/**

View File

@@ -9,15 +9,25 @@ import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.HttpRequest;
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>
*/
public class CtTool extends PanBase {
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=";
//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?" +
"uid={uid}&fid={fid}&folder_id=0&file_chk={file_chk}&mb=0&token={token}&app=0&acheck=0&verifycode=" +
"&rd={rand}";
@@ -49,8 +59,13 @@ public class CtTool extends PanBase {
String[] split = shareKey.split("-");
String uid = split[0], fid = split[1];
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))
.setTemplateParam("path", path)
.setTemplateParam("shareKey", shareKey)
.setTemplateParam("pwd", shareLinkInfo.getSharePassword())
.setTemplateParam("token", token)
@@ -79,10 +94,10 @@ public class CtTool extends PanBase {
}
}).onFailure(handleFail(bufferHttpRequest1.queryParams().toString()));
} else {
fail("解析失败, 可能分享已失效: json: {} 字段 {} 不存在", resJson, "file_chk");
fail("解析失败, file_chk找不到, 可能分享已失效或者分享密码不对: {}", fileJson);
}
} else {
fail("解析失败, 可能分享已失效: json: {} 字段 {} 不存在", resJson, "file");
fail("解析失败, 文件信息为空, 可能分享已失效");
}
}).onFailure(handleFail(bufferHttpRequest1.queryParams().toString()));
return promise.future();

View File

@@ -11,6 +11,8 @@ import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.jackson.DatabindCodec;
import io.vertx.core.shareddata.LocalMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 {
private static final Logger LOGGER = LoggerFactory.getLogger(AppMain.class);
public static void main(String[] args) {
Deploy.instance().start(args, AppMain::exec);
}
@@ -38,7 +42,13 @@ public class AppMain {
DatabindCodec.mapper().registerModule(new JavaTimeModule());
// 数据库
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)) {