Add API - Get user photos (mai)

Add:
New API to return  user photos.
Fix bug:
Missing dependency: ObjectMapper
This commit is contained in:
肥宅虾哥 2023-12-07 19:13:13 +08:00 committed by GitHub
parent 564ada10f5
commit e7848cb965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,8 @@
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;
@ -21,9 +23,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 +94,28 @@ public class ApiMaimai2PlayerDataController {
return divMaxLength;
}
@GetMapping("userPhoto")
public List<String> getUserPhoto(@RequestParam long aimeId) {
List<String> matchedFiles = new ArrayList<>();
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()
.collect(Collectors.toList());
matchedFiles.forEach(System.out::println);
} catch (IOException e) {
}
return matchedFiles;
}
@GetMapping("profile")
public ProfileResp getProfile(@RequestParam long aimeId) {
return mapper.convert(userDataRepository.findByCard_ExtId(aimeId).orElseThrow(), new TypeReference<>() {