feat: integrate LAN option with quicksettings

This commit is contained in:
bsourisse 2023-06-11 15:39:11 +02:00
parent f1fdbc47fc
commit fb9d84226d
3 changed files with 21 additions and 3 deletions

View file

@ -5,6 +5,23 @@ import classes from './QuickCommands.module.css';
import { IconSettingsAutomation, IconCopy } from '@tabler/icons'; import { IconSettingsAutomation, IconCopy } from '@tabler/icons';
export default function QuickCommands(props) { export default function QuickCommands(props) {
////Vars
//Needed to generate command for borg over LAN instead of WAN if env vars are set and option enabled.
let HOSTNAME;
let SSH_SERVER_PORT;
console.log(props.lanCommand);
if (
props.lanCommand &&
process.env.NEXT_PUBLIC_HOSTNAME_LAN &&
process.env.NEXT_PUBLIC_SSH_SERVER_PORT_LAN
) {
HOSTNAME = process.env.NEXT_PUBLIC_HOSTNAME_LAN;
SSH_SERVER_PORT = process.env.NEXT_PUBLIC_SSH_SERVER_PORT_LAN;
} else {
HOSTNAME = process.env.NEXT_PUBLIC_HOSTNAME;
SSH_SERVER_PORT = process.env.NEXT_PUBLIC_SSH_SERVER_PORT;
}
//State //State
const [isCopied, setIsCopied] = useState(false); const [isCopied, setIsCopied] = useState(false);
@ -13,7 +30,7 @@ export default function QuickCommands(props) {
// Asynchronously call copy to clipboard // Asynchronously call copy to clipboard
navigator.clipboard navigator.clipboard
.writeText( .writeText(
`borg init -e repokey-blake2 ssh://${props.unixUser}@${process.env.NEXT_PUBLIC_HOSTNAME}:${process.env.NEXT_PUBLIC_SSH_SERVER_PORT}/./${props.repository}` `borg init -e repokey-blake2 ssh://${props.unixUser}@${HOSTNAME}:${SSH_SERVER_PORT}/./${props.repository}`
) )
.then(() => { .then(() => {
// If successful, update the isCopied state value // If successful, update the isCopied state value
@ -34,8 +51,7 @@ export default function QuickCommands(props) {
) : ( ) : (
<div className={classes.tooltip}> <div className={classes.tooltip}>
borg init -e repokey-blake2 ssh://{props.unixUser}@ borg init -e repokey-blake2 ssh://{props.unixUser}@
{process.env.NEXT_PUBLIC_HOSTNAME}: {HOSTNAME}:{SSH_SERVER_PORT}/./
{process.env.NEXT_PUBLIC_SSH_SERVER_PORT}/./
{props.repository} {props.repository}
</div> </div>
)} )}

View file

@ -34,6 +34,7 @@ export default function Repo(props) {
<QuickCommands <QuickCommands
unixUser={props.unixUser} unixUser={props.unixUser}
repository={props.repository} repository={props.repository}
lanCommand={props.lanCommand}
/> />
</div> </div>

View file

@ -136,6 +136,7 @@ export default function RepoList() {
displayDetails={repo.displayDetails} displayDetails={repo.displayDetails}
unixUser={repo.unixUser} unixUser={repo.unixUser}
comment={repo.comment} comment={repo.comment}
lanCommand={repo.lanCommand}
repoManageEditHandler={() => repoManageEditHandler(repo.id)} repoManageEditHandler={() => repoManageEditHandler(repo.id)}
></Repo> ></Repo>
{repo.displayDetails ? ( {repo.displayDetails ? (