X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fpeertube-auth.ts;h=ff5ffb60e90a36a56009df2359df7d0c2c52bec0;hb=1a12f66d631d28a5a58ebbcd274426f2e6e5d203;hp=e53283fbe7805c6928c279518bd1dad1772917fe;hpb=4913295f9db1a7b814129d90b159a418cb32bb75;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts index e53283fbe..ff5ffb60e 100644 --- a/server/tools/peertube-auth.ts +++ b/server/tools/peertube-auth.ts @@ -9,7 +9,11 @@ const Table = require('cli-table') async function delInstance (url: string) { const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ]) - settings.remotes.splice(settings.remotes.indexOf(url)) + const index = settings.remotes.indexOf(url) + settings.remotes.splice(index) + + if (settings.default === index) settings.default = -1 + await writeSettings(settings) delete netrc.machines[url] @@ -17,12 +21,17 @@ async function delInstance (url: string) { await netrc.save() } -async function setInstance (url: string, username: string, password: string) { +async function setInstance (url: string, username: string, password: string, isDefault: boolean) { const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ]) if (settings.remotes.indexOf(url) === -1) { settings.remotes.push(url) } + + if (isDefault || settings.remotes.length === 1) { + settings.default = settings.remotes.length - 1 + } + await writeSettings(settings) netrc.machines[url] = { login: username, password } @@ -66,7 +75,7 @@ program } } }, async (_, result) => { - await setInstance(result.url, result.username, result.password) + await setInstance(result.url, result.username, result.password, program['default']) process.exit(0) })