1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2025-01-21 21:31:32 +01:00

Convert avatarImage fields to type byte[]

This commit is contained in:
Henry Le Grys 2021-02-16 17:39:54 +00:00
parent a7dcd2c7fb
commit ff12d154c8
7 changed files with 8 additions and 19 deletions

View File

@ -115,7 +115,7 @@ public class MicrosoftLoginService implements LoginService {
private final McProfileResponse profile; private final McProfileResponse profile;
private final Map<String, String> userProperties = Collections.emptyMap(); private final Map<String, String> userProperties = Collections.emptyMap();
private String refreshToken; private String refreshToken;
private String avatarImage; private byte[] avatarImage;
@Override @Override
public String getUuid() { public String getUuid() {

View File

@ -58,7 +58,7 @@ public class OfflineSession implements Session {
} }
@Override @Override
public String getAvatarImage() { public byte[] getAvatarImage() {
return null; return null;
} }

View File

@ -1,12 +1,9 @@
package com.skcraft.launcher.auth; package com.skcraft.launcher.auth;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.HashCodeBuilder;
import java.util.Base64;
/** /**
* Represents a session saved to disk. * Represents a session saved to disk.
*/ */
@ -18,12 +15,7 @@ public class SavedSession {
private String username; private String username;
private String accessToken; private String accessToken;
private String refreshToken; private String refreshToken;
private String avatarImage; private byte[] avatarImage;
@JsonIgnore
public byte[] getAvatarBytes() {
return Base64.getDecoder().decode(avatarImage);
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {

View File

@ -62,7 +62,7 @@ public interface Session {
* *
* @return User's avatar as a base64 string. * @return User's avatar as a base64 string.
*/ */
String getAvatarImage(); byte[] getAvatarImage();
/** /**
* Return true if the user is in an online session. * Return true if the user is in an online session.

View File

@ -3,20 +3,17 @@ package com.skcraft.launcher.auth;
import com.skcraft.launcher.util.HttpRequest; import com.skcraft.launcher.util.HttpRequest;
import java.io.IOException; import java.io.IOException;
import java.util.Base64;
import static com.skcraft.launcher.util.HttpRequest.url; import static com.skcraft.launcher.util.HttpRequest.url;
public class VisageSkinService { public class VisageSkinService {
public static String fetchSkinHead(String uuid) throws IOException, InterruptedException { public static byte[] fetchSkinHead(String uuid) throws IOException, InterruptedException {
String skinUrl = String.format("https://visage.surgeplay.com/face/32/%s.png", uuid); String skinUrl = String.format("https://visage.surgeplay.com/face/32/%s.png", uuid);
byte[] skinBytes = HttpRequest.get(url(skinUrl)) return HttpRequest.get(url(skinUrl))
.execute() .execute()
.expectResponseCode(200) .expectResponseCode(200)
.returnContent() .returnContent()
.asBytes(); .asBytes();
return Base64.getEncoder().encodeToString(skinBytes);
} }
} }

View File

@ -112,7 +112,7 @@ public class YggdrasilLoginService implements LoginService {
@JsonProperty("id") private String uuid; @JsonProperty("id") private String uuid;
private String name; private String name;
private boolean legacy; private boolean legacy;
private String avatarImage; private byte[] avatarImage;
@JsonIgnore private final Map<String, String> userProperties = Collections.emptyMap(); @JsonIgnore private final Map<String, String> userProperties = Collections.emptyMap();
@JsonBackReference private AuthenticateResponse response; @JsonBackReference private AuthenticateResponse response;

View File

@ -222,7 +222,7 @@ public class AccountSelectDialog extends JDialog {
public Component getListCellRendererComponent(JList<? extends SavedSession> list, SavedSession value, int index, boolean isSelected, boolean cellHasFocus) { public Component getListCellRendererComponent(JList<? extends SavedSession> list, SavedSession value, int index, boolean isSelected, boolean cellHasFocus) {
setText(value.getUsername()); setText(value.getUsername());
if (value.getAvatarImage() != null) { if (value.getAvatarImage() != null) {
setIcon(new ImageIcon(value.getAvatarBytes())); setIcon(new ImageIcon(value.getAvatarImage()));
} else { } else {
setIcon(SwingHelper.createIcon(Launcher.class, "default_skin.png", 32, 32)); setIcon(SwingHelper.createIcon(Launcher.class, "default_skin.png", 32, 32));
} }