-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add addon hash table and return addon hash status from panel ge…
…t plugins endpoint
- Loading branch information
Showing
8 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Pano/src/main/kotlin/com/panomc/platform/db/dao/AddonHashDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.panomc.platform.db.dao | ||
|
||
import com.panomc.platform.db.Dao | ||
import com.panomc.platform.db.model.AddonHash | ||
import io.vertx.sqlclient.SqlClient | ||
|
||
abstract class AddonHashDao : Dao<AddonHash>(AddonHash::class.java) { | ||
abstract suspend fun add( | ||
addonHash: AddonHash, | ||
sqlClient: SqlClient | ||
): Long | ||
|
||
abstract suspend fun byListOfHash( | ||
hashList: List<String>, | ||
sqlClient: SqlClient | ||
): Map<String, AddonHash> | ||
} |
81 changes: 81 additions & 0 deletions
81
Pano/src/main/kotlin/com/panomc/platform/db/implementation/AddonHashDaoImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.panomc.platform.db.implementation | ||
|
||
import com.panomc.platform.annotation.Dao | ||
import com.panomc.platform.db.dao.AddonHashDao | ||
import com.panomc.platform.db.model.AddonHash | ||
import io.vertx.kotlin.coroutines.await | ||
import io.vertx.mysqlclient.MySQLClient | ||
import io.vertx.sqlclient.Row | ||
import io.vertx.sqlclient.RowSet | ||
import io.vertx.sqlclient.SqlClient | ||
import io.vertx.sqlclient.Tuple | ||
|
||
@Dao | ||
class AddonHashDaoImpl : AddonHashDao() { | ||
|
||
override suspend fun init(sqlClient: SqlClient) { | ||
sqlClient | ||
.query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS `${getTablePrefix() + tableName}` ( | ||
`id` bigint NOT NULL AUTO_INCREMENT, | ||
`hash` text NOT NULL, | ||
`status` varchar(255) NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Addon hash table.'; | ||
""" | ||
) | ||
.execute() | ||
.await() | ||
} | ||
|
||
override suspend fun add( | ||
addonHash: AddonHash, | ||
sqlClient: SqlClient | ||
): Long { | ||
val query = | ||
"INSERT INTO `${getTablePrefix() + tableName}` (`hash`, `status`) " + | ||
"VALUES (?, ?)" | ||
|
||
val rows: RowSet<Row> = sqlClient | ||
.preparedQuery(query) | ||
.execute( | ||
Tuple.of( | ||
addonHash.hash, | ||
addonHash.status | ||
) | ||
).await() | ||
|
||
return rows.property(MySQLClient.LAST_INSERTED_ID) | ||
} | ||
|
||
override suspend fun byListOfHash( | ||
hashList: List<String>, | ||
sqlClient: SqlClient | ||
): Map<String, AddonHash> { | ||
var listText = "" | ||
|
||
hashList.forEach { hash -> | ||
if (listText == "") | ||
listText = "'$hash'" | ||
else | ||
listText += ", '$hash'" | ||
} | ||
|
||
val query = | ||
"SELECT `id`, `hash`, `status` FROM `${getTablePrefix() + tableName}` where `hash` IN ($listText)" | ||
|
||
val rows: RowSet<Row> = sqlClient | ||
.preparedQuery(query) | ||
.execute() | ||
.await() | ||
|
||
val listOfAddonHash = mutableMapOf<String, AddonHash>() | ||
|
||
rows.forEach { row -> | ||
listOfAddonHash[row.getString(1)] = row.toEntity() | ||
} | ||
|
||
return listOfAddonHash | ||
} | ||
} |
Empty file.
36 changes: 36 additions & 0 deletions
36
Pano/src/main/kotlin/com/panomc/platform/db/migration/DatabaseMigration1to2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.panomc.platform.db.migration | ||
|
||
import com.panomc.platform.annotation.Migration | ||
import com.panomc.platform.db.DatabaseManager | ||
import com.panomc.platform.db.DatabaseMigration | ||
import io.vertx.kotlin.coroutines.await | ||
import io.vertx.sqlclient.SqlClient | ||
|
||
@Migration | ||
class DatabaseMigration1to2(databaseManager: DatabaseManager) : DatabaseMigration(databaseManager) { | ||
override val FROM_SCHEME_VERSION = 1 | ||
override val SCHEME_VERSION = 2 | ||
override val SCHEME_VERSION_INFO = "Add addon_hash table" | ||
|
||
override val handlers: List<suspend (SqlClient) -> Unit> = listOf( | ||
deleteSecretKeyColumn() | ||
) | ||
|
||
private fun deleteSecretKeyColumn(): suspend (sqlClient: SqlClient) -> Unit = | ||
{ sqlClient: SqlClient -> | ||
sqlClient | ||
.query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS `${getTablePrefix()}addon_hash` ( | ||
`id` bigint NOT NULL AUTO_INCREMENT, | ||
`hash` text NOT NULL, | ||
`status` varchar(255) NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Addon hash table.'; | ||
""".trimIndent() | ||
) | ||
.execute() | ||
.await() | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
Pano/src/main/kotlin/com/panomc/platform/db/model/AddonHash.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.panomc.platform.db.model | ||
|
||
import com.panomc.platform.db.DBEntity | ||
import com.panomc.platform.util.AddonHashStatus | ||
|
||
data class AddonHash( | ||
val id: Long = -1, | ||
val hash: String, | ||
val status: AddonHashStatus, | ||
) : DBEntity() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Pano/src/main/kotlin/com/panomc/platform/util/AddonHashStatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.panomc.platform.util | ||
|
||
enum class AddonHashStatus { | ||
VERIFIED, | ||
NOT_VERIFIED, | ||
UNKNOWN | ||
} |