-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: linting and do not run lint during npm publish
- Loading branch information
Showing
8 changed files
with
379 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
|
||
function addLine(map, id, point1, point2, color) { | ||
map.addSource(id, { | ||
'type': 'geojson', | ||
'data': { | ||
'type': 'Feature', | ||
'properties': {}, | ||
'geometry': { | ||
'type': 'LineString', | ||
'coordinates': [ | ||
point1, | ||
point2 | ||
] | ||
} | ||
} | ||
}); | ||
map.addLayer({ | ||
'id': id, | ||
'type': 'line', | ||
'source': id, | ||
'layout': { | ||
'line-join': 'round', | ||
'line-cap': 'round' | ||
}, | ||
'paint': { | ||
'line-color': color, | ||
'line-width': 4, | ||
'line-offset': 4 | ||
} | ||
}); | ||
function addLine (map, id, point1, point2, color) { | ||
map.addSource(id, { | ||
type: 'geojson', | ||
data: { | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: [ | ||
point1, | ||
point2 | ||
] | ||
} | ||
} | ||
}) | ||
map.addLayer({ | ||
id: id, | ||
type: 'line', | ||
source: id, | ||
layout: { | ||
'line-join': 'round', | ||
'line-cap': 'round' | ||
}, | ||
paint: { | ||
'line-color': color, | ||
'line-width': 4, | ||
'line-offset': 4 | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,68 @@ | ||
const UNAUTH_SESSION_ID = '00000000000000000000000000000000'; | ||
const DEFAULT_SESSION_TIMEOUT = 5000; | ||
const UNAUTH_SESSION_ID = '00000000000000000000000000000000' | ||
const DEFAULT_SESSION_TIMEOUT = 5000 | ||
|
||
const parseResult = result => | ||
new Promise((res, rej) => { | ||
if (result.error) { return rej(result.error); } | ||
if (result.result[0] !== 0) { return rej(result); } | ||
result = result.result[1]; | ||
if (result && result.status === 'error') { | ||
return rej(result.message); | ||
} | ||
return res(result); | ||
}) | ||
new Promise((res, rej) => { | ||
if (result.error) { return rej(result.error) } | ||
if (result.result[0] !== 0) { return rej(result) } | ||
result = result.result[1] | ||
if (result && result.status === 'error') { | ||
return rej(result.message) | ||
} | ||
return res(result) | ||
}) | ||
|
||
class UhttpdService { | ||
constructor() { | ||
const origin = window.origin | ||
const defaultHost = `http://thisnode.info` | ||
this.url = `${defaultHost}/ubus`; | ||
this.jsonrpc = '2.0'; | ||
this.sec = 0; | ||
this.requestList = []; | ||
} | ||
constructor () { | ||
const origin = window.origin | ||
const defaultHost = 'http://thisnode.info' | ||
this.url = `${defaultHost}/ubus` | ||
this.jsonrpc = '2.0' | ||
this.sec = 0 | ||
this.requestList = [] | ||
} | ||
|
||
sid() { | ||
const sid = sessionStorage.getItem('sid'); | ||
return sid || UNAUTH_SESSION_ID; | ||
} | ||
sid () { | ||
const sid = sessionStorage.getItem('sid') | ||
return sid || UNAUTH_SESSION_ID | ||
} | ||
|
||
addId() { | ||
this.sec += 1; | ||
return Number(this.sec); | ||
} | ||
addId () { | ||
this.sec += 1 | ||
return Number(this.sec) | ||
} | ||
|
||
async call (action, method, data, hostname, customSid = null, timeout = null) { | ||
const url = hostname ? `http://${hostname}/ubus` : this.url // Must be dynamic to pull from other nodes | ||
this.sec += 1 | ||
const body = { | ||
id: this.addId(), | ||
jsonrpc: this.jsonrpc, | ||
method: 'call', | ||
params: [customSid || this.sid(), action, method, data] | ||
} | ||
const controller = new AbortController() | ||
const id = setTimeout(() => controller.abort(), timeout || 15000) | ||
return fetch(url, | ||
{ method: 'POST', body: JSON.stringify(body), signal: controller.signal }) | ||
.then(response => response.json()) | ||
.then(parseResult) | ||
.finally(clearTimeout(id)) | ||
} | ||
|
||
async call(action, method, data, hostname, customSid = null, timeout = null) { | ||
const url = hostname ? `http://${hostname}/ubus` : this.url // Must be dynamic to pull from other nodes | ||
this.sec +=1; | ||
const body = { | ||
id: this.addId(), | ||
jsonrpc: this.jsonrpc, | ||
method: 'call', | ||
params: [customSid || this.sid(), action, method, data] | ||
}; | ||
const controller = new AbortController(); | ||
const id = setTimeout(() => controller.abort(), timeout || 15000); | ||
return fetch(url, | ||
{ method: 'POST', body: JSON.stringify(body), signal: controller.signal }) | ||
.then(response => response.json()) | ||
.then(parseResult) | ||
.finally(clearTimeout(id)); | ||
} | ||
|
||
login(username, password, hostname) { | ||
const data = { username, password, timeout: DEFAULT_SESSION_TIMEOUT }; | ||
return this.call('session', 'login', data, hostname, UNAUTH_SESSION_ID) | ||
.then(response => | ||
new Promise((res, rej) => { | ||
if (response.ubus_rpc_session) { | ||
sessionStorage.setItem('sid', response.ubus_rpc_session); | ||
res(response); | ||
} | ||
else { | ||
rej(response); | ||
} | ||
})); | ||
} | ||
login (username, password, hostname) { | ||
const data = { username, password, timeout: DEFAULT_SESSION_TIMEOUT } | ||
return this.call('session', 'login', data, hostname, UNAUTH_SESSION_ID) | ||
.then(response => | ||
new Promise((res, rej) => { | ||
if (response.ubus_rpc_session) { | ||
sessionStorage.setItem('sid', response.ubus_rpc_session) | ||
res(response) | ||
} else { | ||
rej(response) | ||
} | ||
})) | ||
} | ||
} | ||
|
||
const api = new UhttpdService(); | ||
const api = new UhttpdService() |
Oops, something went wrong.