mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-02-24 14:15:24 +00:00
158
web-service/src/main/java/cn/qaiu/lz/web/http/ServerApi.java
Normal file
158
web-service/src/main/java/cn/qaiu/lz/web/http/ServerApi.java
Normal file
@@ -0,0 +1,158 @@
|
||||
package cn.qaiu.lz.web.http;
|
||||
|
||||
import cn.qaiu.lz.common.util.CowTool;
|
||||
import cn.qaiu.lz.common.util.EcTool;
|
||||
import cn.qaiu.lz.common.util.LzTool;
|
||||
import cn.qaiu.lz.common.util.UcTool;
|
||||
import cn.qaiu.lz.web.model.SysUser;
|
||||
import cn.qaiu.lz.web.service.UserService;
|
||||
import cn.qaiu.vx.core.annotaions.RouteHandler;
|
||||
import cn.qaiu.vx.core.annotaions.RouteMapping;
|
||||
import cn.qaiu.vx.core.enums.RouteMethod;
|
||||
import cn.qaiu.vx.core.model.JsonResult;
|
||||
import cn.qaiu.vx.core.util.AsyncServiceUtil;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.http.HttpServerRequest;
|
||||
import io.vertx.core.http.HttpServerResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static io.vertx.core.http.HttpHeaders.CONTENT_TYPE;
|
||||
|
||||
/**
|
||||
* 服务API
|
||||
* <br>Create date 2021/4/28 9:15
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Slf4j
|
||||
@RouteHandler("/")
|
||||
public class ServerApi {
|
||||
|
||||
private final UserService userService = AsyncServiceUtil.getAsyncServiceInstance(UserService.class);
|
||||
|
||||
@RouteMapping(value = "/login", method = RouteMethod.POST)
|
||||
public Future<String> login(SysUser user) {
|
||||
log.info("<------- login: {}", user.getUsername());
|
||||
return userService.login(user);
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/test2", method = RouteMethod.GET)
|
||||
public JsonResult<String> test01() {
|
||||
return JsonResult.data("ok");
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/parser", method = RouteMethod.GET)
|
||||
public Future<Void> parse(HttpServerResponse response, HttpServerRequest request, String url, String pwd) {
|
||||
Promise<Void> promise = Promise.promise();
|
||||
if (url.contains("lanzou")) {
|
||||
String urlDownload = null;
|
||||
try {
|
||||
urlDownload = LzTool.parse(url);
|
||||
log.info("url = {}", urlDownload);
|
||||
response.putHeader("location", urlDownload).setStatusCode(302).end();
|
||||
promise.complete();
|
||||
} catch (Exception e) {
|
||||
promise.fail(e);
|
||||
}
|
||||
} else if (url.contains("cowtransfer.com")) {
|
||||
String urlDownload = null;
|
||||
try {
|
||||
urlDownload = CowTool.parse(url);
|
||||
response.putHeader("location", urlDownload).setStatusCode(302).end();
|
||||
promise.complete();
|
||||
} catch (Exception e) {
|
||||
promise.fail(e);
|
||||
}
|
||||
|
||||
} else if (url.contains(EcTool.EC_HOST)) {
|
||||
// 默认读取Url参数会被截断手动获取一下其他参数
|
||||
String data = request.getParam("data");
|
||||
EcTool.parse(data).onSuccess(resUrl -> {
|
||||
response.putHeader("location", resUrl).setStatusCode(302).end();
|
||||
promise.complete();
|
||||
}).onFailure(t -> {
|
||||
promise.fail(t.fillInStackTrace());
|
||||
});
|
||||
} else if (url.contains(UcTool.FULL_URL_PREFIX)) {
|
||||
UcTool.parse(url, pwd).onSuccess(resUrl -> {
|
||||
response.putHeader("location", resUrl).setStatusCode(302).end();
|
||||
promise.complete();
|
||||
}).onFailure(t -> {
|
||||
promise.fail(t.fillInStackTrace());
|
||||
});
|
||||
}
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/lz/:id", method = RouteMethod.GET)
|
||||
public void lzParse(HttpServerResponse response, String id) throws Exception {
|
||||
var url = "https://wwsd.lanzoue.com/" + id;
|
||||
var urlDownload = LzTool.parse(url);
|
||||
log.info("url = {}", urlDownload);
|
||||
response.putHeader("location", urlDownload).setStatusCode(302).end();
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/cow/:id", method = RouteMethod.GET)
|
||||
public void cowParse(HttpServerResponse response, String id) throws Exception {
|
||||
var url = "https://cowtransfer.com/s/" + id;
|
||||
var urlDownload = CowTool.parse(url);
|
||||
response.putHeader("location", urlDownload).setStatusCode(302).end();
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/json/lz/:id", method = RouteMethod.GET)
|
||||
public JsonResult<String> lzParseJson(HttpServerResponse response, String id) throws Exception {
|
||||
var url = "https://wwsd.lanzoue.com/" + id;
|
||||
var urlDownload = LzTool.parse(url);
|
||||
log.info("url = {}", urlDownload);
|
||||
return JsonResult.data(urlDownload);
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/json/cow/:id", method = RouteMethod.GET)
|
||||
public JsonResult<String> cowParseJson(HttpServerResponse response, String id) throws Exception {
|
||||
var url = "https://cowtransfer.com/s/" + id;
|
||||
return JsonResult.data(CowTool.parse(url));
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/ec/:id", method = RouteMethod.GET)
|
||||
public void ecParse(HttpServerResponse response, String id) {
|
||||
EcTool.parse(id).onSuccess(resUrl -> {
|
||||
response.putHeader("location", resUrl).setStatusCode(302).end();
|
||||
}).onFailure(t -> {
|
||||
response.putHeader(CONTENT_TYPE, "text/html;charset=utf-8");
|
||||
response.end(t.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/json/ec/:id", method = RouteMethod.GET)
|
||||
public Future<String> ecParseJson(HttpServerResponse response, String id) {
|
||||
return EcTool.parse(id);
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/uc/:id", method = RouteMethod.GET)
|
||||
public void ucParse(HttpServerResponse response, String id) {
|
||||
String code = "";
|
||||
if (id.contains("#")) {
|
||||
String[] ids = id.split("#");
|
||||
id = ids[0];
|
||||
code = ids[1];
|
||||
}
|
||||
UcTool.parse(id, code).onSuccess(resUrl -> {
|
||||
response.putHeader("location", resUrl).setStatusCode(302).end();
|
||||
}).onFailure(t -> {
|
||||
response.putHeader(CONTENT_TYPE, "text/html;charset=utf-8");
|
||||
response.end(t.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
@RouteMapping(value = "/json/uc/:id", method = RouteMethod.GET)
|
||||
public Future<String> ucParseJson(String id) {
|
||||
String code = "";
|
||||
if (id.contains("#")) {
|
||||
String[] ids = id.split("#");
|
||||
id = ids[0];
|
||||
code = ids[1];
|
||||
}
|
||||
return UcTool.parse(id, code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package cn.qaiu.lz.web.model;
|
||||
|
||||
public class CowUser {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package cn.qaiu.lz.web.model;
|
||||
|
||||
public class LzUser {
|
||||
}
|
||||
26
web-service/src/main/java/cn/qaiu/lz/web/model/SysUser.java
Normal file
26
web-service/src/main/java/cn/qaiu/lz/web/model/SysUser.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package cn.qaiu.lz.web.model;
|
||||
|
||||
import cn.qaiu.db.ddl.Table;
|
||||
import cn.qaiu.lz.common.ToJson;
|
||||
import io.vertx.codegen.annotations.DataObject;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DataObject
|
||||
@Table("t_user")
|
||||
public class SysUser implements ToJson {
|
||||
private String id;
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public SysUser(JsonObject json) {
|
||||
this.username = json.getString("username");
|
||||
this.password = json.getString("password");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.qaiu.lz.web.service;
|
||||
|
||||
import cn.qaiu.lz.common.model.UserInfo;
|
||||
import cn.qaiu.vx.core.base.BaseAsyncService;
|
||||
import io.vertx.codegen.annotations.ProxyGen;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
/**
|
||||
* lz-web
|
||||
* <br>Create date 2021/7/12 17:16
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@ProxyGen
|
||||
public interface DbService extends BaseAsyncService {
|
||||
Future<JsonObject> sayOk(String data);
|
||||
Future<JsonObject> sayOk2(String data, UserInfo holder);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.qaiu.lz.web.service;
|
||||
|
||||
import cn.qaiu.vx.core.util.CastUtil;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
/**
|
||||
* JDK代理类工厂
|
||||
*/
|
||||
public class JdkProxyFactory {
|
||||
public static <T> T getProxy(T target) {
|
||||
return CastUtil.cast(Proxy.newProxyInstance(
|
||||
target.getClass().getClassLoader(),
|
||||
target.getClass().getInterfaces(),
|
||||
new ServiceJdkProxy<>(target))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.qaiu.lz.web.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* lz-web
|
||||
* <br>Create date 2021/8/25 14:28
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Slf4j
|
||||
public class ServiceJdkProxy<T> implements InvocationHandler {
|
||||
|
||||
private final T target;
|
||||
|
||||
public ServiceJdkProxy(T target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
|
||||
return method.invoke(target, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.qaiu.lz.web.service;
|
||||
|
||||
import cn.qaiu.lz.web.model.SysUser;
|
||||
import cn.qaiu.vx.core.base.BaseAsyncService;
|
||||
import io.vertx.codegen.annotations.ProxyGen;
|
||||
import io.vertx.core.Future;
|
||||
|
||||
/**
|
||||
* lz-web
|
||||
* <br>Create date 2021/8/27 14:06
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@ProxyGen
|
||||
public interface UserService extends BaseAsyncService {
|
||||
Future<String> login(SysUser user);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.qaiu.lz.web.service.impl;
|
||||
|
||||
import cn.qaiu.lz.common.model.UserInfo;
|
||||
import cn.qaiu.lz.web.service.DbService;
|
||||
import cn.qaiu.vx.core.annotaions.Service;
|
||||
import cn.qaiu.vx.core.model.JsonResult;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* lz-web
|
||||
* <br>Create date 2021/7/12 17:26
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DbServiceImpl implements DbService {
|
||||
@Override
|
||||
public Future<JsonObject> sayOk(String data) {
|
||||
log.info("say ok1 -> wait...");
|
||||
try {
|
||||
Thread.sleep(4000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Future.succeededFuture(JsonObject.mapFrom(JsonResult.data("Hi: " + data)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<JsonObject> sayOk2(String data, UserInfo holder) {
|
||||
// val context = VertxHolder.getVertxInstance().getOrCreateContext();
|
||||
// log.info("say ok2 -> " + context.get("username"));
|
||||
// log.info("--> {}", holder.toString());
|
||||
return Future.succeededFuture(JsonObject.mapFrom(JsonResult.data("Hi: " + data)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.qaiu.lz.web.service.impl;
|
||||
|
||||
import cn.qaiu.lz.web.model.SysUser;
|
||||
import cn.qaiu.lz.web.service.UserService;
|
||||
import cn.qaiu.vx.core.annotaions.Service;
|
||||
import io.vertx.core.Future;
|
||||
|
||||
/**
|
||||
* lz-web
|
||||
* <br>Create date 2021/8/27 14:09
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
public Future<String> login(SysUser user) {
|
||||
|
||||
return Future.succeededFuture("111");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user