尝试给OSS限速,好像失败了
This commit is contained in:
parent
8491879c2a
commit
3fcf1e72cc
@ -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");
|
||||
|
@ -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");
|
||||
|
||||
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());
|
||||
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);
|
||||
OSSManager.upload("oss-name-" + item.getString("type"), item.getString("path"), file);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void scanFile(File path, DownloadInterface interfaces){
|
||||
if(!path.exists()){
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user