handle other archive types for linux

This commit is contained in:
Garret Patti
2026-04-12 13:09:07 -04:00
parent 080cc011b9
commit 0091606e4d
3 changed files with 24 additions and 5 deletions

View File

@@ -23,18 +23,34 @@ const MIME_TYPES: Record<string, string> = {
'.zip': 'application/zip', '.zip': 'application/zip',
'.dmg': 'application/x-apple-diskimage', '.dmg': 'application/x-apple-diskimage',
'.gz': 'application/gzip', '.gz': 'application/gzip',
'.tgz': 'application/gzip',
'.bz2': 'application/x-bzip2',
'.xz': 'application/x-xz',
'.zst': 'application/zstd',
} }
function getMimeType(filePath: string): string { function getMimeType(filePath: string): string {
// Special-case .tar.gz before checking the last extension // Special-case multi-part extensions before checking the last extension
if (filePath.toLowerCase().endsWith('.tar.gz')) return 'application/gzip' const lower = filePath.toLowerCase()
if (lower.endsWith('.tar.gz')) return 'application/gzip'
if (lower.endsWith('.tar.bz2')) return 'application/x-bzip2'
if (lower.endsWith('.tar.xz')) return 'application/x-xz'
if (lower.endsWith('.tar.zst')) return 'application/zstd'
const ext = path.extname(filePath).toLowerCase() const ext = path.extname(filePath).toLowerCase()
return MIME_TYPES[ext] ?? 'application/octet-stream' return MIME_TYPES[ext] ?? 'application/octet-stream'
} }
function isDownloadAttachment(filePath: string): boolean { function isDownloadAttachment(filePath: string): boolean {
const lower = filePath.toLowerCase() const lower = filePath.toLowerCase()
return lower.endsWith('.zip') || lower.endsWith('.tar.gz') || lower.endsWith('.dmg') return (
lower.endsWith('.zip') ||
lower.endsWith('.tar.gz') ||
lower.endsWith('.tar.bz2') ||
lower.endsWith('.tar.xz') ||
lower.endsWith('.tar.zst') ||
lower.endsWith('.tgz') ||
lower.endsWith('.dmg')
)
} }
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {

View File

@@ -609,7 +609,6 @@ function DownloadButton({
onMouseLeave={(e) => ((e.currentTarget as HTMLElement).style.backgroundColor = 'transparent')} onMouseLeave={(e) => ((e.currentTarget as HTMLElement).style.backgroundColor = 'transparent')}
> >
<span className="flex-shrink-0"></span> <span className="flex-shrink-0"></span>
<PlatformPill platform={primary.platform} />
<span className="truncate">{primary.filename}</span> <span className="truncate">{primary.filename}</span>
<span className="justify-right flex-shrink-0"><PlatformPill platform={primary.platform} /></span> <span className="justify-right flex-shrink-0"><PlatformPill platform={primary.platform} /></span>
</a> </a>
@@ -647,8 +646,8 @@ function DownloadButton({
onMouseLeave={(e) => ((e.currentTarget as HTMLElement).style.backgroundColor = 'transparent')} onMouseLeave={(e) => ((e.currentTarget as HTMLElement).style.backgroundColor = 'transparent')}
> >
<span style={{ color: 'var(--text-secondary)' }} className="flex-shrink-0"></span> <span style={{ color: 'var(--text-secondary)' }} className="flex-shrink-0"></span>
<PlatformPill platform={file.platform} />
<span className="truncate">{file.filename}</span> <span className="truncate">{file.filename}</span>
<PlatformPill platform={file.platform} />
</a> </a>
))} ))}
</div> </div>

View File

@@ -11,6 +11,10 @@ function platformForFile(name: string): GamePlatform | null {
const lower = name.toLowerCase() const lower = name.toLowerCase()
if (lower.endsWith('.zip')) return 'windows' if (lower.endsWith('.zip')) return 'windows'
if (lower.endsWith('.tar.gz')) return 'linux' if (lower.endsWith('.tar.gz')) return 'linux'
if (lower.endsWith('.tar.bz2')) return 'linux'
if (lower.endsWith('.tar.xz')) return 'linux'
if (lower.endsWith('.tar.zst')) return 'linux'
if (lower.endsWith('.tgz')) return 'linux'
if (lower.endsWith('.dmg')) return 'macos' if (lower.endsWith('.dmg')) return 'macos'
if (lower.endsWith('.apk')) return 'android' if (lower.endsWith('.apk')) return 'android'
return null return null