|
|
@@ -237,16 +237,62 @@ public class NjsSceneBoxModelServiceImpl extends ServiceImpl<INjsSceneBoxModelMa
|
|
|
public void publicNjsSceneBoxModel(String num) throws IOException {
|
|
|
List<NjsSceneBoxModel> list = lambdaQuery().eq(NjsSceneBoxModel::getNum, num).list();
|
|
|
String njsBoxModelKey = String.format(UploadFilePath.USER_EDIT_PATH, num) + "njsBoxModels.json";
|
|
|
- if(list.isEmpty() && fYunFileService.fileExist(njsBoxModelKey)){
|
|
|
- fYunFileService.deleteFile(njsBoxModelKey);
|
|
|
+ String njsBoxModelDir = String.format(UploadFilePath.USER_EDIT_PATH, num) + "njsBoxModels";
|
|
|
+ if(list.isEmpty()){
|
|
|
+ if(fYunFileService.fileExist(njsBoxModelKey)){
|
|
|
+ fYunFileService.deleteFile(njsBoxModelKey);
|
|
|
+ }
|
|
|
+ if(fYunFileService.fileExist(njsBoxModelDir)){
|
|
|
+ fYunFileService.deleteFile(njsBoxModelDir);
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ //删除无效文件
|
|
|
+ Set<String> prefixList = list.stream().map(v -> njsBoxModelDir + "/" + v.getData().getString("sid")).collect(Collectors.toSet());
|
|
|
+ List<String> keyList = fYunFileService.listRemoteFiles(njsBoxModelDir);
|
|
|
+ if(!keyList.isEmpty()){
|
|
|
+ keyList.removeIf(file ->
|
|
|
+ prefixList.stream().anyMatch(file::startsWith)
|
|
|
+ );
|
|
|
+ if(!keyList.isEmpty()){
|
|
|
+ keyList.stream().forEach(key -> {
|
|
|
+ try {
|
|
|
+ fYunFileService.deleteFile(key);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
List<JSONObject> collect = list.stream().map(v -> v.getData()).collect(Collectors.toList());
|
|
|
fYunFileService.uploadFile(JSON.toJSONString(collect).getBytes(StandardCharsets.UTF_8), njsBoxModelKey);
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- System.out.println(Instant.EPOCH.toEpochMilli());
|
|
|
+ List<String> prefixes = Arrays.asList(
|
|
|
+ "img/",
|
|
|
+ "video/2025/",
|
|
|
+ "model/mesh/"
|
|
|
+ );
|
|
|
+
|
|
|
+ List<String> files = new ArrayList<>(Arrays.asList(
|
|
|
+ "img/a.png",
|
|
|
+ "img/b.jpg",
|
|
|
+ "tmp/c.txt",
|
|
|
+ "video/2024/d.mp4",
|
|
|
+ "model/mesh/x.obj"
|
|
|
+ ));
|
|
|
+
|
|
|
+ files.removeIf(file ->
|
|
|
+ prefixes.stream().anyMatch(file::startsWith)
|
|
|
+ );
|
|
|
+
|
|
|
+ System.out.println(files);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|