Skip to content

Commit

Permalink
[Feat]: 图片上传默认取最大像素
Browse files Browse the repository at this point in the history
  • Loading branch information
why committed Dec 17, 2023
1 parent 908d978 commit 2a932b2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ open class BasePostViewModel : BaseViewModel() {
val blogImage = BgmApiManager.bgmWebApi.uploadBlogImage(
MultipartBody.Part.createFormData("file", file.name, file.asRequestBody())
)
val url = blogImage.thumbUrl.orEmpty()

return if (url.startsWith("//")) "https:$url" else url
return blogImage.thumbUrl.orEmpty().optImageUrl(largest = true)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ fun String.fetchStyleBackgroundUrl(): String {
* --->
* https://lain.bgm.tv/pic/photo/g/41/30/823739_i8sWx.jpg
*/
fun String.optImageUrl(large: Boolean = true): String {
fun String.optImageUrl(large: Boolean = true, largest: Boolean = false): String {
val imageUrl = when {
startsWith("//") -> "https:$this"
startsWith("/") -> "${BgmApiManager.URL_BASE_WEB}$this"
else -> this
}
val size = if (large) "400" else "200"
val size = if (largest) "800" else if (large) "400" else "200"
val defaultImage = "file:///android_asset/image/info_only.jpg"
return imageUrl
.replace("/r/(.*?)/".toRegex(), "/")
Expand Down

0 comments on commit 2a932b2

Please sign in to comment.