Skip to content

Commit

Permalink
fix: image download
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed May 28, 2022
1 parent 409c8cc commit d14de44
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/kotlin/io/github/gnuf0rce/mirai/rss/RssContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ internal val client: RssHttpClient by lazy {
}
}

private val Url.filename get() = encodedPath.substringAfterLast('/').decodeURLPart()
internal val Url.filename get() = encodedPath.substringAfterLast('/').decodeURLPart()

private fun HttpMessage.contentDisposition(): ContentDisposition? {
internal fun HttpMessage.contentDisposition(): ContentDisposition? {
return ContentDisposition.parse(headers[HttpHeaders.ContentDisposition] ?: return null)
}

Expand Down Expand Up @@ -167,12 +167,14 @@ internal suspend fun Element.image(subject: Contact): MessageContent {
client.useHttpClient { http ->
http.get<HttpStatement>(url).execute { response ->
val relative = response.contentDisposition()?.parameter(ContentDisposition.Parameters.FileName)
?: response.etag()?.removeSurrounding("\"")
?.plus(".")?.plus(response.contentType()?.contentSubtype)
?: response.request.url.filename

val file = ImageFolder.resolve(relative)

if (file.exists().not()) {
file.mkdirs()
file.parentFile.mkdirs()
file.outputStream().use { output ->
val channel: ByteReadChannel = response.receive()

Expand Down

0 comments on commit d14de44

Please sign in to comment.