Skip to content

Commit 527dd0e

Browse files
committed
城通分享格式适配, 优化日志打印
1 parent 74ed747 commit 527dd0e

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

core-database/src/main/java/cn/qaiu/db/ddl/CreateTable.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import io.vertx.codegen.format.Case;
77
import io.vertx.codegen.format.LowerCamelCase;
88
import io.vertx.codegen.format.SnakeCase;
9+
import io.vertx.core.Future;
10+
import io.vertx.core.Promise;
911
import io.vertx.jdbcclient.JDBCPool;
1012
import io.vertx.sqlclient.templates.annotations.Column;
1113
import io.vertx.sqlclient.templates.annotations.RowMapped;
@@ -14,9 +16,7 @@
1416
import org.slf4j.LoggerFactory;
1517

1618
import java.lang.reflect.Field;
17-
import java.util.HashMap;
18-
import java.util.Map;
19-
import java.util.Set;
19+
import java.util.*;
2020

2121
/**
2222
* 创建表
@@ -161,17 +161,27 @@ public static String getCreateTableSQL(Class<?> clz, JDBCType type) {
161161
return sql.substring(0, sql.length() - 1) + endStr;
162162
}
163163

164-
public static void createTable(JDBCPool pool, JDBCType type) {
164+
public static Future<Void> createTable(JDBCPool pool, JDBCType type) {
165165
Set<Class<?>> tableClassList = ReflectionUtil.getReflections().getTypesAnnotatedWith(Table.class);
166166
if (tableClassList.isEmpty()) LOGGER.info("Table model class not fount");
167+
List<Future<Object>> futures = new ArrayList<>();
167168
tableClassList.forEach(clazz -> {
168169
String createTableSQL = getCreateTableSQL(clazz, type);
169-
170-
pool.query(createTableSQL).execute().onSuccess(
171-
rs -> LOGGER.info("table auto generate:\n" + createTableSQL)
172-
).onFailure(e -> {
170+
Future<Object> future = pool.query(createTableSQL).execute().compose(rs -> {
171+
LOGGER.info("table auto generate:\n" + createTableSQL);
172+
return Future.succeededFuture();
173+
}).onFailure(e -> {
173174
LOGGER.error(e.getMessage() + " SQL: \n" + createTableSQL);
174175
});
176+
futures.add(future);
175177
});
178+
179+
Promise<Void> promise = Promise.promise();
180+
Future.all(futures).onSuccess(r -> {
181+
LOGGER.info("create table success");
182+
promise.complete();
183+
}).onFailure(promise::fail);
184+
185+
return promise.future();
176186
}
177187
}

core-database/src/main/java/cn/qaiu/db/pool/JDBCPoolInit.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cn.qaiu.db.ddl.CreateTable;
44
import cn.qaiu.db.ddl.CreateDatabase;
55
import cn.qaiu.vx.core.util.VertxHolder;
6+
import io.vertx.core.Future;
67
import io.vertx.core.Vertx;
78
import io.vertx.core.json.JsonObject;
89
import io.vertx.jdbcclient.JDBCPool;
@@ -80,10 +81,10 @@ public JDBCPoolInit build() {
8081
* init h2db<br>
8182
* 这个方法只允许调用一次
8283
*/
83-
synchronized public void initPool() {
84+
synchronized public Future<Void> initPool() {
8485
if (pool != null) {
8586
LOGGER.error("pool 重复初始化");
86-
return;
87+
return null;
8788
}
8889

8990
// 初始化数据库连接
@@ -92,8 +93,8 @@ synchronized public void initPool() {
9293
CreateDatabase.createDatabase(dbConfig);
9394
}
9495
pool = JDBCPool.pool(vertx, dbConfig);
95-
CreateTable.createTable(pool, type);
9696
LOGGER.info("数据库连接初始化: URL=" + url);
97+
return CreateTable.createTable(pool, type);
9798
}
9899

99100
/**

parser/src/main/java/cn/qaiu/parser/impl/CtTool.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,25 @@
99
import io.vertx.ext.web.client.HttpRequest;
1010
import io.vertx.uritemplate.UriTemplate;
1111

12+
import java.net.MalformedURLException;
13+
import java.net.URL;
14+
import java.util.regex.Pattern;
15+
1216
/**
1317
* <a href="https://www.ctfile.com">诚通网盘</a>
1418
*/
1519
public class CtTool extends PanBase {
1620
private static final String API_URL_PREFIX = "https://webapi.ctfile.com";
1721

18-
private static final String API1 = API_URL_PREFIX + "/getfile.php?path=file" +
22+
// https://webapi.ctfile.com/getfile.php?path=f&f=55050874-1246660795-6464f6&
23+
// passcode=7548&token=30wiijxs1fzhb6brw0p9m6&r=0.5885881231735761&
24+
// ref=&url=https%3A%2F%2F474b.com%2Ff%2F55050874-1246660795-6464f6%3Fp%3D7548
25+
private static final String API1 = API_URL_PREFIX + "/getfile.php?path={path}" +
1926
"&f={shareKey}&passcode={pwd}&token={token}&r={rand}&ref=";
2027

28+
//https://webapi.ctfile.com/get_file_url.php?uid=55050874&fid=1246660795&folder_id=0&
29+
// file_chk=054bc20461f5c63ff82015b9e69fb7fc&mb=1&token=30wiijxs1fzhb6brw0p9m6&app=0&
30+
// acheck=1&verifycode=&rd=0.965929071503574
2131
private static final String API2 = API_URL_PREFIX + "/get_file_url.php?" +
2232
"uid={uid}&fid={fid}&folder_id=0&file_chk={file_chk}&mb=0&token={token}&app=0&acheck=0&verifycode=" +
2333
"&rd={rand}";
@@ -49,8 +59,13 @@ public Future<String> parse() {
4959
String[] split = shareKey.split("-");
5060
String uid = split[0], fid = split[1];
5161
String token = RandomStringGenerator.generateRandomString();
62+
// 获取url path
63+
int i1 = shareLinkInfo.getShareUrl().indexOf("com/");
64+
int i2 = shareLinkInfo.getShareUrl().lastIndexOf("/");
65+
String path = shareLinkInfo.getShareUrl().substring(i1 + 4, i2);
5266

5367
HttpRequest<Buffer> bufferHttpRequest1 = clientSession.getAbs(UriTemplate.of(API1))
68+
.setTemplateParam("path", path)
5469
.setTemplateParam("shareKey", shareKey)
5570
.setTemplateParam("pwd", shareLinkInfo.getSharePassword())
5671
.setTemplateParam("token", token)
@@ -79,10 +94,10 @@ public Future<String> parse() {
7994
}
8095
}).onFailure(handleFail(bufferHttpRequest1.queryParams().toString()));
8196
} else {
82-
fail("解析失败, 可能分享已失效: json: {} 字段 {} 不存在", resJson, "file_chk");
97+
fail("解析失败, file_chk找不到, 可能分享已失效或者分享密码不对: {}", fileJson);
8398
}
8499
} else {
85-
fail("解析失败, 可能分享已失效: json: {} 字段 {} 不存在", resJson, "file");
100+
fail("解析失败, 文件信息为空, 可能分享已失效");
86101
}
87102
}).onFailure(handleFail(bufferHttpRequest1.queryParams().toString()));
88103
return promise.future();

web-service/src/main/java/cn/qaiu/lz/AppMain.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import io.vertx.core.json.JsonObject;
1212
import io.vertx.core.json.jackson.DatabindCodec;
1313
import io.vertx.core.shareddata.LocalMap;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
1416

1517
import static cn.qaiu.vx.core.util.ConfigConstant.LOCAL;
1618

@@ -23,6 +25,8 @@
2325
*/
2426
public class AppMain {
2527

28+
private static final Logger LOGGER = LoggerFactory.getLogger(AppMain.class);
29+
2630
public static void main(String[] args) {
2731
Deploy.instance().start(args, AppMain::exec);
2832
}
@@ -38,7 +42,13 @@ private static void exec(JsonObject jsonObject) {
3842
DatabindCodec.mapper().registerModule(new JavaTimeModule());
3943
// 数据库
4044
if (jsonObject.getJsonObject(ConfigConstant.SERVER).getBoolean("enableDatabase")) {
41-
JDBCPoolInit.builder().config(jsonObject.getJsonObject("dataSource")).build().initPool();
45+
JDBCPoolInit.builder().config(jsonObject.getJsonObject("dataSource"))
46+
.build()
47+
.initPool().onSuccess(PreparedStatement -> {
48+
LOGGER.info("数据库连接成功");
49+
String addr = jsonObject.getJsonObject(ConfigConstant.SERVER).getString("domainName");
50+
LOGGER.info("启动成功: \n本地服务地址: {}", addr);
51+
});
4252
}
4353
// 缓存
4454
if (jsonObject.containsKey(ConfigConstant.CACHE)) {

0 commit comments

Comments
 (0)