Skip to content

Commit 81972ed

Browse files
committed
fix: dandanplay api auth
1 parent 1ddf96a commit 81972ed

6 files changed

Lines changed: 62 additions & 5 deletions

File tree

.github/workflows/build.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ jobs:
2020
java-version: '17'
2121
distribution: 'temurin'
2222
cache: gradle
23-
- name: Load Google Service file
23+
- name: Load secret files
2424
env:
25-
DATA: ${{ secrets.GOOGLE_SERVICES_JSON }}
26-
run: echo $DATA | base64 -di > app/google-services.json
25+
- GOOGLE_SERVICES_JSON_DATA: ${{ secrets.GOOGLE_SERVICES_JSON }}
26+
- SIGN_KEY_DATA: ${{ secrets.SIGN_KEY }}
27+
- KEY_STORE_PROP_DATA: ${{ secrets.KEY_STORE_PROP }}
28+
run: |
29+
echo $GOOGLE_SERVICES_JSON_DATA | base64 -di > app/google-services.json
30+
echo $SIGN_KEY_DATA | base64 -di > MUEDSA.jks
31+
echo $KEY_STORE_PROP_DATA | base64 -di > keystore.properties
2732
- name: Grant execute permission for gradlew
2833
run: chmod +x gradlew
2934
- name: Build with Gradle

app/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ android {
4848
}
4949
}
5050

51+
defaultConfig {
52+
buildConfigField(
53+
"String",
54+
"DANDANPLAY_APP_ID",
55+
"\"${keystoreProperties["muedsa.danDanPlay.appId"]}\""
56+
)
57+
buildConfigField(
58+
"String",
59+
"DANDANPLAY_APP_SECRET",
60+
"\"${keystoreProperties["muedsa.danDanPlay.appSecret"]}\""
61+
)
62+
}
63+
5164
buildTypes {
5265
release {
5366
isMinifyEnabled = false
@@ -70,6 +83,7 @@ android {
7083

7184
buildFeatures {
7285
compose = true
86+
buildConfig = true
7387
}
7488

7589
room {

app/src/main/java/com/muedsa/tvbox/AppModule.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import android.content.Context
44
import androidx.room.Room
55
import com.muedsa.tvbox.room.AppDatabase
66
import com.muedsa.tvbox.service.DanDanPlayApiService
7+
import com.muedsa.tvbox.service.DanDanPlayAuthInterceptor
78
import com.muedsa.tvbox.store.DataStoreRepo
89
import com.muedsa.tvbox.tool.createJsonRetrofit
10+
import com.muedsa.tvbox.tool.createOkHttpClient
911
import com.muedsa.util.AppUtil
1012
import dagger.Module
1113
import dagger.Provides
@@ -46,6 +48,8 @@ internal object AppModule {
4648
createJsonRetrofit(
4749
baseUrl = "https://api.dandanplay.net/api/",
4850
service = DanDanPlayApiService::class.java,
49-
debug = AppUtil.debuggable(context)
51+
okHttpClient = createOkHttpClient(debug = AppUtil.debuggable(context)) {
52+
addInterceptor(DanDanPlayAuthInterceptor())
53+
}
5054
)
5155
}

app/src/main/java/com/muedsa/tvbox/screens/detail/MediaDetailScreenViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.muedsa.tvbox.screens.detail
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5+
import com.muedsa.tvbox.BuildConfig
56
import com.muedsa.tvbox.api.data.MediaDetail
67
import com.muedsa.tvbox.api.data.MediaEpisode
78
import com.muedsa.tvbox.api.data.MediaHttpSource
@@ -93,6 +94,8 @@ class MediaDetailScreenViewModel @Inject constructor(
9394
private val _danBangumiListFlow =
9495
combine(_mediaDetailFlow, _banBangumiSearchQueryFlow) { wrapper, searchQuery ->
9596
if (wrapper.data != null
97+
&& !BuildConfig.DANDANPLAY_APP_ID.isEmpty()
98+
&& !BuildConfig.DANDANPLAY_APP_SECRET.isEmpty()
9699
&& wrapper.data.second.enableDanDanPlaySearch
97100
&& !wrapper.data.third.enableCustomDanmakuList
98101
&& !wrapper.data.third.enableCustomDanmakuFlow

app/src/main/java/com/muedsa/tvbox/screens/playback/PlaybackScreenViewModel.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.muedsa.tvbox.screens.playback
33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
55
import com.kuaishou.akdanmaku.data.DanmakuItemData
6+
import com.muedsa.tvbox.BuildConfig
67
import com.muedsa.tvbox.api.data.DanmakuDataFlow
78
import com.muedsa.tvbox.api.data.MediaEpisode
89
import com.muedsa.tvbox.model.AppSettingModel
@@ -70,7 +71,10 @@ class PlaybackScreenViewModel @Inject constructor(
7071
danmakuStyle = data.danmakuStyle
7172
)
7273
}
73-
} else if (it.danEpisodeId > 0) {
74+
} else if (!BuildConfig.DANDANPLAY_APP_ID.isEmpty()
75+
&& !BuildConfig.DANDANPLAY_APP_SECRET.isEmpty()
76+
&& it.danEpisodeId > 0
77+
) {
7478
danDanPlayApiService.getComment(
7579
episodeId = it.danEpisodeId,
7680
from = 0,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.muedsa.tvbox.service
2+
3+
import com.muedsa.tvbox.BuildConfig
4+
import com.muedsa.tvbox.tool.encodeBase64
5+
import okhttp3.Interceptor
6+
import okhttp3.Response
7+
import java.security.MessageDigest
8+
9+
class DanDanPlayAuthInterceptor : Interceptor {
10+
11+
override fun intercept(chain: Interceptor.Chain): Response {
12+
val timestamp = System.currentTimeMillis() / 1000
13+
val path = chain.request().url.encodedPath
14+
val sign =
15+
"${BuildConfig.DANDANPLAY_APP_ID}$timestamp$path${BuildConfig.DANDANPLAY_APP_SECRET}".let {
16+
MessageDigest.getInstance("SHA-256")
17+
.digest(it.toByteArray(Charsets.UTF_8))
18+
.encodeBase64()
19+
}
20+
val request = chain.request().newBuilder()
21+
.header("X-AppId", BuildConfig.DANDANPLAY_APP_ID)
22+
.header("X-Timestamp", "$timestamp")
23+
.header("X-Signature", sign)
24+
.build()
25+
return chain.proceed(request)
26+
}
27+
}

0 commit comments

Comments
 (0)