支持jar图床(img+开头)

pull/75/head
于俊 3 years ago
parent 746d2a665e
commit e55033595a
  1. 20
      app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java

@ -114,6 +114,16 @@ public class ApiConfig {
return json;
}
private static byte[] getImgJar(String body){
Pattern pattern = Pattern.compile("[A-Za-z0]{8}\\*\\*");
Matcher matcher = pattern.matcher(body);
if(matcher.find()){
body = body.substring(body.indexOf(matcher.group()) + 10);
return Base64.decode(body, Base64.DEFAULT);
}
return "".getBytes();
}
public void loadConfig(boolean useCache, LoadConfigCallback callback, Activity activity) {
String apiUrl = Hawk.get(HawkConfig.API_URL, "");
if (apiUrl.isEmpty()) {
@ -229,6 +239,8 @@ public class ApiConfig {
}
}
boolean isJarInImg = jarUrl.startsWith("img+");
jarUrl = jarUrl.replace("img+", "");
OkGo.<File>get(jarUrl)
.headers("User-Agent", userAgent)
.headers("Accept", requestAccept)
@ -242,7 +254,13 @@ public class ApiConfig {
if (cache.exists())
cache.delete();
FileOutputStream fos = new FileOutputStream(cache);
fos.write(response.body().bytes());
if(isJarInImg) {
String respData = response.body().string();
byte[] imgJar = getImgJar(respData);
fos.write(imgJar);
} else {
fos.write(response.body().bytes());
}
fos.flush();
fos.close();
return cache;

Loading…
Cancel
Save