@@ -59,25 +59,27 @@ class Fedy(
59
59
if (! MessageDigest .isEqual(this .toByteArray(), props.key.toByteArray())) 403 - " Invalid Key"
60
60
}
61
61
62
- data class PullReq (val extId : Long , val game : Str , val exportOptions : ExportOptions )
63
- @API(" /pull" )
64
- fun handlePull (@RH(KEY_HEADER ) key : Str , @RB req : PullReq ): Any {
62
+ data class DataPullReq (val extId : Long , val game : Str , val exportOptions : ExportOptions )
63
+ data class DataPullRes (val error : DataPullErr ? = null , val result : Any? = null )
64
+ data class DataPullErr (val code : Int , val message : Str )
65
+ @API(" /data/pull" )
66
+ fun handleDataPull (@RH(KEY_HEADER ) key : Str , @RB req : DataPullReq ): DataPullRes {
65
67
key.checkKey()
66
68
val card = cardRepo.findByExtId(req.extId).orElse(null )
67
69
? : (404 - " Card with extId ${req.extId} not found" )
68
70
fun catched (block : () -> Any ) =
69
- try { mapOf ( " result" to block()) }
70
- catch (e: ApiException ) { mapOf ( " error" to mapOf ( " code" to e.code, " message" to e.message.toString())) }
71
+ try { DataPullRes ( result = block()) }
72
+ catch (e: ApiException ) { DataPullRes ( error = DataPullErr ( code = e.code, message = e.message.toString())) }
71
73
return when (req.game) {
72
74
" mai2" -> catched { mai2Import.export(card, req.exportOptions) }
73
75
else -> 406 - " Unsupported game"
74
76
}
75
77
}
76
78
77
- data class PushReq (val extId : Long , val game : Str , val data : JDict , val removeOldData : Bool )
79
+ data class DataPushReq (val extId : Long , val game : Str , val data : JDict , val removeOldData : Bool )
78
80
@Suppress(" UNCHECKED_CAST" )
79
- @API(" /push" )
80
- fun handlePush (@RH(KEY_HEADER ) key : Str , @RB req : PushReq ): Any {
81
+ @API(" /data/ push" )
82
+ fun handleDataPush (@RH(KEY_HEADER ) key : Str , @RB req : DataPushReq ): Any {
81
83
key.checkKey()
82
84
val extId = req.extId
83
85
fun <UserData : IUserData , UserRepo : GenericUserDataRepo <UserData >> removeOldData (repo : UserRepo ) {
@@ -102,6 +104,27 @@ class Fedy(
102
104
return SUCCESS
103
105
}
104
106
107
+ // TODO: don't trigger Fedy events for operations initiated by Fedy downstream itself
108
+
109
+ data class CardResolveReq (val luid : Str , val pairedLuid : Str ? , val createIfNotFound : Bool )
110
+ data class CardResolveRes (val extId : Long , val isGhost : Bool , val isNewlyCreated : Bool , val isPairedLuidDiverged : Bool )
111
+ @API(" /card/resolve" )
112
+ fun handleCardResolve (@RH(KEY_HEADER ) key : Str , @RB req : CardResolveReq ): CardResolveRes {
113
+ throw NotImplementedError (" Not implemented" )
114
+ }
115
+
116
+ data class CardLinkReq (val auId : Long , val luid : Str )
117
+ @API(" /card/link" )
118
+ fun handleCardLink (@RH(KEY_HEADER ) key : Str , @RB req : CardLinkReq ): Any {
119
+ throw NotImplementedError (" Not implemented" )
120
+ }
121
+
122
+ data class CardUnlinkReq (val auId : Long , val luid : Str )
123
+ @API(" /card/unlink" )
124
+ fun handleCardUnlink (@RH(KEY_HEADER ) key : Str , @RB req : CardUnlinkReq ): Any {
125
+ throw NotImplementedError (" Not implemented" )
126
+ }
127
+
105
128
fun onCardCreated (luid : Str , extId : Long ) = maybeNotifyAsync(FedyEvent (cardCreated = CardCreatedEvent (luid, extId)))
106
129
fun onCardLinked (luid : Str , oldExtId : Long? , extId : Long , migratedGames : List <Str >) = maybeNotifyAsync(FedyEvent (cardLinked = CardLinkedEvent (luid, oldExtId, extId, migratedGames)))
107
130
fun onCardUnlinked (luid : Str ) = maybeNotifyAsync(FedyEvent (cardUnlinked = CardUnlinkedEvent (luid)))
0 commit comments