优化
This commit is contained in:
@@ -101,12 +101,18 @@ public class LocalQualificationStorage {
|
||||
}
|
||||
|
||||
public Resource load(long tenantId, String fileName) {
|
||||
if (!fileName.matches("[0-9a-fA-F-]{36}\\.(jpg|png|pdf)")) throw new BizException("Invalid file name");
|
||||
if (fileName == null || !fileName.matches("[0-9a-fA-F-]{36}\\.(jpg|png|pdf)")) {
|
||||
throw fileNotFound();
|
||||
}
|
||||
Path directory = tenantDirectory(tenantId);
|
||||
Path target = directory.resolve(fileName).normalize();
|
||||
if (!target.startsWith(directory) || !Files.isRegularFile(target)) throw new BizException("File not found");
|
||||
if (!target.startsWith(directory) || !Files.isRegularFile(target)) throw fileNotFound();
|
||||
try { return new UrlResource(target.toUri()); }
|
||||
catch (Exception exception) { throw new BizException("File not found"); }
|
||||
catch (Exception exception) { throw fileNotFound(); }
|
||||
}
|
||||
|
||||
private BizException fileNotFound() {
|
||||
return new BizException(ResultCode.NOT_FOUND, "File not found");
|
||||
}
|
||||
|
||||
public void delete(StoredFile file) {
|
||||
|
||||
Reference in New Issue
Block a user