Skip to content

Commit f6fbd60

Browse files
authored
Merge pull request #112 from jwdeveloper/develop-1.8.11
Develop 1.8.11
2 parents 2dc3001 + 437335f commit f6fbd60

File tree

11 files changed

+45
-40
lines changed

11 files changed

+45
-40
lines changed

API/src/main/java/io/github/jwdeveloper/tiktok/data/events/websocket/TikTokWebsocketUnhandledMessageEvent.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
2929
import lombok.Getter;
3030

31-
32-
3331
@Getter
3432
@EventMeta(eventType = EventType.Debug)
3533
public class TikTokWebsocketUnhandledMessageEvent extends TikTokUnhandledEvent<WebcastResponse.Message>
@@ -42,4 +40,4 @@ public WebcastResponse.Message getMessage()
4240
{
4341
return this.getData();
4442
}
45-
}
43+
}

API/src/main/java/io/github/jwdeveloper/tiktok/data/models/Picture.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.awt.image.BufferedImage;
3131
import java.io.*;
3232
import java.net.URL;
33+
import java.util.Objects;
3334
import java.util.concurrent.CompletableFuture;
3435

3536
public class Picture {
@@ -85,8 +86,7 @@ private BufferedImage download(String urlString) {
8586
throw new TikTokLiveException("Unable map downloaded image", e);
8687
}
8788

88-
var bais = new ByteArrayInputStream(baos.toByteArray());
89-
try {
89+
try (var bais = new ByteArrayInputStream(baos.toByteArray())) {
9090
return ImageIO.read(bais);
9191
} catch (IOException e) {
9292
throw new TikTokLiveException("Unable map downloaded image bytes to Image", e);
@@ -97,8 +97,25 @@ public static Picture empty() {
9797
return new Picture("");
9898
}
9999

100+
public Picture asUnsigned() {
101+
if (link == null || link.isEmpty())
102+
return this;
103+
// p16-sign-va.tiktokcdn.com -> p16-va.tiktokcdn.com || p16-sign.tiktokcdn.com -> p16.tiktokcdn.com
104+
return new Picture(link.replace("-sign-", "-").replace("-sign.", "."));
105+
}
106+
100107
@Override
101108
public String toString() {
102109
return "Picture{link='" + link + "', image=" + image + "}";
103110
}
111+
112+
@Override
113+
public final boolean equals(Object o) {
114+
return o == this || o instanceof Picture picture && picture.link != null && picture.link.equals(link);
115+
}
116+
117+
@Override
118+
public int hashCode() {
119+
return Objects.hashCode(link);
120+
}
104121
}

API/src/main/java/io/github/jwdeveloper/tiktok/data/requests/GiftsData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929

3030
public class GiftsData
3131
{
32-
@Getter
32+
@Data
3333
@AllArgsConstructor
3434
public static final class Response
3535
{
36-
private String json;
37-
private List<Gift> gifts;
36+
private final String json;
37+
private final List<Gift> gifts;
3838
}
3939
}

API/src/main/java/io/github/jwdeveloper/tiktok/data/requests/LiveConnectionData.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,19 @@
2828
import lombok.Getter;
2929

3030
import java.net.URI;
31-
import java.time.Duration;
3231

3332
public class LiveConnectionData {
3433
@Getter
3534
@AllArgsConstructor
3635
public static class Request {
37-
private String roomId;
36+
private final String roomId;
3837
}
3938

40-
@Getter
39+
@Data
4140
@AllArgsConstructor
4241
public static class Response {
43-
private String websocketCookies;
44-
private URI websocketUrl;
45-
private WebcastResponse webcastResponse;
42+
private final String websocketCookies;
43+
private final URI websocketUrl;
44+
private final WebcastResponse webcastResponse;
4645
}
47-
}
46+
}

API/src/main/java/io/github/jwdeveloper/tiktok/data/requests/LiveData.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class LiveData {
3131
@Getter
3232
@AllArgsConstructor
3333
public static class Request {
34-
private String roomId;
34+
private final String roomId;
3535
}
3636

3737
@Data
@@ -46,11 +46,7 @@ public static class Response {
4646
private boolean ageRestricted;
4747
private User host;
4848
private LiveType liveType;
49-
public Response() {
50-
51-
}
52-
53-
49+
public Response() {}
5450
}
5551

5652
public enum LiveStatus {

API/src/main/java/io/github/jwdeveloper/tiktok/data/requests/LiveUserData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public Request(String userName) {
3838
}
3939
}
4040

41-
@Getter
41+
@Data
4242
@AllArgsConstructor
4343
public static class Response {
4444
private final String json;

API/src/main/java/io/github/jwdeveloper/tiktok/live/LiveMessagesHandler.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,10 @@
2222
*/
2323
package io.github.jwdeveloper.tiktok.live;
2424

25-
import io.github.jwdeveloper.tiktok.data.dto.MessageMetaData;
26-
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
27-
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketMessageEvent;
28-
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketResponseEvent;
29-
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
30-
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveMessageException;
3125
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
32-
import io.github.jwdeveloper.tiktok.utils.Stopwatch;
33-
34-
import java.time.Duration;
3526

3627
public interface LiveMessagesHandler {
3728
void handle(LiveClient client, WebcastResponse webcastResponse);
3829

3930
void handleSingleMessage(LiveClient client, WebcastResponse.Message message);
40-
}
31+
}

Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ protected ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
225225
if (clientSettings.getApiKey() != null)
226226
builder.withParam("apiKey", clientSettings.getApiKey());
227227

228-
var result = builder.build().toResponse();
228+
var result = builder.build().toHttpResponse(HttpResponse.BodyHandlers.ofByteArray());
229229

230230
if (result.isFailure())
231231
throw new TikTokSignServerException("Unable to get websocket connection credentials - "+result);

Client/src/main/java/io/github/jwdeveloper/tiktok/http/HttpClient.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public class HttpClient {
4242
protected final String url;
4343
private final Pattern pattern = Pattern.compile("charset=(.*?)(?=&|$)");
4444

45-
public ActionResult<HttpResponse<byte[]>> toResponse() {
45+
public <T> ActionResult<HttpResponse<T>> toHttpResponse(HttpResponse.BodyHandler<T> handler) {
4646
var client = prepareClient();
4747
var request = prepareGetRequest();
4848
try {
49-
var response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
49+
var response = client.send(request, handler);
5050
var result = ActionResult.of(response);
5151
return switch (response.statusCode()) {
5252
case 420 -> result.message("HttpResponse Code:", response.statusCode(), "| IP Cloudflare Blocked.").failure();
@@ -68,8 +68,12 @@ public ActionResult<HttpResponse<byte[]>> toResponse() {
6868
}
6969
}
7070

71+
public <T> ActionResult<T> toResponse(HttpResponse.BodyHandler<T> handler) {
72+
return toHttpResponse(handler).map(HttpResponse::body);
73+
}
74+
7175
public ActionResult<String> toJsonResponse() {
72-
return toResponse().map(content -> new String(content.body(), charsetFrom(content.headers())));
76+
return toResponse(HttpResponse.BodyHandlers.ofString());
7377
}
7478

7579
private Charset charsetFrom(HttpHeaders headers) {
@@ -87,7 +91,7 @@ private Charset charsetFrom(HttpHeaders headers) {
8791
}
8892

8993
public ActionResult<byte[]> toBinaryResponse() {
90-
return toResponse().map(HttpResponse::body);
94+
return toResponse(HttpResponse.BodyHandlers.ofByteArray());
9195
}
9296

9397
public URI toUri() {

Client/src/main/java/io/github/jwdeveloper/tiktok/http/HttpProxyClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public ActionResult<HttpResponse<byte[]>> handleHttpProxyRequest() {
7777
throw new TikTokProxyRequestException(e);
7878
} catch (IOException e) {
7979
if (e.getMessage().contains("503") && proxySettings.isFallback()) // Indicates proxy protocol is not supported
80-
return super.toResponse();
80+
return super.toHttpResponse(HttpResponse.BodyHandlers.ofByteArray());
8181
throw new TikTokProxyRequestException(e);
8282
} catch (Exception e) {
8383
throw new TikTokLiveRequestException(e);
@@ -122,7 +122,7 @@ public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {}
122122
return ActionResult.success(response);
123123
} catch (IOException e) {
124124
if (e.getMessage().contains("503") && proxySettings.isFallback()) // Indicates proxy protocol is not supported
125-
return super.toResponse();
125+
return super.toHttpResponse(HttpResponse.BodyHandlers.ofByteArray());
126126
if (proxySettings.isAutoDiscard())
127127
proxySettings.remove();
128128
throw new TikTokProxyRequestException(e);

0 commit comments

Comments
 (0)