fix: download link (#5365)

This commit is contained in:
Faisal Amir 2025-06-19 15:40:54 +07:00 committed by GitHub
parent 85d32a4c70
commit cf17576e1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 50 deletions

View File

@ -23,26 +23,25 @@ const systemsTemplate: SystemType[] = [
name: 'Mac ',
label: 'Universal',
logo: FaApple,
fileFormat: '{appname}-mac-universal-{tag}.dmg',
fileFormat: 'Jan_{tag}_universal.dmg',
},
{
name: 'Windows',
label: 'Standard (64-bit)',
logo: FaWindows,
fileFormat: '{appname}-win-x64-{tag}.exe',
fileFormat: 'Jan_{tag}_x64-setup.exe',
},
{
name: 'Linux (AppImage)',
label: 'AppImage',
logo: FaLinux,
fileFormat: '{appname}-linux-x86_64-{tag}.AppImage',
fileFormat: 'Jan_{tag}_amd64.AppImage',
},
{
name: 'Linux (deb)',
label: 'Deb',
logo: FaLinux,
fileFormat: '{appname}-linux-amd64-{tag}.deb',
fileFormat: 'Jan_{tag}_amd64.deb',
},
]
@ -55,37 +54,16 @@ const groupTemnplate = [
export default function CardDownload({ lastRelease }: Props) {
const [systems, setSystems] = useState(systemsTemplate)
const extractAppName = (fileName: string) => {
const regex = /^(.*?)-(?:mac|win|linux)-(?:arm64|x64|amd64|x86_64)-.*$/
const match = fileName.match(regex)
return match ? match[1] : null
}
useEffect(() => {
const updateDownloadLinks = async () => {
try {
// Extract appname from the first asset name
const firstAssetName = lastRelease.assets[0].name
const appname = extractAppName(firstAssetName)
if (!appname) {
console.error(
'Failed to extract appname from file name:',
firstAssetName
)
return
}
// Remove 'v' at the start of the tag_name
const tag = lastRelease.tag_name.startsWith('v')
? lastRelease.tag_name.substring(1)
: lastRelease.tag_name
const updatedSystems = systems.map((system) => {
const downloadUrl = system.fileFormat
.replace('{appname}', appname)
.replace('{tag}', tag)
const downloadUrl = system.fileFormat.replace('{tag}', tag)
// Find the corresponding asset to get the file size
const asset = lastRelease.assets.find(

View File

@ -28,31 +28,25 @@ const systemsTemplate: SystemType[] = [
{
name: 'Download for Mac',
logo: FaApple,
fileFormat: '{appname}-mac-universal-{tag}.dmg',
fileFormat: 'Jan_{tag}_universal.dmg',
},
{
name: 'Download for Windows',
logo: FaWindows,
fileFormat: '{appname}-win-x64-{tag}.exe',
fileFormat: 'Jan_{tag}_x64-setup.exe',
},
{
name: 'Download for Linux (AppImage)',
logo: FaLinux,
fileFormat: '{appname}-linux-x86_64-{tag}.AppImage',
fileFormat: 'Jan_{tag}_amd64.AppImage',
},
{
name: 'Download for Linux (deb)',
logo: FaLinux,
fileFormat: '{appname}-linux-amd64-{tag}.deb',
fileFormat: 'Jan_{tag}_amd64.deb',
},
]
const extractAppName = (fileName: string) => {
const regex = /^(.*?)-(?:mac|win|linux)-(?:arm64|x64|x86_64|amd64)-.*$/
const match = fileName.match(regex)
return match ? match[1] : null
}
const DropdownDownload = ({ lastRelease }: Props) => {
const [systems, setSystems] = useState(systemsTemplate)
const [defaultSystem, setDefaultSystem] = useState(systems[0])
@ -131,25 +125,14 @@ const DropdownDownload = ({ lastRelease }: Props) => {
useEffect(() => {
const updateDownloadLinks = async () => {
try {
const firstAssetName = await lastRelease.assets[0]?.name
console.log(lastRelease)
const appname = extractAppName(firstAssetName)
if (!appname) {
console.error(
'Failed to extract appname from file name:',
firstAssetName
)
changeDefaultSystem(systems)
return
}
const tag = lastRelease.tag_name.startsWith('v')
? lastRelease.tag_name.substring(1)
: lastRelease.tag_name
const updatedSystems = systems.map((system) => {
const downloadUrl = system.fileFormat
.replace('{appname}', appname)
.replace('{tag}', tag)
const downloadUrl = system.fileFormat.replace('{tag}', tag)
// Find the corresponding asset to get the file size
const asset = lastRelease.assets.find(