-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload Download Kernel Images (#413)
* base for kernel image upload/download * Downloads page and artifact upload/download * fix example resources * improved file drag and drop zone * functionality to upload tgz artifact * Fetch artifacts * Kernel upload flow * partial lint fix * Revert independent artifact backend changes * New KernelImage model, crud, and routers * Kernel Image Upload Download * Base64 Encode File workaround TypeSafe * Require mod or admin permissions backend * Fix admin mod permission and lint * Fix typing on update kernel image
- Loading branch information
1 parent
f719274
commit 991d854
Showing
18 changed files
with
3,849 additions
and
2,591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { useState } from "react"; | ||
|
||
import { | ||
Card, | ||
CardContent, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/Card"; | ||
import { Badge } from "@/components/ui/badge"; | ||
import { Button } from "@/components/ui/button"; | ||
import { components } from "@/gen/api"; | ||
import { useAlertQueue } from "@/hooks/useAlertQueue"; | ||
import axios from "axios"; | ||
import { Download } from "lucide-react"; | ||
|
||
type KernelImageResponse = components["schemas"]["KernelImageResponse"]; | ||
|
||
interface Props { | ||
kernelImage: KernelImageResponse; | ||
} | ||
|
||
const DownloadKernelImage = ({ kernelImage }: Props) => { | ||
const { addErrorAlert } = useAlertQueue(); | ||
const [isDownloading, setIsDownloading] = useState(false); | ||
|
||
const handleDownload = async () => { | ||
setIsDownloading(true); | ||
try { | ||
const response = await axios.get( | ||
`/api/kernel-images/download/${kernelImage.id}`, | ||
); | ||
const downloadUrl = response.data; | ||
window.location.href = downloadUrl; | ||
} catch (error) { | ||
console.error("Error downloading kernel image:", error); | ||
addErrorAlert("Error downloading kernel image"); | ||
} finally { | ||
setIsDownloading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Card key={kernelImage.id}> | ||
<CardHeader className="space-y-2"> | ||
<CardTitle className="flex justify-between items-center"> | ||
{kernelImage.name} | ||
<div className="flex gap-1"> | ||
<Badge variant="outline" className="bg-blue-100 text-blue-800"> | ||
Kernel | ||
</Badge> | ||
{kernelImage.is_official && ( | ||
<Badge variant="primary">Official</Badge> | ||
)} | ||
</div> | ||
</CardTitle> | ||
{kernelImage.description ? ( | ||
<p className="text-sm text-muted-foreground"> | ||
{kernelImage.description} | ||
</p> | ||
) : ( | ||
<div className="h-5" /> // Placeholder to maintain spacing | ||
)} | ||
</CardHeader> | ||
<CardContent> | ||
<div className="flex flex-col justify-between text-sm text-gray-11"> | ||
<span>Size: {(kernelImage.size / 1024 / 1024).toFixed(2)} MB</span> | ||
<span>Downloads: {kernelImage.downloads}</span> | ||
</div> | ||
</CardContent> | ||
<CardFooter> | ||
<Button | ||
className="w-full" | ||
onClick={handleDownload} | ||
disabled={isDownloading} | ||
> | ||
<Download className="mr-2 h-4 w-4" /> | ||
{isDownloading ? "Downloading..." : "Download"} | ||
</Button> | ||
</CardFooter> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default DownloadKernelImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.