package com.adealink.weparty.util

import android.net.Uri
import androidx.core.net.toUri

/**
 * 从链接获取比例
 * 输入
 * eg: https://lanu-public-test-1377959011.cos.ap-guangzhou.myqcloud.com/gami/avatar/44046515/2026/61/cii/74386ebf2e4b9f4443544f794762899f.838x838.png
 *
 * 输出
 * 838x838
 */
fun parseResolution(url: String): String? {
    val uri = url.toUri()
    return uri.extractResolutionFromFileName()
}

// 扩展函数版本
fun Uri.extractResolutionFromFileName(): String? {
    val fileName = this.lastPathSegment ?: return null
    val pattern = "\\d+x\\d+".toRegex()
    return pattern.find(fileName)?.value
}