()
| 1165 | } |
| 1166 | |
| 1167 | async function migrateLegacyRemoteWorkspaceSecrets(): Promise<void> { |
| 1168 | const cfg = await loadConfig() |
| 1169 | let changed = false |
| 1170 | let nextProfiles = [...cfg.remoteWorkspaceProfiles] |
| 1171 | let nextRemoteWorkspace = cfg.remoteWorkspace |
| 1172 | let nextProfileId = cfg.remoteWorkspaceProfileId |
| 1173 | |
| 1174 | for (const profile of nextProfiles) { |
| 1175 | if (profile.authToken && profile.authToken.trim()) { |
| 1176 | await setRemoteWorkspaceSecret(profile.id, profile.authToken) |
| 1177 | delete profile.authToken |
| 1178 | changed = true |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | if (nextRemoteWorkspace?.authToken && nextRemoteWorkspace.authToken.trim()) { |
| 1183 | let targetProfile = |
| 1184 | findRemoteProfileById(nextProfiles, nextProfileId) ?? |
| 1185 | nextProfiles.find( |
| 1186 | (entry) => normalizeRemoteBaseUrl(entry.baseUrl) === normalizeRemoteBaseUrl(nextRemoteWorkspace!.baseUrl) |
| 1187 | ) ?? |
| 1188 | null |
| 1189 | |
| 1190 | if (!targetProfile) { |
| 1191 | targetProfile = { |
| 1192 | id: randomUUID(), |
| 1193 | name: deriveRemoteWorkspaceProfileName( |
| 1194 | { |
| 1195 | baseUrl: nextRemoteWorkspace.baseUrl, |
| 1196 | vaultPath: currentVault?.root ?? null |
| 1197 | }, |
| 1198 | nextProfiles |
| 1199 | ), |
| 1200 | baseUrl: normalizeRemoteBaseUrl(nextRemoteWorkspace.baseUrl), |
| 1201 | vaultPath: currentVault?.root ?? null, |
| 1202 | lastConnectedAt: null |
| 1203 | } |
| 1204 | nextProfiles = [...nextProfiles, targetProfile].sort((a, b) => a.name.localeCompare(b.name)) |
| 1205 | nextProfileId = targetProfile.id |
| 1206 | } |
| 1207 | |
| 1208 | await setRemoteWorkspaceSecret(targetProfile.id, nextRemoteWorkspace.authToken) |
| 1209 | nextRemoteWorkspace = { baseUrl: nextRemoteWorkspace.baseUrl } |
| 1210 | changed = true |
| 1211 | } |
| 1212 | |
| 1213 | if (!changed) return |
| 1214 | |
| 1215 | await updateConfig((current) => ({ |
| 1216 | ...current, |
| 1217 | remoteWorkspace: nextRemoteWorkspace |
| 1218 | ? { |
| 1219 | baseUrl: normalizeRemoteBaseUrl(nextRemoteWorkspace.baseUrl) |
| 1220 | } |
| 1221 | : null, |
| 1222 | remoteWorkspaceProfiles: nextProfiles.map((profile) => ({ |
| 1223 | id: profile.id, |
| 1224 | name: profile.name, |
no test coverage detected