Skip to content

Commit

Permalink
perf: 快照优化
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 25, 2023
1 parent c690edd commit ce3ca5a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/li/songe/gkd/debug/HttpService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class HttpService : CompositionService({
return embeddedServer(Netty, port, configure = { tcpKeepAlive = true }) {
install(KtorCorsPlugin)
install(KtorErrorPlugin)
install(ContentNegotiation) { json(Singleton.json) }
install(ContentNegotiation) { json(Singleton.keepNullJson) }

routing {
get("/") { call.respond("hello world") }
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/li/songe/gkd/debug/SnapshotExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ object SnapshotExt {

withContext(Dispatchers.IO) {
File(getSnapshotParentPath(snapshot.id)).apply { if (!exists()) mkdirs() }
val stream = File(getScreenshotPath(snapshot.id)).outputStream()
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
stream.close()
File(getScreenshotPath(snapshot.id)).outputStream().use { stream ->
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
}
val text = Singleton.keepNullJson.encodeToString(snapshot)
File(getSnapshotPath(snapshot.id)).writeText(text)
DbSet.snapshotDao.insert(snapshot.toSnapshot())
Expand Down
23 changes: 3 additions & 20 deletions app/src/main/java/li/songe/gkd/ui/SnapshotPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import li.songe.gkd.data.Snapshot
import li.songe.gkd.db.DbSet
import li.songe.gkd.debug.SnapshotExt
import li.songe.gkd.ui.destinations.ImagePreviewPageDestination
import li.songe.gkd.util.IMPORT_BASE_URL
import li.songe.gkd.util.LoadStatus
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.LocalPickContentLauncher
Expand Down Expand Up @@ -228,24 +229,6 @@ fun SnapshotPage() {
})
.then(modifier)
)
Divider()
Text(
text = "分享链接", modifier = Modifier
.clickable(onClick = {
selectedSnapshot = null
val intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, url)
type = "text/plain"
}
context.startActivity(
Intent.createChooser(
intent, "分享链接"
)
)
})
.then(modifier)
)
} else {
Text(
text = "生成链接(需科学上网)", modifier = Modifier
Expand Down Expand Up @@ -382,7 +365,7 @@ fun SnapshotPage() {

is LoadStatus.Success -> {
AlertDialog(title = { Text(text = "上传完成") }, text = {
Text(text = "https://gkd-kit.gitee.io/import/" + uploadStatusVal.result.id)
Text(text = IMPORT_BASE_URL + uploadStatusVal.result.id)
}, onDismissRequest = {}, dismissButton = {
TextButton(onClick = {
vm.uploadStatusFlow.value = null
Expand All @@ -391,7 +374,7 @@ fun SnapshotPage() {
}
}, confirmButton = {
TextButton(onClick = {
ClipboardUtils.copyText("https://gkd-kit.gitee.io/import/" + uploadStatusVal.result.id)
ClipboardUtils.copyText(IMPORT_BASE_URL + uploadStatusVal.result.id)
ToastUtils.showShort("复制成功")
vm.uploadStatusFlow.value = null
}) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/li/songe/gkd/util/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const val FILE_UPLOAD_URL = "https://github-upload-assets.lisonge.workers.dev/"
const val DEFAULT_SUBS_UPDATE_URL =
"https://registry.npmmirror.com/@gkd-kit/subscription/latest/files"

const val IMPORT_BASE_URL = "https://i.gkd.li/import/"

val safeRemoteBaseUrls = arrayOf(
"https://registry.npmmirror.com/@gkd-kit/",
"https://cdn.jsdelivr.net/npm/@gkd-kit/",
Expand Down

0 comments on commit ce3ca5a

Please sign in to comment.