(
input: {
id?: string
baseUrl: string
vaultPath?: string | null
},
existingProfiles: PersistedRemoteWorkspaceProfile[]
)
| 1109 | } |
| 1110 | |
| 1111 | function deriveRemoteWorkspaceProfileName( |
| 1112 | input: { |
| 1113 | id?: string |
| 1114 | baseUrl: string |
| 1115 | vaultPath?: string | null |
| 1116 | }, |
| 1117 | existingProfiles: PersistedRemoteWorkspaceProfile[] |
| 1118 | ): string { |
| 1119 | const normalizedBaseUrl = normalizeRemoteBaseUrl(input.baseUrl) |
| 1120 | let host = 'ZenNotes Server' |
| 1121 | try { |
| 1122 | const normalizedUrl = /^https?:\/\//i.test(normalizedBaseUrl) |
| 1123 | ? normalizedBaseUrl |
| 1124 | : `http://${normalizedBaseUrl}` |
| 1125 | host = new URL(normalizedUrl).host || host |
| 1126 | } catch { |
| 1127 | if (normalizedBaseUrl) host = normalizedBaseUrl |
| 1128 | } |
| 1129 | |
| 1130 | const trimmedVaultPath = input.vaultPath?.trim() || null |
| 1131 | let baseName = host |
| 1132 | if (trimmedVaultPath) { |
| 1133 | const normalizedVaultPath = trimmedVaultPath.replace(/\\/g, '/').replace(/\/+$/, '') |
| 1134 | const vaultName = path.posix.basename(normalizedVaultPath) |
| 1135 | if (vaultName && vaultName !== '.' && vaultName !== '/') { |
| 1136 | baseName = `${vaultName} (${host})` |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | const otherProfiles = existingProfiles.filter((entry) => entry.id !== input.id) |
| 1141 | if (!otherProfiles.some((entry) => entry.name === baseName)) return baseName |
| 1142 | |
| 1143 | let suffix = 2 |
| 1144 | while (otherProfiles.some((entry) => entry.name === `${baseName} ${suffix}`)) suffix += 1 |
| 1145 | return `${baseName} ${suffix}` |
| 1146 | } |
| 1147 | |
| 1148 | function profileMatchesConnection( |
| 1149 | profile: PersistedRemoteWorkspaceProfile, |
no test coverage detected