mirror of https://github.com/hykilpikonna/AquaDX
commit
722d415e75
|
@ -1,9 +1,12 @@
|
|||
package icu.samnyan.aqua.api.controller.sega.game.maimai2;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import icu.samnyan.aqua.api.model.MessageResponse;
|
||||
import icu.samnyan.aqua.api.model.ReducedPageResponse;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.maimai2.ProfileResp;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.maimai2.PhotoResp;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.maimai2.external.ExternalUserData;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.maimai2.external.Maimai2DataExport;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.maimai2.external.Maimai2DataImport;
|
||||
|
@ -21,9 +24,12 @@ import org.springframework.http.HttpStatus;
|
|||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
|
@ -89,6 +95,38 @@ public class ApiMaimai2PlayerDataController {
|
|||
return divMaxLength;
|
||||
}
|
||||
|
||||
@GetMapping("userPhoto")
|
||||
public PhotoResp getUserPhoto(@RequestParam long aimeId,
|
||||
@RequestParam(required = false, defaultValue = "0") int imageIndex) {
|
||||
List<String> matchedFiles = new ArrayList<>();
|
||||
PhotoResp Photo = new PhotoResp();
|
||||
try (Stream<Path> paths = Files.walk(Paths.get("data"))) {
|
||||
matchedFiles = paths
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(path -> path.getFileName().toString().endsWith(".jpg"))
|
||||
.filter(path -> {
|
||||
String fileName = path.getFileName().toString();
|
||||
String[] parts = fileName.split("-");
|
||||
return parts.length > 0 && parts[0].equals(String.valueOf(aimeId));
|
||||
})
|
||||
.map(Path::getFileName)
|
||||
.map(Path::toString)
|
||||
.sorted(Comparator.reverseOrder())
|
||||
.collect(Collectors.toList());
|
||||
Photo.setTotalImage(matchedFiles.size());
|
||||
Photo.setImageIndex(imageIndex);
|
||||
if(matchedFiles.size() > imageIndex){
|
||||
byte[] targetImageContent = Files.readAllBytes(Paths.get("data/" + matchedFiles.get(imageIndex)));
|
||||
String divData = Base64.getEncoder().encodeToString(targetImageContent);
|
||||
Photo.setDivData(divData);
|
||||
Photo.setFileName(matchedFiles.get(imageIndex));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
return Photo;
|
||||
}
|
||||
|
||||
@GetMapping("profile")
|
||||
public ProfileResp getProfile(@RequestParam long aimeId) {
|
||||
return mapper.convert(userDataRepository.findByCard_ExtId(aimeId).orElseThrow(), new TypeReference<>() {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package icu.samnyan.aqua.api.model.resp.sega.maimai2;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PhotoResp {
|
||||
private int imageIndex;
|
||||
private int totalImage;
|
||||
private String fileName;
|
||||
private String divData;
|
||||
}
|
Loading…
Reference in New Issue