Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -13,7 +13,7 @@ jobs:
|
|||||||
stale:
|
stale:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: ${{ github.actor == 'gedoor' }}
|
if: ${{ github.repository == 'gedoor/legado' }}
|
||||||
permissions:
|
permissions:
|
||||||
issues: write
|
issues: write
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun onArchiveFileClick(fileDoc: FileDoc) {
|
open fun onArchiveFileClick(fileDoc: FileDoc) {
|
||||||
val fileNames = ArchiveUtils.getArchiveFilesName(fileDoc) {
|
val fileNames = ArchiveUtils.getArchiveFilesName(fileDoc) {
|
||||||
it.matches(AppPattern.bookFileRegex)
|
it.matches(AppPattern.bookFileRegex)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package io.legado.app.utils
|
package io.legado.app.utils
|
||||||
|
|
||||||
|
import io.legado.app.BuildConfig
|
||||||
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
@@ -75,11 +77,25 @@ object UrlUtil {
|
|||||||
conn.instanceFollowRedirects = false
|
conn.instanceFollowRedirects = false
|
||||||
conn.connect()
|
conn.connect()
|
||||||
|
|
||||||
|
if (AppConfig.recordLog || BuildConfig.DEBUG) {
|
||||||
|
val headers = conn.headerFields
|
||||||
|
val headersString = buildString {
|
||||||
|
headers.forEach { (key, value) ->
|
||||||
|
value.forEach {
|
||||||
|
append(key)
|
||||||
|
append(": ")
|
||||||
|
append(it)
|
||||||
|
append("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AppLog.put("${url.toString()} response header:\n$headersString")
|
||||||
|
}
|
||||||
|
|
||||||
// val fileSize = conn.getContentLengthLong() / 1024
|
// val fileSize = conn.getContentLengthLong() / 1024
|
||||||
/** Content-Disposition 存在三种情况
|
/** Content-Disposition 存在三种情况 文件名应该用引号 有些用空格
|
||||||
* filename="filename"
|
* filename="filename"
|
||||||
* filename=filename
|
* filename*="charset''filename"
|
||||||
* filename*=charset''filename
|
|
||||||
*/
|
*/
|
||||||
val raw: String? = conn.getHeaderField("Content-Disposition")
|
val raw: String? = conn.getHeaderField("Content-Disposition")
|
||||||
// Location跳转到实际链接
|
// Location跳转到实际链接
|
||||||
@@ -90,13 +106,13 @@ object UrlUtil {
|
|||||||
val names = hashSetOf<String>()
|
val names = hashSetOf<String>()
|
||||||
fileNames.forEach {
|
fileNames.forEach {
|
||||||
var fileName = it.substringAfter("=")
|
var fileName = it.substringAfter("=")
|
||||||
|
.trim()
|
||||||
|
.replace("^\"".toRegex(), "")
|
||||||
|
.replace("\"$".toRegex(), "")
|
||||||
if (it.contains("filename*")) {
|
if (it.contains("filename*")) {
|
||||||
val data = fileName.split("''")
|
val data = fileName.split("''")
|
||||||
names.add(URLDecoder.decode(data[1], data[0]))
|
names.add(URLDecoder.decode(data[1], data[0]))
|
||||||
} else {
|
} else {
|
||||||
fileName = fileName
|
|
||||||
.replace("^\"".toRegex(), "")
|
|
||||||
.replace("\"$".toRegex(), "")
|
|
||||||
names.add(
|
names.add(
|
||||||
String(
|
String(
|
||||||
fileName.toByteArray(StandardCharsets.ISO_8859_1),
|
fileName.toByteArray(StandardCharsets.ISO_8859_1),
|
||||||
@@ -110,19 +126,7 @@ object UrlUtil {
|
|||||||
val newUrl= URL(URLDecoder.decode(redirectUrl, "UTF-8"))
|
val newUrl= URL(URLDecoder.decode(redirectUrl, "UTF-8"))
|
||||||
getFileNameFromPath(newUrl)
|
getFileNameFromPath(newUrl)
|
||||||
} else {
|
} else {
|
||||||
// 其余情况 返回响应头
|
AppLog.put("Cannot obtain URL file name, enable recordLog for detail")
|
||||||
val headers = conn.headerFields
|
|
||||||
val headersString = buildString {
|
|
||||||
headers.forEach { (key, value) ->
|
|
||||||
value.forEach {
|
|
||||||
append(key)
|
|
||||||
append(": ")
|
|
||||||
append(it)
|
|
||||||
append("\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AppLog.put("Cannot obtain URL file name:\n$headersString")
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user