mirror of https://github.com/hykilpikonna/AquaDX
[+] Return AquaNet profile photo as maimai userPortrait
parent
fde952fcd9
commit
f7c842774b
|
@ -1,9 +1,14 @@
|
||||||
package icu.samnyan.aqua.sega.maimai2.handler;
|
package icu.samnyan.aqua.sega.maimai2.handler;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import icu.samnyan.aqua.net.db.AquaNetUser;
|
||||||
|
import icu.samnyan.aqua.net.utils.PathProps;
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
import icu.samnyan.aqua.sega.general.BaseHandler;
|
||||||
|
import icu.samnyan.aqua.sega.general.dao.CardRepository;
|
||||||
|
import icu.samnyan.aqua.sega.general.model.Card;
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.request.data.UserPortrait;
|
import icu.samnyan.aqua.sega.maimai2.model.request.data.UserPortrait;
|
||||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
@ -11,7 +16,6 @@ import org.springframework.security.crypto.codec.Utf8;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -23,22 +27,18 @@ public class GetUserPortraitHandler implements BaseHandler {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GetUserPortraitHandler.class);
|
private static final Logger logger = LoggerFactory.getLogger(GetUserPortraitHandler.class);
|
||||||
|
|
||||||
private final BasicMapper mapper;
|
private final BasicMapper mapper;
|
||||||
private final String picSavePath;
|
|
||||||
private final boolean enable;
|
private final boolean enable;
|
||||||
|
private final CardRepository cardRepo;
|
||||||
|
private final String portraitPath;
|
||||||
|
|
||||||
public GetUserPortraitHandler(BasicMapper mapper,
|
public GetUserPortraitHandler(BasicMapper mapper,
|
||||||
@Value("${game.maimai2.userPhoto.enable:true}") boolean enable,
|
@Value("${game.maimai2.userPhoto.enable:true}") boolean enable,
|
||||||
@Value("${paths.mai2-portrait:data/userPhoto}") String picSavePath) {
|
CardRepository cardRepo,
|
||||||
|
PathProps paths) {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.picSavePath = picSavePath;
|
|
||||||
this.enable = enable;
|
this.enable = enable;
|
||||||
|
this.cardRepo = cardRepo;
|
||||||
if (enable) {
|
this.portraitPath = paths.getAquaNetPortrait();
|
||||||
try {
|
|
||||||
Files.createDirectories(Paths.get(picSavePath));
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,14 +46,13 @@ public class GetUserPortraitHandler implements BaseHandler {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
var userId = ((Number) request.get("userId")).longValue();
|
var userId = ((Number) request.get("userId")).longValue();
|
||||||
var list = new ArrayList<UserPortrait>();
|
var list = new ArrayList<UserPortrait>();
|
||||||
|
var card = cardRepo.findByExtId(userId);
|
||||||
|
var user = card.map(Card::getAquaUser);
|
||||||
|
var profilePicture = user.map(AquaNetUser::getProfilePicture).orElse(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var filePath = Paths.get(picSavePath, userId + "-up.jpg");
|
if (!StringUtils.isEmpty(profilePicture)) {
|
||||||
|
var filePath = Paths.get(portraitPath, profilePicture);
|
||||||
if (Files.exists(filePath)) {
|
|
||||||
var templateJsonStr = Files.readString(Paths.get(picSavePath, userId + "-up.json"));
|
|
||||||
var templateUserPortrait = mapper.read(templateJsonStr, UserPortrait.class);
|
|
||||||
|
|
||||||
var buffer = new byte[10240];
|
var buffer = new byte[10240];
|
||||||
|
|
||||||
var stream = new FileInputStream(filePath.toFile());
|
var stream = new FileInputStream(filePath.toFile());
|
||||||
|
@ -64,11 +63,11 @@ public class GetUserPortraitHandler implements BaseHandler {
|
||||||
|
|
||||||
var userPortrait = new UserPortrait();
|
var userPortrait = new UserPortrait();
|
||||||
|
|
||||||
userPortrait.setFileName(templateUserPortrait.getFileName());
|
userPortrait.setFileName("portrait.jpg");
|
||||||
userPortrait.setPlaceId(templateUserPortrait.getPlaceId());
|
userPortrait.setPlaceId(0);
|
||||||
userPortrait.setUserId(templateUserPortrait.getUserId());
|
userPortrait.setUserId(userId);
|
||||||
userPortrait.setClientId(templateUserPortrait.getClientId());
|
userPortrait.setClientId("");
|
||||||
userPortrait.setUploadDate(templateUserPortrait.getUploadDate());
|
userPortrait.setUploadDate("1970-01-01 09:00:00.0");
|
||||||
userPortrait.setDivData(Utf8.decode(Base64.getEncoder().encode(encodeBuffer)));
|
userPortrait.setDivData(Utf8.decode(Base64.getEncoder().encode(encodeBuffer)));
|
||||||
|
|
||||||
userPortrait.setDivNumber(list.size());
|
userPortrait.setDivNumber(list.size());
|
||||||
|
|
Loading…
Reference in New Issue