Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function searchServer(serverId) {
let serverInfo = await getServer(serverId)
if (serverInfo === null) {
console.error("serverInfo not found");
return
}
let client = createClient(serverInfo.url, serverInfo.username, serverInfo.password)
createClient.setFetchMethod(window.fetch);
/**
* returns Object:[]DirInfo
*/
let bfs = async function () {
let queue = ['/']
let foundDirectories = []
while (queue.length) {
let path = queue.shift()
// TODO: Implement depth better
if (path.split('/').length > SEARCH_DEPTH)
break; // We've exceeded search depth
let contents = await client.getDirectoryContents(path, { credentials: 'omit' });
let foundKDBXInDir = false;
return getServer(serverId).then(serverInfo => {
if (serverInfo === null)
return []
let client = createClient(serverInfo.url, serverInfo.username, serverInfo.password)
createClient.setFetchMethod(window.fetch);
return client.getDirectoryContents(directory, { credentials: 'omit' }).then(contents => {
// map from directory contents to DBInfo type.
return contents.filter(element => {
return element.filename.indexOf('.kdbx') >= 1
}).map(element => {
return {
title: element.basename,
path: element.filename,
serverId: serverId
}
})
})
})
}
function addServer(url, username, password) {
let client = createClient(url, username, password)
createClient.setFetchMethod((a, b) => {
return window.fetch(a, b);
})
return client.getDirectoryContents('/', { credentials: 'omit' }).then(contents => {
// success!
let serverInfo = {
url: url,
username: username,
password: password
}
return settings.getSetWebdavServerList().then(serverList => {
serverList = serverList.length ? serverList : []
let matches = serverList.filter((elem, i, a) => {
return (elem.url == serverInfo.url
&& elem.username == serverInfo.username
&& elem.password == serverInfo.password)
})
createWebDAVfs.setFetchMethod = function setFetchMethod(fetchFn) {
createWebDAVClient.setFetchMethod(fetchFn);
};