+const isValidIpAddress = (ipAddress: string): Boolean => {
+ if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipAddress)) {
+ return true;
+ }
+
+ return false;
+};
+
+const mountainduckTemplate = ({
+ uuid,
+ username,
+ cyberDavStr,
+ collectionsUrl
+}: any) => {
+
+ return `<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+ <plist version="1.0">
+ <dict>
+ <key>Protocol</key>
+ <string>davs</string>
+ <key>Provider</key>
+ <string>iterate GmbH</string>
+ <key>UUID</key>
+ <string>${uuid}</string>
+ <key>Hostname</key>
+ <string>${collectionsUrl.replace('https://', ``).replace('*', uuid).split(':')[0]}</string>
+ <key>Port</key>
+ <string>${(cyberDavStr.split(':')[2] || '443').split('/')[0]}</string>
+ <key>Username</key>
+ <string>${username}</string>${isValidIpAddress(collectionsUrl.replace('https://', ``).split(':')[0]) ?
+ `
+ <key>Path</key>
+ <string>/c=${uuid}</string>` : ''}
+ <key>Labels</key>
+ <array>
+ </array>
+ </dict>
+ </plist>`.split(/\r?\n/).join('\n');
+};
+
+const downloadMountainduckFileHandler = (filename: string, text: string) => {
+ const element = document.createElement('a');
+ element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
+ element.setAttribute('download', filename);
+
+ element.style.display = 'none';
+ document.body.appendChild(element);
+
+ element.click();
+
+ document.body.removeChild(element);
+};
+