Skip to content

Commit

Permalink
fix release error
Browse files Browse the repository at this point in the history
  • Loading branch information
storytellerF committed Oct 19, 2024
1 parent b41a3da commit 5980d25
Show file tree
Hide file tree
Showing 66 changed files with 345 additions and 343 deletions.
8 changes: 4 additions & 4 deletions backend/src/main/kotlin/com/perraco/utils/SnowflakeFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package com.perraco.utils

import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.yield
Expand Down Expand Up @@ -79,7 +79,7 @@ object SnowflakeFactory {

private val lock = Mutex()

suspend fun nextId(): OKey {
suspend fun nextId(): PrimaryKey {
return lock.withLock {
nextIdInternal()
}
Expand All @@ -90,7 +90,7 @@ object SnowflakeFactory {
* @return The generated Snowflake ID in the configured base alphanumeric string.
* @throws IllegalStateException If the system clock has moved backwards, breaking the ID sequence.
*/
private suspend fun nextIdInternal(): OKey {
private suspend fun nextIdInternal(): PrimaryKey {
var currentTimestampMs: Long = newTimestamp()

// Check for invalid system clock settings.
Expand Down Expand Up @@ -128,7 +128,7 @@ object SnowflakeFactory {
* @param id The Snowflake ID to parse.
* @return SnowflakeData containing the ID segments.
*/
fun parse(id: OKey): SnowflakeData {
fun parse(id: PrimaryKey): SnowflakeData {
// Extract the machine ID segment.
val machineIdSegment = (id shr SEQUENCE_BITS) and MAX_MACHINE_ID.toULong()

Expand Down
4 changes: 2 additions & 2 deletions backend/src/main/kotlin/com/storyteller_f/BaseTable.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.storyteller_f

import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import kotlinx.datetime.LocalDateTime
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.kotlin.datetime.datetime
Expand All @@ -12,4 +12,4 @@ abstract class BaseTable : Table() {
override val primaryKey = PrimaryKey(id)
}

abstract class BaseObj(val id: OKey, val createdTime: LocalDateTime)
abstract class BaseObj(val id: PrimaryKey, val createdTime: LocalDateTime)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import co.elastic.clients.transport.TransportUtils
import co.elastic.clients.transport.rest_client.RestClientTransport
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import com.storyteller_f.ElasticConnection
import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.future.await
import kotlinx.coroutines.withContext
Expand All @@ -30,7 +30,7 @@ class ElasticTopicDocumentService(private val connection: ElasticConnection) : T
}
}

override suspend fun getDocument(idList: List<OKey>): List<TopicDocument?> {
override suspend fun getDocument(idList: List<PrimaryKey>): List<TopicDocument?> {
return useElasticClient(connection) {
idList.map { id ->
get({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.storyteller_f.index

import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import org.apache.lucene.analysis.standard.StandardAnalyzer
import org.apache.lucene.document.*
import org.apache.lucene.index.DirectoryReader
Expand Down Expand Up @@ -29,7 +29,7 @@ class LuceneTopicDocumentService(private val path: Path) : TopicDocumentService
}
}

override suspend fun getDocument(idList: List<OKey>): List<TopicDocument?> {
override suspend fun getDocument(idList: List<PrimaryKey>): List<TopicDocument?> {
return FSDirectory.open(path).use {
DirectoryReader.open(it).use { reader ->
val searcher = IndexSearcher(reader)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.storyteller_f.index

import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey

data class TopicDocument(val id: OKey, val content: String)
data class TopicDocument(val id: PrimaryKey, val content: String)

interface TopicDocumentService {
suspend fun saveDocument(topics: List<TopicDocument>)

suspend fun getDocument(idList: List<OKey>): List<TopicDocument?>
suspend fun getDocument(idList: List<PrimaryKey>): List<TopicDocument?>

suspend fun clean()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.storyteller_f.naming

import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey

class NameService {
private val nameMap = mutableMapOf<Int, Int>()
Expand Down Expand Up @@ -28,7 +28,7 @@ class NameService {
}

// 将数字转换为自定义字符集表示的字符串
private fun numberToCustomCharset(num: OKey): String {
private fun numberToCustomCharset(num: PrimaryKey): String {
val base = countList.last().toULong()

var number = num
Expand Down
12 changes: 6 additions & 6 deletions backend/src/main/kotlin/com/storyteller_f/tables/Communities.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.storyteller_f.tables

import com.storyteller_f.*
import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import com.storyteller_f.shared.utils.now
import kotlinx.datetime.LocalDateTime
import org.jetbrains.exposed.sql.*
Expand All @@ -18,9 +18,9 @@ class Community(
val aid: String,
val name: String,
val icon: String?,
val owner: OKey,
val owner: PrimaryKey,
val poster: String?,
id: OKey,
id: PrimaryKey,
createdTime: LocalDateTime
) :
BaseObj(id, createdTime) {
Expand All @@ -41,7 +41,7 @@ class Community(
return Communities.selectAll().where(function)
}

fun findById(id: OKey): Query {
fun findById(id: PrimaryKey): Query {
return Communities.selectAll().where {
Communities.id eq id
}
Expand All @@ -68,8 +68,8 @@ fun findCommunityByAId(aid: String): ResultRow? {
}

fun createCommunityJoin(
id: OKey,
community: OKey
id: PrimaryKey,
community: PrimaryKey
) = CommunityJoins.insert {
it[joinTime] = now()
it[uid] = id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.storyteller_f.tables

import com.storyteller_f.DatabaseFactory
import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.kotlin.datetime.datetime
Expand All @@ -17,7 +17,7 @@ object CommunityJoins : Table() {
}
}

suspend fun isCommunityJoined(communityId: OKey, uid: OKey) = !DatabaseFactory.empty {
suspend fun isCommunityJoined(communityId: PrimaryKey, uid: PrimaryKey) = !DatabaseFactory.empty {
CommunityJoins.selectAll().where {
CommunityJoins.communityId eq communityId and (CommunityJoins.uid eq uid)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.storyteller_f.tables

import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.selectAll

Expand All @@ -13,7 +13,7 @@ object CommunityRooms : Table() {
}
}

fun checkRoomIsPrivate(roomId: OKey): Boolean {
fun checkRoomIsPrivate(roomId: PrimaryKey): Boolean {
return CommunityRooms.selectAll().where {
CommunityRooms.roomId eq roomId
}.limit(1).count() == 0L
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.storyteller_f.tables

import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.Table

Expand All @@ -11,7 +11,7 @@ object EncryptedTopics : Table() {
override val primaryKey = PrimaryKey(topicId)
}

class EncryptedTopic(val topicId: OKey, val content: ByteArray) {
class EncryptedTopic(val topicId: PrimaryKey, val content: ByteArray) {
companion object {
fun wrapRow(row: ResultRow): EncryptedTopic {
return EncryptedTopic(row[EncryptedTopics.topicId], row[EncryptedTopics.content].bytes)
Expand All @@ -25,7 +25,7 @@ object EncryptedTopicKeys : Table() {
val encryptedAes = blob("encrypted_aes")
}

class EncryptedTopicKey(val topicId: OKey, val uid: OKey, val encryptedAes: ByteArray) {
class EncryptedTopicKey(val topicId: PrimaryKey, val uid: PrimaryKey, val encryptedAes: ByteArray) {
companion object {
fun wrapRow(row: ResultRow): EncryptedTopicKey {
return EncryptedTopicKey(
Expand Down
11 changes: 5 additions & 6 deletions backend/src/main/kotlin/com/storyteller_f/tables/RoomJoins.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.storyteller_f.tables

import com.storyteller_f.DatabaseFactory
import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import com.storyteller_f.shared.utils.now
import kotlinx.datetime.LocalDateTime
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.kotlin.datetime.datetime
import kotlin.text.insert

object RoomJoins : Table() {
val uid = ulong("uid").index()
Expand All @@ -18,23 +17,23 @@ object RoomJoins : Table() {
}
}

class RoomJoin(val uid: OKey, val roomId: OKey, val joinTime: LocalDateTime) {
class RoomJoin(val uid: PrimaryKey, val roomId: PrimaryKey, val joinTime: LocalDateTime) {
companion object {
fun wrapRow(row: ResultRow): RoomJoin {
return RoomJoin(row[RoomJoins.uid], row[RoomJoins.roomId], row[RoomJoins.joinTime])
}
}
}

suspend fun isRoomJoined(roomId: OKey, uid: OKey) = !DatabaseFactory.empty {
suspend fun isRoomJoined(roomId: PrimaryKey, uid: PrimaryKey) = !DatabaseFactory.empty {
RoomJoins.selectAll().where {
RoomJoins.roomId eq roomId and (RoomJoins.uid eq uid)
}
}

fun addRoomJoin(
room: OKey,
id: OKey
room: PrimaryKey,
id: PrimaryKey
) = RoomJoins.insert {
it[joinTime] = now()
it[roomId] = room
Expand Down
8 changes: 4 additions & 4 deletions backend/src/main/kotlin/com/storyteller_f/tables/Rooms.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.storyteller_f.tables

import com.storyteller_f.*
import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import kotlinx.datetime.LocalDateTime
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.selectAll
Expand All @@ -17,8 +17,8 @@ class Room(
val aid: String,
val name: String,
val icon: String?,
val creator: OKey,
id: OKey,
val creator: PrimaryKey,
id: PrimaryKey,
createdTime: LocalDateTime
) : BaseObj(id, createdTime) {
companion object {
Expand All @@ -35,7 +35,7 @@ class Room(
}
}

fun findRoomById(id: OKey): ResultRow? {
fun findRoomById(id: PrimaryKey): ResultRow? {
return Rooms.selectAll().where {
Rooms.id eq id
}.limit(1).firstOrNull()
Expand Down
16 changes: 8 additions & 8 deletions backend/src/main/kotlin/com/storyteller_f/tables/Topics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.storyteller_f.tables
import com.storyteller_f.BaseObj
import com.storyteller_f.BaseTable
import com.storyteller_f.objectType
import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import com.storyteller_f.shared.type.ObjectType
import com.storyteller_f.shared.utils.now
import kotlinx.datetime.LocalDateTime
Expand All @@ -27,13 +27,13 @@ object Topics : BaseTable() {
}

class Topic(
val author: OKey,
val parentId: OKey,
val author: PrimaryKey,
val parentId: PrimaryKey,
val parentType: ObjectType,
val rootId: OKey,
val rootId: PrimaryKey,
val rootType: ObjectType,
val lastModifiedTime: LocalDateTime?,
id: OKey,
id: PrimaryKey,
createdTime: LocalDateTime
) : BaseObj(id, createdTime) {
companion object {
Expand All @@ -50,11 +50,11 @@ class Topic(
)
}

fun findById(topicId: OKey): Topic? {
fun findById(topicId: PrimaryKey): Topic? {
return findTopicById(topicId)?.let(::wrapRow)
}

fun new(info: Topic): OKey {
fun new(info: Topic): PrimaryKey {
val newTopicId = Topics.insert {
it[id] = info.id
it[author] = info.author
Expand All @@ -70,7 +70,7 @@ class Topic(
}
}

fun findTopicById(id: OKey): ResultRow? {
fun findTopicById(id: PrimaryKey): ResultRow? {
return Topics.selectAll().where {
Topics.id eq id
}.limit(1).firstOrNull()
Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/kotlin/com/storyteller_f/tables/Users.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.storyteller_f.tables

import com.storyteller_f.*
import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import kotlinx.datetime.LocalDateTime
import org.jetbrains.exposed.sql.*

Expand All @@ -19,7 +19,7 @@ class User(
val address: String,
val icon: String?,
val nickname: String,
id: OKey,
id: PrimaryKey,
createdTime: LocalDateTime
) :
BaseObj(id, createdTime) {
Expand All @@ -36,7 +36,7 @@ class User(
)
}

fun findById(it: OKey): User? {
fun findById(it: PrimaryKey): User? {
return find {
Users.id eq it
}.limit(1).firstOrNull()?.let(::wrapRow)
Expand Down
6 changes: 3 additions & 3 deletions cli/src/main/kotlin/com/storyteller_f/Add.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.storyteller_f.shared.*
import com.storyteller_f.shared.obj.AddRoom
import com.storyteller_f.shared.obj.AddTaskValue
import com.storyteller_f.shared.obj.AddTopic
import com.storyteller_f.shared.type.OKey
import com.storyteller_f.shared.type.PrimaryKey
import com.storyteller_f.shared.type.ObjectType
import com.storyteller_f.shared.type.Tuple4
import com.storyteller_f.shared.type.Tuple5
Expand Down Expand Up @@ -119,7 +119,7 @@ class Add : Subcommand("add", "add entry") {

private fun roomJoinCommunity(
l: List<AddRoom>,
idList: List<OKey>
idList: List<PrimaryKey>
): List<ResultRow> {
val communities = l.mapNotNull {
it.community
Expand Down Expand Up @@ -444,7 +444,7 @@ class Add : Subcommand("add", "add entry") {
}
}

private fun userJoinCommunity(users: List<String>, communityId: OKey) {
private fun userJoinCommunity(users: List<String>, communityId: PrimaryKey) {
users.forEach {
val userId = Users.select(Users.id).where {
Users.aid eq it
Expand Down
Loading

0 comments on commit 5980d25

Please sign in to comment.