diff options
Diffstat (limited to 'server/tools/peertube-auth.ts')
-rw-r--r-- | server/tools/peertube-auth.ts | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts index 8bc3d332c..ff5ffb60e 100644 --- a/server/tools/peertube-auth.ts +++ b/server/tools/peertube-auth.ts | |||
@@ -9,7 +9,11 @@ const Table = require('cli-table') | |||
9 | async function delInstance (url: string) { | 9 | async 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 | ||
20 | async function setInstance (url: string, username: string, password: string) { | 24 | async 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 | }) |
@@ -93,6 +102,8 @@ program | |||
93 | }) | 102 | }) |
94 | 103 | ||
95 | settings.remotes.forEach(element => { | 104 | settings.remotes.forEach(element => { |
105 | if (!netrc.machines[element]) return | ||
106 | |||
96 | table.push([ | 107 | table.push([ |
97 | element, | 108 | element, |
98 | netrc.machines[element].login | 109 | netrc.machines[element].login |