-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: try_find_clients_endpoints #184
base: alpha
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { ClientsMapType, readFile } from '../detect_services'; | ||
|
||
type EndpointType = { id: string; address: string }; | ||
|
||
const buildEndpointsMap = (endpoints: EndpointType[]) => { | ||
return new Map(endpoints.map(({ id, address }) => [id.split('-').join(''), { address, id }])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Какой интересный способ сделать |
||
}; | ||
|
||
const subsequenceLenghth = (target: string, subsequenceStr: string) => { | ||
let maxCount = 0; | ||
|
||
for (let i = 0; i !== target.length; i++) { | ||
if (subsequenceStr[0] === target[i]) { | ||
let count = 0; | ||
for (let j = 0, k = i; j !== subsequenceStr.length && k !== target.length; j++, k++) { | ||
if (subsequenceStr[j] === target[k]) count++; | ||
else break; | ||
} | ||
|
||
if (count > maxCount) maxCount = count; | ||
} | ||
} | ||
|
||
return maxCount; | ||
}; | ||
|
||
const main = async () => { | ||
const resp = await fetch('https://api.cloud.yandex.net/endpoints', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Было бы круто еще endpoint принимать аргументом, чтобы другие инсталляции тыкать можно было. |
||
method: 'get', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
}).then((response) => response.json()); | ||
|
||
const endpointsMap = buildEndpointsMap(resp.endpoints); | ||
|
||
const serviceMap = readFile(); | ||
|
||
Object.keys(serviceMap).forEach((serviceName) => { | ||
let maxCount = 0; | ||
let res: string[] = []; | ||
let resId: string[] = []; | ||
|
||
endpointsMap.forEach(({ address, id }, endpointId) => { | ||
const count = subsequenceLenghth(serviceName.split('/').join(''), endpointId); | ||
|
||
if (count === 0) return; | ||
|
||
if (count > maxCount) { | ||
maxCount = count; | ||
res = [address]; | ||
resId = [id]; | ||
return; | ||
} | ||
|
||
if (count === maxCount) { | ||
res.push(address); | ||
resId.push(id); | ||
} | ||
}); | ||
|
||
console.log(`\n ${serviceName} ${maxCount}`); | ||
console.log(res, resId); | ||
console.log(`\n`); | ||
}); | ||
}; | ||
|
||
if (require.main === module) { | ||
main(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,21 @@ | |
"lib": ["es6"], | ||
"disableSizeLimit": true | ||
}, | ||
"include": ["./src"] | ||
"include": ["./src"], | ||
"ts-node": { | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"allowJs": true, | ||
"declaration": true, | ||
"outDir": "./dist", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"resolveJsonModule": true, | ||
"lib": ["es6", "DOM"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А зачем DOM? |
||
"disableSizeLimit": true | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?