Skip to content

Commit 94328e2

Browse files
committed
feat: /card/* API stubs
1 parent 1c95dd5 commit 94328e2

File tree

1 file changed

+31
-8
lines changed
  • src/main/java/icu/samnyan/aqua/net

1 file changed

+31
-8
lines changed

src/main/java/icu/samnyan/aqua/net/Fedy.kt

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,27 @@ class Fedy(
5959
if (!MessageDigest.isEqual(this.toByteArray(), props.key.toByteArray())) 403 - "Invalid Key"
6060
}
6161

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 {
6567
key.checkKey()
6668
val card = cardRepo.findByExtId(req.extId).orElse(null)
6769
?: (404 - "Card with extId ${req.extId} not found")
6870
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())) }
7173
return when (req.game) {
7274
"mai2" -> catched { mai2Import.export(card, req.exportOptions) }
7375
else -> 406 - "Unsupported game"
7476
}
7577
}
7678

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)
7880
@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 {
8183
key.checkKey()
8284
val extId = req.extId
8385
fun<UserData : IUserData, UserRepo : GenericUserDataRepo<UserData>> removeOldData(repo: UserRepo) {
@@ -102,6 +104,27 @@ class Fedy(
102104
return SUCCESS
103105
}
104106

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+
105128
fun onCardCreated(luid: Str, extId: Long) = maybeNotifyAsync(FedyEvent(cardCreated = CardCreatedEvent(luid, extId)))
106129
fun onCardLinked(luid: Str, oldExtId: Long?, extId: Long, migratedGames: List<Str>) = maybeNotifyAsync(FedyEvent(cardLinked = CardLinkedEvent(luid, oldExtId, extId, migratedGames)))
107130
fun onCardUnlinked(luid: Str) = maybeNotifyAsync(FedyEvent(cardUnlinked = CardUnlinkedEvent(luid)))

0 commit comments

Comments
 (0)