Fix alist token header

This commit is contained in:
FongMi 2023-05-22 14:58:20 +08:00
parent 39f99eedf8
commit 5b5e4d27f8
4 changed files with 23 additions and 11 deletions

View File

@ -6,6 +6,7 @@ import android.text.TextUtils;
import com.github.catvod.bean.Class; import com.github.catvod.bean.Class;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Image; import com.github.catvod.utils.Image;
import com.github.catvod.utils.Utils;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ -32,6 +33,8 @@ public class Drive {
private int version; private int version;
@SerializedName("path") @SerializedName("path")
private String path; private String path;
@SerializedName("token")
private String token;
public static Drive objectFrom(String str) { public static Drive objectFrom(String str) {
return new Gson().fromJson(str, Drive.class); return new Gson().fromJson(str, Drive.class);
@ -81,6 +84,14 @@ public class Drive {
this.path = TextUtils.isEmpty(path) ? "" : path; 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() { public boolean isNew() {
return getVersion() == 3; 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 @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) return true; if (this == obj) return true;

View File

@ -12,6 +12,7 @@ import com.github.catvod.bean.alist.Drive;
import com.github.catvod.bean.alist.Item; import com.github.catvod.bean.alist.Item;
import com.github.catvod.bean.alist.Sorter; import com.github.catvod.bean.alist.Sorter;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Utils;
@ -30,7 +31,6 @@ public class AList extends Spider {
private List<Drive> drives; private List<Drive> drives;
private String vodPic; private String vodPic;
private String token;
private String ext; private String ext;
private List<Filter> getFilter() { private List<Filter> getFilter() {
@ -52,19 +52,13 @@ public class AList extends Spider {
return drives.get(drives.indexOf(new Drive(name))).check(); 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) { private String post(Drive drive, String url, String param) {
return post(drive, url, param, true); return post(drive, url, param, true);
} }
private String post(Drive drive, String url, String param, boolean retry) { 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); if (retry && response.contains("Guest user is disabled") && login(drive)) return post(drive, url, param, false);
return response; return response;
} }
@ -156,7 +150,7 @@ public class AList extends Spider {
params.put("username", drive.getLogin().getUsername()); params.put("username", drive.getLogin().getUsername());
params.put("password", drive.getLogin().getPassword()); params.put("password", drive.getLogin().getPassword());
String response = OkHttp.postJson(drive.loginApi(), params.toString()).getBody(); 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; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

Binary file not shown.

View File

@ -1 +1 @@
945ad30d5255359385ba59b8fb061bb7 9eeae00749e17517c5041546a98418cd