mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
update votes to sha256 and add github link
This commit is contained in:
parent
37c9be96bb
commit
8172696d1a
4 changed files with 42 additions and 21 deletions
|
@ -20,47 +20,45 @@ object VotingApi { // please do not cheat the votes lol
|
|||
|
||||
private fun transformUrl(url: String): String = // dont touch or all votes get reset
|
||||
MessageDigest
|
||||
.getInstance("SHA-1")
|
||||
.getInstance("SHA-256")
|
||||
.digest("${url}#funny-salt".toByteArray())
|
||||
.fold("") { str, it -> str + "%02x".format(it) }
|
||||
|
||||
suspend fun SitePlugin.getVotes(): Int {
|
||||
if (repositoryUrl == null) return 0
|
||||
return getVotes(repositoryUrl, url)
|
||||
return getVotes(url)
|
||||
}
|
||||
|
||||
suspend fun SitePlugin.vote(requestType: VoteType): Int {
|
||||
if (repositoryUrl == null) return 0
|
||||
return vote(repositoryUrl, url, requestType)
|
||||
return vote(url, requestType)
|
||||
}
|
||||
|
||||
fun SitePlugin.getVoteType(): VoteType {
|
||||
if (repositoryUrl == null) return VoteType.NONE
|
||||
return getVoteType(repositoryUrl, url)
|
||||
return getVoteType(url)
|
||||
}
|
||||
|
||||
suspend fun getVotes(repositoryUrl: String, pluginUrl: String): Int {
|
||||
val url = "${apiDomain}/get/cs3-votes-${transformUrl(repositoryUrl)}/${transformUrl(pluginUrl)}"
|
||||
suspend fun getVotes(pluginUrl: String): Int {
|
||||
val url = "${apiDomain}/get/cs3-votes/${transformUrl(pluginUrl)}"
|
||||
Log.d(LOGKEY, "Requesting: $url")
|
||||
return app.get(url).parsedSafe<Result>()?.value ?: (0.also {
|
||||
ioSafe {
|
||||
createBucket(repositoryUrl, pluginUrl)
|
||||
createBucket(pluginUrl)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun getVoteType(repositoryUrl: String, pluginUrl: String): VoteType {
|
||||
return getKey("cs3-votes-${transformUrl(repositoryUrl)}/${transformUrl(pluginUrl)}") ?: VoteType.NONE
|
||||
fun getVoteType(pluginUrl: String): VoteType {
|
||||
return getKey("cs3-votes/${transformUrl(pluginUrl)}") ?: VoteType.NONE
|
||||
}
|
||||
|
||||
private suspend fun createBucket(repositoryUrl: String, pluginUrl: String) {
|
||||
val url = "${apiDomain}/create?namespace=cs3-votes-${transformUrl(repositoryUrl)}&key=${transformUrl(pluginUrl)}&value=0&update_lowerbound=-2&update_upperbound=2&enable_reset=0"
|
||||
private suspend fun createBucket(pluginUrl: String) {
|
||||
val url = "${apiDomain}/create?namespace=cs3-votes&key=${transformUrl(pluginUrl)}&value=0&update_lowerbound=-2&update_upperbound=2&enable_reset=0"
|
||||
Log.d(LOGKEY, "Requesting: $url")
|
||||
app.get(url)
|
||||
}
|
||||
|
||||
suspend fun vote(repositoryUrl: String, pluginUrl: String, requestType: VoteType): Int {
|
||||
val savedType: VoteType = getKey("cs3-votes-${transformUrl(repositoryUrl)}/${transformUrl(pluginUrl)}") ?: VoteType.NONE
|
||||
suspend fun vote(pluginUrl: String, requestType: VoteType): Int {
|
||||
val savedType: VoteType = getKey("cs3-votes/${transformUrl(pluginUrl)}") ?: VoteType.NONE
|
||||
var newType: VoteType = requestType
|
||||
var changeValue = 0
|
||||
if (requestType == savedType) {
|
||||
|
@ -71,11 +69,11 @@ object VotingApi { // please do not cheat the votes lol
|
|||
} else if (savedType != requestType) {
|
||||
changeValue = -savedType.value + requestType.value
|
||||
}
|
||||
val url = "${apiDomain}/update/cs3-votes-${transformUrl(repositoryUrl)}/${transformUrl(pluginUrl)}?amount=${changeValue}"
|
||||
val url = "${apiDomain}/update/cs3-votes/${transformUrl(pluginUrl)}?amount=${changeValue}"
|
||||
Log.d(LOGKEY, "Requesting: $url")
|
||||
val res = app.get(url).parsedSafe<Result>()?.value
|
||||
if (res != null) {
|
||||
setKey("cs3-votes-${transformUrl(repositoryUrl)}/${transformUrl(pluginUrl)}", newType)
|
||||
setKey("cs3-votes/${transformUrl(pluginUrl)}", newType)
|
||||
}
|
||||
return res ?: 0
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ class PluginAdapter(
|
|||
val metadata = data.plugin.second
|
||||
val disabled = metadata.status == PROVIDER_STATUS_DOWN
|
||||
val alpha = if (disabled) 0.6f else 1f
|
||||
val isLocal = data.plugin.second.repositoryUrl == null
|
||||
val isLocal = !data.plugin.second.url.startsWith("http")
|
||||
itemView.main_text?.alpha = alpha
|
||||
itemView.sub_text?.alpha = alpha
|
||||
|
||||
|
@ -216,12 +216,18 @@ class PluginAdapter(
|
|||
itemView.lang_icon.text = fromTwoLettersToLanguage(metadata.language)
|
||||
}
|
||||
|
||||
ioSafe {
|
||||
metadata.getVotes().main {
|
||||
itemView.ext_votes?.setText(txt(R.string.votes_format, prettyCount(it)))
|
||||
if (isLocal) {
|
||||
itemView.ext_votes?.isVisible = false
|
||||
} else {
|
||||
itemView.ext_votes?.isVisible = true
|
||||
ioSafe {
|
||||
metadata.getVotes().main {
|
||||
itemView.ext_votes?.setText(txt(R.string.votes_format, prettyCount(it)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (metadata.fileSize != null) {
|
||||
itemView.ext_filesize?.isVisible = true
|
||||
itemView.ext_filesize?.text = formatShortFileSize(itemView.context, metadata.fileSize)
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.lagradost.cloudstream3.plugins.VotingApi.vote
|
|||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser
|
||||
|
||||
|
||||
class PluginDetailsFragment(val data: PluginViewData) : BottomSheetDialogFragment() {
|
||||
|
@ -68,6 +69,13 @@ class PluginDetailsFragment(val data: PluginViewData) : BottomSheetDialogFragmen
|
|||
plugin_status?.text = resources.getStringArray(R.array.extension_statuses)[metadata.status]
|
||||
plugin_types?.text = if ((metadata.tvTypes == null) || metadata.tvTypes.isEmpty()) getString(R.string.no_data) else metadata.tvTypes.joinToString(", ")
|
||||
|
||||
github_btn.setOnClickListener {
|
||||
if (metadata.repositoryUrl != null) {
|
||||
openBrowser(metadata.repositoryUrl)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
upvote.setOnClickListener {
|
||||
ioSafe {
|
||||
metadata.vote(VotingApi.VoteType.UPVOTE).main {
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
|
@ -41,6 +42,14 @@
|
|||
android:textSize="20sp"
|
||||
android:textStyle="normal"
|
||||
tools:text="Hello world" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/github_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_github_logo" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
Loading…
Reference in a new issue