aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-auth.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/peertube-auth.ts')
-rw-r--r--server/tools/peertube-auth.ts15
1 files changed, 12 insertions, 3 deletions
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')
9async function delInstance (url: string) { 9async function delInstance (url: string) {
10 const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ]) 10 const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ])
11 11
12 settings.remotes.splice(settings.remotes.indexOf(url)) 12 const index = settings.remotes.indexOf(url)
13 settings.remotes.splice(index)
14
15 if (settings.default === index) settings.default = -1
16
13 await writeSettings(settings) 17 await writeSettings(settings)
14 18
15 delete netrc.machines[url] 19 delete netrc.machines[url]
@@ -17,12 +21,17 @@ async function delInstance (url: string) {
17 await netrc.save() 21 await netrc.save()
18} 22}
19 23
20async function setInstance (url: string, username: string, password: string) { 24async function setInstance (url: string, username: string, password: string, isDefault: boolean) {
21 const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ]) 25 const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ])
22 26
23 if (settings.remotes.indexOf(url) === -1) { 27 if (settings.remotes.indexOf(url) === -1) {
24 settings.remotes.push(url) 28 settings.remotes.push(url)
25 } 29 }
30
31 if (isDefault || settings.remotes.length === 1) {
32 settings.default = settings.remotes.length - 1
33 }
34
26 await writeSettings(settings) 35 await writeSettings(settings)
27 36
28 netrc.machines[url] = { login: username, password } 37 netrc.machines[url] = { login: username, password }
@@ -66,7 +75,7 @@ program
66 } 75 }
67 } 76 }
68 }, async (_, result) => { 77 }, async (_, result) => {
69 await setInstance(result.url, result.username, result.password) 78 await setInstance(result.url, result.username, result.password, program['default'])
70 79
71 process.exit(0) 80 process.exit(0)
72 }) 81 })