Skip to content

Commit 2d701d4

Browse files
authored
feat: Device snapshot delete api (gkd-kit#1294)
### **快照删除 API 详情** * **请求地址**: `http://[手机IP]:[端口]/api/deleteSnapshot` * **请求方法**: `POST` * **请求头**: `Content-Type: application/json` * **请求体 (JSON)**: ```json { "id": 123456789 } ``` *(注:`id` 为长整型数字,不加引号)* * **预期响应**: ```json { "message": "快照删除成功" } ```
1 parent 5cbfab3 commit 2d701d4

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

app/src/main/kotlin/li/songe/gkd/service/HttpService.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ private fun CoroutineScope.createServer(port: Int) = embeddedServer(CIO, port) {
214214
}
215215
call.respond(list)
216216
}
217+
post("/deleteSnapshot") {
218+
val data = call.receive<ReqId>()
219+
val allSnapshots = DbSet.snapshotDao.query().first()
220+
val snapshot = allSnapshots.find { it.id == data.id }
221+
if (snapshot != null) {
222+
SnapshotExt.removeSnapshot(data.id)
223+
DbSet.snapshotDao.delete(snapshot)
224+
call.respond(RpcOk("快照删除成功"))
225+
} else {
226+
throw RpcError("快照不存在或已被删除")
227+
}
228+
}
217229
post("/updateSubscription") {
218230
val subscription =
219231
RawSubscription.parse(call.receiveText(), json5 = false)

0 commit comments

Comments
 (0)