fix: apply API changes
This commit is contained in:
parent
c63ca8c1da
commit
be230e8a11
@ -19,11 +19,14 @@ import ru.sweetbread.unn.db.loadSchedule
|
||||
import ru.sweetbread.unn.db.loadUserByBitrixId
|
||||
import ru.sweetbread.unn.ui.layout.LoginData
|
||||
import ru.sweetbread.unn.ui.layout.client
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import java.time.LocalTime
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
|
||||
private lateinit var PHPSESSID: String
|
||||
private lateinit var CSRF: String
|
||||
lateinit var ME: User
|
||||
@ -31,8 +34,10 @@ lateinit var ME: User
|
||||
const val portalURL = "https://portal.unn.ru"
|
||||
const val ruzapiURL = "$portalURL/ruzapi"
|
||||
const val vuzapiURL = "$portalURL/bitrix/vuz/api"
|
||||
const val prtl2URL = "$portalURL/portal2/api"
|
||||
const val restURL = "$portalURL/rest"
|
||||
|
||||
|
||||
enum class Type(val s: String) {
|
||||
Student("student"),
|
||||
Group("group"),
|
||||
@ -109,7 +114,6 @@ class User(
|
||||
|
||||
class Post(
|
||||
val id: Int,
|
||||
val blogId: Int,
|
||||
val authorId: Int,
|
||||
val enableComments: Boolean,
|
||||
val numComments: Int,
|
||||
@ -123,6 +127,7 @@ class AvatarSet(
|
||||
val small: String
|
||||
)
|
||||
|
||||
|
||||
/**
|
||||
* Authorize user by [login] and [password]
|
||||
*
|
||||
@ -149,10 +154,8 @@ suspend fun auth(
|
||||
if (r.status.value == 302) {
|
||||
PHPSESSID =
|
||||
"""PHPSESSID=([\w\d]+)""".toRegex().find(r.headers["Set-Cookie"]!!)!!.groupValues[1]
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
getMyself(login)
|
||||
getCSRF()
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@ -162,9 +165,10 @@ suspend fun auth(
|
||||
* Save info about current [User] in memory
|
||||
*/
|
||||
private suspend fun getMyself(login: String) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
val studentinfo = JSONObject(client.get("$ruzapiURL/studentinfo") {
|
||||
parameter("uns", login.substring(1))
|
||||
// WARNING: trailing / is important, 'cuz API devs are eating shit
|
||||
val studentinfo = JSONObject(client.get("$ruzapiURL/studentinfo/") {
|
||||
header("Cookie", "PHPSESSID=$PHPSESSID")
|
||||
parameter("uns", login.drop(1))
|
||||
}.bodyAsText())
|
||||
|
||||
val user = JSONObject(
|
||||
@ -173,6 +177,8 @@ private suspend fun getMyself(login: String) {
|
||||
}.bodyAsText()
|
||||
)
|
||||
|
||||
Log.d("studentInfo", studentinfo.toString(2))
|
||||
|
||||
ME = User(
|
||||
unnId = studentinfo.getString("id").toInt(),
|
||||
bitrixId = user.getInt("bitrix_id"),
|
||||
@ -185,10 +191,10 @@ private suspend fun getMyself(login: String) {
|
||||
nameRu = user.getString("fullname"),
|
||||
nameEn = user.getString("fullname_en"),
|
||||
isMale = user.getString("sex") == "M",
|
||||
birthday = LocalDate.parse(
|
||||
user.getString("birthdate"),
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
||||
),
|
||||
birthday = Instant
|
||||
.parse(user.getString("birthdate"))
|
||||
.atZone(ZoneId.of("Europe/Moscow"))
|
||||
.toLocalDate(),
|
||||
avatar = user.getJSONObject("photo").let {
|
||||
AvatarSet(
|
||||
it.getString("orig"),
|
||||
@ -197,7 +203,6 @@ private suspend fun getMyself(login: String) {
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getScheduleDay(
|
||||
@ -223,7 +228,7 @@ suspend fun getSchedule(
|
||||
start: LocalDate,
|
||||
finish: LocalDate
|
||||
): ArrayList<ScheduleUnit> {
|
||||
val unnDatePattern = DateTimeFormatter.ofPattern("yyyy.MM.dd")
|
||||
val unnDatePattern = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
||||
|
||||
val r = client.get("$ruzapiURL/schedule/${type.s}/$id") {
|
||||
parameter("start", start.format(unnDatePattern))
|
||||
@ -310,28 +315,26 @@ suspend fun getCSRF() {
|
||||
}
|
||||
|
||||
suspend fun getBlogposts(): ArrayList<Post> {
|
||||
val r = client.get("$restURL/log.blogpost.get") {
|
||||
val r = client.get("$prtl2URL/news.php") {
|
||||
header("Cookie", "PHPSESSID=$PHPSESSID")
|
||||
parameter("sessid", CSRF)
|
||||
header("x-bitrix-sessid-token", CSRF)
|
||||
}
|
||||
val json = JSONObject(r.bodyAsText())
|
||||
val result = json.getJSONArray("result")
|
||||
val result = JSONArray(r.bodyAsText())
|
||||
|
||||
val out = arrayListOf<Post>()
|
||||
for (i in 0 until result.length()) {
|
||||
val el = result.getJSONObject(i)
|
||||
out.add(
|
||||
Post(
|
||||
id = el.getString("ID").toInt(),
|
||||
blogId = el.getString("BLOG_ID").toInt(),
|
||||
authorId = el.getString("AUTHOR_ID").toInt(),
|
||||
enableComments = el.getString("ENABLE_COMMENTS") == "Y",
|
||||
numComments = el.getString("NUM_COMMENTS").toInt(),
|
||||
id = el.getString("id").toInt(),
|
||||
authorId = el.getJSONObject("author").getInt("id").toInt(),
|
||||
enableComments = true, // FIXME: Delete the field or get correct value
|
||||
numComments = el.getString("commentsnum").toInt(),
|
||||
date = LocalDateTime.parse(
|
||||
el.getString("DATE_PUBLISH"),
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'+03:00'")
|
||||
el.getString("time"),
|
||||
DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss")
|
||||
),
|
||||
content = el.getString("DETAIL_TEXT")
|
||||
content = el.getString("fulltext")
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -375,10 +378,10 @@ suspend fun getUser(id: Int): User {
|
||||
nameRu = json.getString("fullname"),
|
||||
nameEn = json.getString("fullname_en"),
|
||||
isMale = json.getString("sex") == "M",
|
||||
birthday = LocalDate.parse(
|
||||
json.getString("birthdate"),
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
||||
),
|
||||
birthday = Instant
|
||||
.parse(json.getString("birthdate"))
|
||||
.atZone(ZoneId.of("Europe/Moscow"))
|
||||
.toLocalDate(),
|
||||
avatar = json.getJSONObject("photo").let {
|
||||
AvatarSet(
|
||||
it.getString("orig"),
|
||||
|
@ -11,15 +11,15 @@ class UNNApp : Application() {
|
||||
override fun attachBaseContext(base: Context) {
|
||||
super.attachBaseContext(base)
|
||||
|
||||
initAcra {
|
||||
buildConfigClass = BuildConfig::class.java
|
||||
reportFormat = StringFormat.JSON
|
||||
httpSender {
|
||||
uri = BuildConfig.ACRA_URL
|
||||
basicAuthLogin = BuildConfig.ACRA_LOGIN
|
||||
basicAuthPassword = BuildConfig.ACRA_PASS
|
||||
httpMethod = HttpSender.Method.POST
|
||||
}
|
||||
}
|
||||
// initAcra {
|
||||
// buildConfigClass = BuildConfig::class.java
|
||||
// reportFormat = StringFormat.JSON
|
||||
// httpSender {
|
||||
// uri = BuildConfig.ACRA_URL
|
||||
// basicAuthLogin = BuildConfig.ACRA_LOGIN
|
||||
// basicAuthPassword = BuildConfig.ACRA_PASS
|
||||
// httpMethod = HttpSender.Method.POST
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
@ -278,7 +278,6 @@ fun UserItemPreview() {
|
||||
fun PostItemPreview() {
|
||||
val post = Post(
|
||||
id = 154923,
|
||||
blogId = 121212,
|
||||
authorId = 165945,
|
||||
enableComments = true,
|
||||
numComments = 0,
|
||||
|
@ -1,6 +1,6 @@
|
||||
[versions]
|
||||
acraHttp = "5.11.3"
|
||||
agp = "8.5.2"
|
||||
agp = "8.7.0"
|
||||
calendar = "2.5.4"
|
||||
coilCompose = "2.7.0"
|
||||
compose = "1.6.4" # Updating this will cause an error!
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
||||
#Sat Mar 16 18:30:45 MSK 2024
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
Loading…
x
Reference in New Issue
Block a user