mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Merge pull request #1576 from Dokploy/1564-downloaded-ssh-keys-are-always-named-as-id_rsa-keys
refactor(ssh-keys): simplify downloadKey function and filename genera…
This commit is contained in:
@@ -112,15 +112,17 @@ export const HandleSSHKeys = ({ sshKeyId }: Props) => {
|
|||||||
toast.error("Error generating the SSH Key");
|
toast.error("Error generating the SSH Key");
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloadKey = (
|
const downloadKey = (content: string, keyType: "private" | "public") => {
|
||||||
content: string,
|
|
||||||
defaultFilename: string,
|
|
||||||
keyType: "private" | "public",
|
|
||||||
) => {
|
|
||||||
const keyName = form.watch("name");
|
const keyName = form.watch("name");
|
||||||
|
const publicKey = form.watch("publicKey");
|
||||||
|
|
||||||
|
// Extract algorithm type from public key
|
||||||
|
const isEd25519 = publicKey.startsWith("ssh-ed25519");
|
||||||
|
const defaultName = isEd25519 ? "id_ed25519" : "id_rsa";
|
||||||
|
|
||||||
const filename = keyName
|
const filename = keyName
|
||||||
? `${keyName}${sshKeyId ? `_${sshKeyId}` : ""}_${keyType}_${defaultFilename}`
|
? `${keyName}${sshKeyId ? `_${sshKeyId}` : ""}_${keyType}_${defaultName}${keyType === "public" ? ".pub" : ""}`
|
||||||
: `${keyType}_${defaultFilename}`;
|
: `${defaultName}${keyType === "public" ? ".pub" : ""}`;
|
||||||
const blob = new Blob([content], { type: "text/plain" });
|
const blob = new Blob([content], { type: "text/plain" });
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
@@ -273,7 +275,7 @@ export const HandleSSHKeys = ({ sshKeyId }: Props) => {
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
size="default"
|
size="default"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
downloadKey(form.watch("privateKey"), "id_rsa", "private")
|
downloadKey(form.watch("privateKey"), "private")
|
||||||
}
|
}
|
||||||
className="flex items-center gap-2"
|
className="flex items-center gap-2"
|
||||||
>
|
>
|
||||||
@@ -287,11 +289,7 @@ export const HandleSSHKeys = ({ sshKeyId }: Props) => {
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
size="default"
|
size="default"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
downloadKey(
|
downloadKey(form.watch("publicKey"), "public")
|
||||||
form.watch("publicKey"),
|
|
||||||
"id_rsa.pub",
|
|
||||||
"public",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
className="flex items-center gap-2"
|
className="flex items-center gap-2"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user