mirror of https://github.com/hykilpikonna/AquaDX
[maimai2] Improve UserPortrait exception handling
Added default value for parameter and fix file read orderingpull/1/head
parent
c8902d73c2
commit
cc7b679dd3
|
@ -32,7 +32,9 @@ public class GetUserPortraitHandler implements BaseHandler {
|
||||||
private final String picSavePath;
|
private final String picSavePath;
|
||||||
private final boolean enable;
|
private final boolean enable;
|
||||||
|
|
||||||
public GetUserPortraitHandler(BasicMapper mapper, @Value("${game.maimai2.userPhoto.enable:}") boolean enable, @Value("${game.maimai2.userPhoto.picSavePath:}") String picSavePath) {
|
public GetUserPortraitHandler(BasicMapper mapper,
|
||||||
|
@Value("${game.maimai2.userPhoto.enable:true}") boolean enable,
|
||||||
|
@Value("${game.maimai2.userPhoto.picSavePath:data/userPhoto}") String picSavePath) {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.picSavePath = picSavePath;
|
this.picSavePath = picSavePath;
|
||||||
this.enable = enable;
|
this.enable = enable;
|
||||||
|
@ -54,12 +56,12 @@ public class GetUserPortraitHandler implements BaseHandler {
|
||||||
try {
|
try {
|
||||||
var filePath = Paths.get(picSavePath, userId + "-up.jpg");
|
var filePath = Paths.get(picSavePath, userId + "-up.jpg");
|
||||||
|
|
||||||
|
if (Files.exists(filePath)) {
|
||||||
var templateJsonStr = Files.readString(Paths.get(picSavePath, userId + "-up.json"));
|
var templateJsonStr = Files.readString(Paths.get(picSavePath, userId + "-up.json"));
|
||||||
var templateUserPortrait = mapper.read(templateJsonStr, UserPortrait.class);
|
var templateUserPortrait = mapper.read(templateJsonStr, UserPortrait.class);
|
||||||
|
|
||||||
var buffer = new byte[10240];
|
var buffer = new byte[10240];
|
||||||
|
|
||||||
if (Files.exists(filePath)) {
|
|
||||||
var stream = new FileInputStream(filePath.toFile());
|
var stream = new FileInputStream(filePath.toFile());
|
||||||
while (stream.available() > 0) {
|
while (stream.available() > 0) {
|
||||||
var read = stream.read(buffer, 0, 10240);
|
var read = stream.read(buffer, 0, 10240);
|
||||||
|
|
|
@ -28,7 +28,9 @@ public class UploadUserPortraitHandler implements BaseHandler {
|
||||||
private final String picSavePath;
|
private final String picSavePath;
|
||||||
private final boolean enable;
|
private final boolean enable;
|
||||||
|
|
||||||
public UploadUserPortraitHandler(BasicMapper mapper, @Value("${game.maimai2.userPhoto.enable:}") boolean enable, @Value("${game.maimai2.userPhoto.picSavePath:}") String picSavePath) {
|
public UploadUserPortraitHandler(BasicMapper mapper,
|
||||||
|
@Value("${game.maimai2.userPhoto.enable:true}") boolean enable,
|
||||||
|
@Value("${game.maimai2.userPhoto.picSavePath:data/userPhoto}") String picSavePath) {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.picSavePath = picSavePath;
|
this.picSavePath = picSavePath;
|
||||||
this.enable = enable;
|
this.enable = enable;
|
||||||
|
|
Loading…
Reference in New Issue