Add Matomo Downloads in Download Card Count

This commit is contained in:
shabinder 2021-06-06 03:28:10 +05:30
parent 8ae683585d
commit 796acd6c3b
3 changed files with 22 additions and 5 deletions

View File

@ -0,0 +1,3 @@
package models.matomo
typealias MatomoDownloads = ArrayList<MatomoDownloadsItem>

View File

@ -0,0 +1,12 @@
package models.matomo
import kotlinx.serialization.Serializable
@Serializable
data class MatomoDownloadsItem(
val idsubdatatable: Int = 0,
val label: String = "com.shabinder.spotiflyer",
val nb_hits: Int = 0,
val nb_visits: Int = 0,
val sum_time_spent: Int = 0
)

View File

@ -4,6 +4,7 @@ import common.*
import io.ktor.client.features.* import io.ktor.client.features.*
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.client.statement.* import io.ktor.client.statement.*
import models.matomo.MatomoDownloads
import utils.RETRY_LIMIT_EXHAUSTED import utils.RETRY_LIMIT_EXHAUSTED
import utils.debug import utils.debug
@ -17,7 +18,7 @@ internal suspend fun updateDownloadCards(
fileName = "README.md" fileName = "README.md"
).decryptedContent ).decryptedContent
val totalDownloads:Int = GithubService.getGithubRepoReleasesInfo( var totalDownloads:Int = GithubService.getGithubRepoReleasesInfo(
secrets.ownerName, secrets.ownerName,
secrets.repoName secrets.repoName
).let { allReleases -> ).let { allReleases ->
@ -35,13 +36,14 @@ internal suspend fun updateDownloadCards(
return@let totalCount return@let totalCount
} }
// Add Matomo Downloads
client.get<MatomoDownloads>("https://kind-grasshopper-73.telebit.io/matomo/?module=API&method=Actions.getDownloads&idSite=1&period=year&date=today&format=JSON&token_auth=anonymous").forEach {
totalDownloads += it.nb_hits
}
return getUpdatedContent( return getUpdatedContent(
oldContent, oldContent,
""" """<a href="https://github.com/Shabinder/SpotiFlyer/releases/latest"><img src="${getDownloadCard(totalDownloads)}" height="125" width="280" alt="Total Downloads"></a>""",
<a href="https://github.com/Shabinder/SpotiFlyer/releases/latest">
<img src="${getDownloadCard(totalDownloads)}" height="125" width="280" alt="Total Downloads">
</a>""".trim().trimIndent(),
secrets.tagName secrets.tagName
) )
} }