上线OSS备份功能
This commit is contained in:
@@ -37,6 +37,9 @@ public class ApplicationInit implements ApplicationRunner {
|
||||
case "00:00":
|
||||
musicTools.scanMusic();
|
||||
break;
|
||||
case "01:00":
|
||||
DepotManager.scan();
|
||||
break;
|
||||
case "08:00":
|
||||
case "20:00":
|
||||
QQBotManager.getInstance().reportToDayBangumi();
|
||||
|
||||
@@ -1,10 +1,48 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DepotManager {
|
||||
private DepotManager(){
|
||||
|
||||
}
|
||||
public static void scan(){
|
||||
|
||||
String str=HttpTools.get("http://tools.yutou233.cn/nas/depot/list.do");
|
||||
if(!StringUtils.isEmpty(str)){
|
||||
JSONObject json=JSONObject.parseObject(str);
|
||||
if(json.getInteger("code")==1){
|
||||
JSONArray array=json.getJSONArray("data");
|
||||
for (Object o : array) {
|
||||
JSONObject item=JSONObject.parseObject(o.toString());
|
||||
scanFile(new File(item.getString("path")), new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
super.onDownload(file);
|
||||
OSSManager.upload("oss-name-"+item.getString("type"),item.getString("path"),file);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void scanFile(File path, DownloadInterface interfaces){
|
||||
if(!path.exists()){
|
||||
interfaces.onError(new FileNotFoundException("没有该文件"));
|
||||
return;
|
||||
}
|
||||
for (File file : Objects.requireNonNull(path.listFiles())) {
|
||||
if(file.isDirectory()){
|
||||
scanFile(file,interfaces);
|
||||
}else{
|
||||
interfaces.onDownload(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.yutou.nas.interfaces.DownloadInterface;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class OSSManager {
|
||||
public static final String TYPE_MUSIC = "oss-name-music";
|
||||
@@ -27,13 +28,22 @@ public class OSSManager {
|
||||
|
||||
|
||||
public static void upload(String type, String path, File... files) {
|
||||
if (type.equals(TYPE_MUSIC) && !ConfigTools.load(ConfigTools.CONFIG, TYPE_MUSIC, boolean.class, false)) {
|
||||
return;
|
||||
boolean music=false,photo=false,depot=false;
|
||||
if (type.equals(TYPE_MUSIC) && !ConfigTools.load(ConfigTools.CONFIG, "oss-upload-music", boolean.class, false)) {
|
||||
music=true;
|
||||
}
|
||||
if (type.equals(TYPE_PHOTO) && !ConfigTools.load(ConfigTools.CONFIG, TYPE_PHOTO, boolean.class, false)) {
|
||||
return;
|
||||
if (type.equals(TYPE_PHOTO) && !ConfigTools.load(ConfigTools.CONFIG, "oss-upload-photo", boolean.class, false)) {
|
||||
photo=true;
|
||||
}
|
||||
if (type.equals(TYPE_DEPOT) && !ConfigTools.load(ConfigTools.CONFIG, TYPE_DEPOT, boolean.class, false)) {
|
||||
if (type.equals(TYPE_DEPOT) && !ConfigTools.load(ConfigTools.CONFIG, "oss-upload-depot", boolean.class, false)) {
|
||||
depot=true;
|
||||
}
|
||||
if(music||photo||depot){
|
||||
System.out.println("music = " + music);
|
||||
System.out.println("photo = " + photo);
|
||||
System.out.println("depot = " + depot);
|
||||
System.out.println("type = " + type + ", path = " + path + ", files = " + Arrays.deepToString(files));
|
||||
System.out.println("------------------------------");
|
||||
return;
|
||||
}
|
||||
new Thread(() -> {
|
||||
@@ -46,7 +56,13 @@ public class OSSManager {
|
||||
if (uploadPath.startsWith("/")) {
|
||||
uploadPath = uploadPath.substring(1);
|
||||
}
|
||||
client.putObject(type, uploadPath, file);
|
||||
if(isExist(ConfigTools.load(ConfigTools.CONFIG,type,String.class),uploadPath)){
|
||||
System.out.println("文件已存在:"+file.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
client.putObject(ConfigTools.load(ConfigTools.CONFIG,type,String.class), uploadPath, file);
|
||||
System.out.println(file.getName()+"已上传");
|
||||
}
|
||||
closeClient(client);
|
||||
}).start();
|
||||
|
||||
Reference in New Issue
Block a user