Fix alist token header
This commit is contained in:
parent
39f99eedf8
commit
5b5e4d27f8
|
|
@ -6,6 +6,7 @@ import android.text.TextUtils;
|
|||
import com.github.catvod.bean.Class;
|
||||
import com.github.catvod.net.OkHttp;
|
||||
import com.github.catvod.utils.Image;
|
||||
import com.github.catvod.utils.Utils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
|
|
@ -32,6 +33,8 @@ public class Drive {
|
|||
private int version;
|
||||
@SerializedName("path")
|
||||
private String path;
|
||||
@SerializedName("token")
|
||||
private String token;
|
||||
|
||||
public static Drive objectFrom(String str) {
|
||||
return new Gson().fromJson(str, Drive.class);
|
||||
|
|
@ -81,6 +84,14 @@ public class Drive {
|
|||
this.path = TextUtils.isEmpty(path) ? "" : path;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return TextUtils.isEmpty(token) ? "" : token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public boolean isNew() {
|
||||
return getVersion() == 3;
|
||||
}
|
||||
|
|
@ -135,6 +146,13 @@ public class Drive {
|
|||
}
|
||||
}
|
||||
|
||||
public HashMap<String, String> getHeader() {
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", Utils.CHROME);
|
||||
if (!getToken().isEmpty()) headers.put("Authorization", token);
|
||||
return headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.github.catvod.bean.alist.Drive;
|
|||
import com.github.catvod.bean.alist.Item;
|
||||
import com.github.catvod.bean.alist.Sorter;
|
||||
import com.github.catvod.crawler.Spider;
|
||||
import com.github.catvod.crawler.SpiderDebug;
|
||||
import com.github.catvod.net.OkHttp;
|
||||
import com.github.catvod.utils.Utils;
|
||||
|
||||
|
|
@ -30,7 +31,6 @@ public class AList extends Spider {
|
|||
|
||||
private List<Drive> drives;
|
||||
private String vodPic;
|
||||
private String token;
|
||||
private String ext;
|
||||
|
||||
private List<Filter> getFilter() {
|
||||
|
|
@ -52,19 +52,13 @@ public class AList extends Spider {
|
|||
return drives.get(drives.indexOf(new Drive(name))).check();
|
||||
}
|
||||
|
||||
public HashMap<String, String> getHeader() {
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", Utils.CHROME);
|
||||
if (token != null) headers.put("Authorization", token);
|
||||
return headers;
|
||||
}
|
||||
|
||||
private String post(Drive drive, String url, String param) {
|
||||
return post(drive, url, param, true);
|
||||
}
|
||||
|
||||
private String post(Drive drive, String url, String param, boolean retry) {
|
||||
String response = OkHttp.postJson(url, param, getHeader()).getBody();
|
||||
String response = OkHttp.postJson(url, param, drive.getHeader()).getBody();
|
||||
SpiderDebug.log(response);
|
||||
if (retry && response.contains("Guest user is disabled") && login(drive)) return post(drive, url, param, false);
|
||||
return response;
|
||||
}
|
||||
|
|
@ -156,7 +150,7 @@ public class AList extends Spider {
|
|||
params.put("username", drive.getLogin().getUsername());
|
||||
params.put("password", drive.getLogin().getPassword());
|
||||
String response = OkHttp.postJson(drive.loginApi(), params.toString()).getBody();
|
||||
token = new JSONObject(response).getJSONObject("data").getString("token");
|
||||
drive.setToken(new JSONObject(response).getJSONObject("data").getString("token"));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
945ad30d5255359385ba59b8fb061bb7
|
||||
9eeae00749e17517c5041546a98418cd
|
||||
|
|
|
|||
Loading…
Reference in New Issue