From af7e411932c86942bc1a9aeb84f87a62a8d95ccb Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:55:12 +0800 Subject: [PATCH] Refine GalleryMultiPageViewerPTokenParser --- .../parser/GalleryMultiPageViewerPTokenParser.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryMultiPageViewerPTokenParser.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryMultiPageViewerPTokenParser.kt index 628930854..40d2a0949 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryMultiPageViewerPTokenParser.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryMultiPageViewerPTokenParser.kt @@ -19,22 +19,18 @@ package com.hippo.ehviewer.client.parser import com.hippo.ehviewer.client.exception.ParseException import com.hippo.ehviewer.client.parseAs -import com.hippo.ehviewer.util.ExceptionUtils import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable object GalleryMultiPageViewerPTokenParser { private const val IMAGE_LIST_STRING = "var imagelist = " - fun parse(body: String): List { + fun parse(body: String): List = runCatching { val index = body.indexOf(IMAGE_LIST_STRING) val imagelist = body.substring(index + IMAGE_LIST_STRING.length, body.indexOf(";", index)) - return runCatching { - imagelist.parseAs>().map(Item::token) - }.getOrElse { - ExceptionUtils.throwIfFatal(it) - throw ParseException("Parse pToken from MPV error", it) - } + imagelist.parseAs>().map(Item::token) + }.getOrElse { + throw ParseException("Parse pToken from MPV error", it) } @Serializable