fix: download link (#5365)
This commit is contained in:
parent
85d32a4c70
commit
cf17576e1c
@ -23,26 +23,25 @@ const systemsTemplate: SystemType[] = [
|
|||||||
name: 'Mac ',
|
name: 'Mac ',
|
||||||
label: 'Universal',
|
label: 'Universal',
|
||||||
logo: FaApple,
|
logo: FaApple,
|
||||||
fileFormat: '{appname}-mac-universal-{tag}.dmg',
|
fileFormat: 'Jan_{tag}_universal.dmg',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: 'Windows',
|
name: 'Windows',
|
||||||
label: 'Standard (64-bit)',
|
label: 'Standard (64-bit)',
|
||||||
logo: FaWindows,
|
logo: FaWindows,
|
||||||
fileFormat: '{appname}-win-x64-{tag}.exe',
|
fileFormat: 'Jan_{tag}_x64-setup.exe',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Linux (AppImage)',
|
name: 'Linux (AppImage)',
|
||||||
label: 'AppImage',
|
label: 'AppImage',
|
||||||
logo: FaLinux,
|
logo: FaLinux,
|
||||||
fileFormat: '{appname}-linux-x86_64-{tag}.AppImage',
|
fileFormat: 'Jan_{tag}_amd64.AppImage',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Linux (deb)',
|
name: 'Linux (deb)',
|
||||||
label: 'Deb',
|
label: 'Deb',
|
||||||
logo: FaLinux,
|
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) {
|
export default function CardDownload({ lastRelease }: Props) {
|
||||||
const [systems, setSystems] = useState(systemsTemplate)
|
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(() => {
|
useEffect(() => {
|
||||||
const updateDownloadLinks = async () => {
|
const updateDownloadLinks = async () => {
|
||||||
try {
|
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
|
// Remove 'v' at the start of the tag_name
|
||||||
const tag = lastRelease.tag_name.startsWith('v')
|
const tag = lastRelease.tag_name.startsWith('v')
|
||||||
? lastRelease.tag_name.substring(1)
|
? lastRelease.tag_name.substring(1)
|
||||||
: lastRelease.tag_name
|
: lastRelease.tag_name
|
||||||
|
|
||||||
const updatedSystems = systems.map((system) => {
|
const updatedSystems = systems.map((system) => {
|
||||||
const downloadUrl = system.fileFormat
|
const downloadUrl = system.fileFormat.replace('{tag}', tag)
|
||||||
.replace('{appname}', appname)
|
|
||||||
.replace('{tag}', tag)
|
|
||||||
|
|
||||||
// Find the corresponding asset to get the file size
|
// Find the corresponding asset to get the file size
|
||||||
const asset = lastRelease.assets.find(
|
const asset = lastRelease.assets.find(
|
||||||
|
|||||||
@ -28,31 +28,25 @@ const systemsTemplate: SystemType[] = [
|
|||||||
{
|
{
|
||||||
name: 'Download for Mac',
|
name: 'Download for Mac',
|
||||||
logo: FaApple,
|
logo: FaApple,
|
||||||
fileFormat: '{appname}-mac-universal-{tag}.dmg',
|
fileFormat: 'Jan_{tag}_universal.dmg',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Download for Windows',
|
name: 'Download for Windows',
|
||||||
logo: FaWindows,
|
logo: FaWindows,
|
||||||
fileFormat: '{appname}-win-x64-{tag}.exe',
|
fileFormat: 'Jan_{tag}_x64-setup.exe',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Download for Linux (AppImage)',
|
name: 'Download for Linux (AppImage)',
|
||||||
logo: FaLinux,
|
logo: FaLinux,
|
||||||
fileFormat: '{appname}-linux-x86_64-{tag}.AppImage',
|
fileFormat: 'Jan_{tag}_amd64.AppImage',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Download for Linux (deb)',
|
name: 'Download for Linux (deb)',
|
||||||
logo: FaLinux,
|
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 DropdownDownload = ({ lastRelease }: Props) => {
|
||||||
const [systems, setSystems] = useState(systemsTemplate)
|
const [systems, setSystems] = useState(systemsTemplate)
|
||||||
const [defaultSystem, setDefaultSystem] = useState(systems[0])
|
const [defaultSystem, setDefaultSystem] = useState(systems[0])
|
||||||
@ -131,25 +125,14 @@ const DropdownDownload = ({ lastRelease }: Props) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateDownloadLinks = async () => {
|
const updateDownloadLinks = async () => {
|
||||||
try {
|
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')
|
const tag = lastRelease.tag_name.startsWith('v')
|
||||||
? lastRelease.tag_name.substring(1)
|
? lastRelease.tag_name.substring(1)
|
||||||
: lastRelease.tag_name
|
: lastRelease.tag_name
|
||||||
|
|
||||||
const updatedSystems = systems.map((system) => {
|
const updatedSystems = systems.map((system) => {
|
||||||
const downloadUrl = system.fileFormat
|
const downloadUrl = system.fileFormat.replace('{tag}', tag)
|
||||||
.replace('{appname}', appname)
|
|
||||||
.replace('{tag}', tag)
|
|
||||||
|
|
||||||
// Find the corresponding asset to get the file size
|
// Find the corresponding asset to get the file size
|
||||||
const asset = lastRelease.assets.find(
|
const asset = lastRelease.assets.find(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user