修复返回path不是相对prefix的

This commit is contained in:
Jerry Yan 2024-12-29 18:06:30 +08:00
parent 5af3a14f03
commit 888698de73
3 changed files with 16 additions and 2 deletions

View File

@ -39,7 +39,7 @@ public abstract class AStorageAdapter implements IStorageAdapter {
@Override
public String getUrlForDownload(String... path) {
return getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), path);
return getUrlForDownload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), path);
}
@Override

View File

@ -130,7 +130,7 @@ final public class AliOssAdapter extends AStorageAdapter {
}
return objectList.stream().map(item -> {
StorageFileObject object = new StorageFileObject();
object.setPath(item.getKey().substring(0, item.getKey().lastIndexOf("/")));
object.setPath(getRelativePath(item.getKey().substring(0, item.getKey().lastIndexOf("/"))));
object.setName(item.getKey().substring(item.getKey().lastIndexOf("/") + 1));
object.setSize(item.getSize());
object.setRawObject(item);
@ -179,4 +179,8 @@ final public class AliOssAdapter extends AStorageAdapter {
return StorageUtil.joinPath(paths);
}
}
private String getRelativePath(String path) {
return StorageUtil.getRelativePath(path, config.getPrefix());
}
}

View File

@ -38,4 +38,14 @@ public class StorageUtil {
}
return name;
}
public static String getRelativePath(String fullPath, String relativeOn) {
if (StringUtils.isBlank(relativeOn)) {
fullPath = fullPath.replace(relativeOn, "");
}
if (fullPath.startsWith("/")) {
fullPath = fullPath.substring(1);
}
return fullPath;
}
}