|
|
@@ -93,20 +93,28 @@ public class UserAvatarServiceImpl implements UserAvatarService {
|
|
|
try {
|
|
|
Long uid = Long.parseLong(userId);
|
|
|
UserInfo ui = userInfoMapper.selectById(uid);
|
|
|
- if (ui == null || ui.getAvatar() == null || ui.getAvatar().isEmpty()) {
|
|
|
+ if (ui == null) {
|
|
|
+ logger.warn("[AvatarLoad] userId={}, 用户不存在", userId);
|
|
|
return null;
|
|
|
}
|
|
|
+ String avatarPath = ui.getAvatar();
|
|
|
+ if (avatarPath == null || avatarPath.isEmpty()) {
|
|
|
+ logger.info("[AvatarLoad] userId={}, avatar字段为空", userId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ logger.debug("[AvatarLoad] userId={}, avatarPath={}", userId, avatarPath);
|
|
|
Path root = Paths.get(avatarProperties.getRootPath() == null ? "avatar-storage" : avatarProperties.getRootPath());
|
|
|
- Path file = root.resolve(ui.getAvatar()).normalize();
|
|
|
+ Path file = root.resolve(avatarPath).normalize();
|
|
|
Path rootReal = root.toAbsolutePath().normalize();
|
|
|
if (!file.toAbsolutePath().startsWith(rootReal)) {
|
|
|
- logger.error("[AvatarLoad] userId={}, error=路径穿越", userId);
|
|
|
+ logger.error("[AvatarLoad] userId={}, error=路径穿越, avatarPath={}", userId, avatarPath);
|
|
|
return null;
|
|
|
}
|
|
|
if (!Files.exists(file)) {
|
|
|
- logger.info("[AvatarLoad] userId={}, file not exists {}", userId, file);
|
|
|
+ logger.warn("[AvatarLoad] userId={}, file not exists {}, avatarPath={}", userId, file, avatarPath);
|
|
|
return null;
|
|
|
}
|
|
|
+ logger.debug("[AvatarLoad] userId={}, 成功加载文件 {}", userId, file);
|
|
|
return new FileSystemResource(file.toFile());
|
|
|
} catch (NumberFormatException e) {
|
|
|
logger.error("[AvatarLoad] invalid userId {}", userId);
|