Skip to content

Commit

Permalink
update: Adds method to extract file name from URL in StudentServiceImpl.
Browse files Browse the repository at this point in the history
Signed-off-by: 自由的世界人 <3196812536@qq.com>
  • Loading branch information
Pleasurecruise committed Nov 27, 2024
1 parent dc01c7d commit 0fa02fb
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public Student update(StudentDTO studentDTO) throws Exception {
String accessToken = getAccessToken();
boolean isUsernameSafe = contentCheckUtil.checkTextContent(studentDTO.getUsername(), 1, student.getOpenid(), accessToken);

String photoName = extractFileName(student.getAvatar());
String photoName = student.getAvatar();
ImageModerationResponse response = ImageCheckUtil.invokeFunction(
aliOssUtil.getAccessKeyId(),
aliOssUtil.getAccessKeySecret(),
Expand All @@ -296,16 +296,14 @@ public Student update(StudentDTO studentDTO) throws Exception {
throw new TeapotException(MessageConstant.CONTENT_UNSECURED);
}
if (!isAvatarSafe) {
String objectName = extractFileName(studentDTO.getAvatar());
aliOssUtil.delete(objectName);
aliOssUtil.delete(studentDTO.getAvatar());
throw new TeapotException(MessageConstant.CONTENT_UNSECURED);
}

String currentAvatarName = extractFileName(student.getAvatar());
String newAvatarName = extractFileName(studentDTO.getAvatar());
String currentAvatarName = student.getAvatar();
String newAvatarName = studentDTO.getAvatar();
if (!currentAvatarName.equals(newAvatarName) && !student.getAvatar().contains("default.jpg")) {
String objectName = extractFileName(student.getAvatar());
aliOssUtil.delete(objectName);
aliOssUtil.delete(currentAvatarName);
}

student.setUsername(studentDTO.getUsername());
Expand Down

0 comments on commit 0fa02fb

Please sign in to comment.