diff --git a/src/main/java/com/yutou/nas/NasApplication.java b/src/main/java/com/yutou/nas/NasApplication.java index aa55454..6d02f39 100644 --- a/src/main/java/com/yutou/nas/NasApplication.java +++ b/src/main/java/com/yutou/nas/NasApplication.java @@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import; @Import(BTDownloadManager.class) @SpringBootApplication public class NasApplication { - public static final String version="1.1.4"; + public static final String version="1.1.4.2"; public static void main(String[] args) { SpringApplication.run(NasApplication.class, args); AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir"); diff --git a/src/main/java/com/yutou/nas/utils/DepotManager.java b/src/main/java/com/yutou/nas/utils/DepotManager.java index d331590..1c7af40 100644 --- a/src/main/java/com/yutou/nas/utils/DepotManager.java +++ b/src/main/java/com/yutou/nas/utils/DepotManager.java @@ -10,37 +10,45 @@ import java.io.FileNotFoundException; import java.util.Objects; public class DepotManager { - private 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); + + public static void scan() { + new Thread(new Runnable() { + @Override + public void run() { + String str = HttpTools.get("http://tools.yutou233.cn/nas/depot/list.do?token=" + HttpTools.serverKey); + 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); + } + }); } - }); + } } } - } + }).start(); + } - private static void scanFile(File path, DownloadInterface interfaces){ - if(!path.exists()){ + + 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{ + if (file.isDirectory()) { + scanFile(file, interfaces); + } else { interfaces.onDownload(file); } } diff --git a/src/main/java/com/yutou/nas/utils/HttpTools.java b/src/main/java/com/yutou/nas/utils/HttpTools.java index 7ec475f..456acb6 100644 --- a/src/main/java/com/yutou/nas/utils/HttpTools.java +++ b/src/main/java/com/yutou/nas/utils/HttpTools.java @@ -12,6 +12,7 @@ import java.net.URLEncoder; import java.util.Set; public class HttpTools { + public static final String serverKey="zIrsh9TUZP2lfRW753PannG49E7VJvor"; public static String get(String url) { try { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); diff --git a/src/main/java/com/yutou/nas/utils/OSSManager.java b/src/main/java/com/yutou/nas/utils/OSSManager.java index 9cde526..08ba3fe 100644 --- a/src/main/java/com/yutou/nas/utils/OSSManager.java +++ b/src/main/java/com/yutou/nas/utils/OSSManager.java @@ -4,6 +4,7 @@ import com.aliyun.oss.OSS; import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.model.OSSObject; import com.aliyun.oss.model.ObjectMetadata; +import com.aliyun.oss.model.PutObjectRequest; import com.aliyun.oss.model.StorageClass; import com.yutou.nas.interfaces.DownloadInterface; @@ -61,7 +62,11 @@ public class OSSManager { return; } - client.putObject(ConfigTools.load(ConfigTools.CONFIG,type,String.class), uploadPath, file); + //client.putObject(ConfigTools.load(ConfigTools.CONFIG,type,String.class), uploadPath, file); + int limitSpeed = 100 * 1024 * 8; + PutObjectRequest request=new PutObjectRequest(ConfigTools.load(ConfigTools.CONFIG,type,String.class),uploadPath,file); + request.setTrafficLimit(limitSpeed); + client.putObject(request); System.out.println(file.getName()+"已上传"); } closeClient(client);