Skip to content

Commit

Permalink
Account for different API versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Stricker committed Dec 26, 2023
1 parent 92721b2 commit 956e7fe
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ When the adapter crashes or another Code error happens, this error message that
<a name="Revision-History"></a>

## Changelog
### **WORK IN PROGRESS**
- Account for different API versions

### 0.1.5 (2023-12-10)
- minor bug fixes

Expand Down
44 changes: 38 additions & 6 deletions lib/web_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,30 @@ class SrmClient {
*
* @return {Promise<Object[]>} Devices
*/
async getAllDevices () {
async getAllDevices (api_version = 4) {
const data = {
method: 'get',
version: 4,
version: api_version,
conntype: 'all',
api: 'SYNO.Core.Network.NSM.Device',
};
return (await this.request('/webapi/entry.cgi', data)).devices;
try{
const nodes = (await this.request('/webapi/entry.cgi', data)).devices;
return nodes;
} catch (error) {
if (error.message === 'This API version is not supported') {
if (api_version > 1){
this.getAllDevices(api_version - 1);
}
else{
throw new Error('This API version is not supported');
}
}
else{
throw new Error(error.message);
}
}
return [];
}

/**
Expand All @@ -249,13 +265,29 @@ class SrmClient {
*
* @return {Promise<Object[]>} Mesh nodes
*/
async getMeshNodes () {
async getMeshNodes (api_version = 4) {
const data = {
method: 'get',
version: 4,
version: api_version,
api: 'SYNO.Mesh.Node.List',
};
return (await this.request('/webapi/entry.cgi', data)).nodes;
try{
const nodes = (await this.request('/webapi/entry.cgi', data)).nodes;
return nodes;
} catch (error) {
if (error.message === 'This API version is not supported') {
if (api_version > 1){
this.getMeshNodes(api_version - 1);
}
else{
throw new Error('This API version is not supported');
}
}
else{
throw new Error(error.message);
}
}
return [];
}

/**
Expand Down

0 comments on commit 956e7fe

Please sign in to comment.