上线OSS备份功能
This commit is contained in:
parent
44e0a866a3
commit
8491879c2a
@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import;
|
||||
@Import(BTDownloadManager.class)
|
||||
@SpringBootApplication
|
||||
public class NasApplication {
|
||||
public static final String version="1.1.3";
|
||||
public static final String version="1.1.4";
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(NasApplication.class, args);
|
||||
AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
||||
|
@ -187,7 +187,6 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
try {
|
||||
if(getMusicData(file.getAbsolutePath())==null) {
|
||||
musicDataDao.insert(data);
|
||||
OSSManager.upload(OSSManager.TYPE_MUSIC,musicPath,file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -3,6 +3,7 @@ package com.yutou.nas.other;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.nas.NasApplication;
|
||||
import com.yutou.nas.utils.DepotManager;
|
||||
import com.yutou.nas.utils.RedisTools;
|
||||
import com.yutou.nas.utils.Tools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@ -16,7 +17,6 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class tools {
|
||||
@ -118,5 +118,11 @@ public class tools {
|
||||
}
|
||||
return RedisTools.get("request");
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/public/deport.do")
|
||||
public String testDeport(){
|
||||
DepotManager.scan();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user