PageSourceSearch

https://www.uradmonitor.com/tools/lib/frontend-07/js/api.js?v=20260430002

js uradmonitor.com collected 2026-09-24 18:57:33 UTC 3,149 bytes, 73 lines download raw bytes

1/* dashboard-10 — api.js
2   Wraps the proxy.php endpoint. Tracks in-flight count so the UI can show
3   a progress indicator. d10OnProgress(fn) registers a listener that gets
4   called with the current count whenever it changes.
5*/
6
7const D10_API = {
8  endpoint: '/tools/lib/security/proxy.php',
9  userid:   'www',
10  userhash: 'a00e0aee1b47f439c7c914418b6cf06b',
11  timeoutMs: 60000,
12};
13
14let _d10InFlight = 0;
15const _d10ProgressListeners = [];
16function d10OnProgress(fn){ _d10ProgressListeners.push(fn); fn(_d10InFlight); }
17function _d10NotifyProgress(){ for (let i=0;i<_d10ProgressListeners.length;i++) _d10ProgressListeners[i](_d10InFlight); }
18function _d10Begin(){ _d10InFlight++; _d10NotifyProgress(); }
19function _d10End(){ _d10InFlight=Math.max(0,_d10InFlight-1); _d10NotifyProgress(); }
20
21function _d10AjaxGet(param) {
22  _d10Begin();
23  return new Promise((resolve, reject) => {
24    $.ajax({
25      url: D10_API.endpoint,
26      type:'GET',
27      dataType:'json',
28      timeout: D10_API.timeoutMs,
29      data: { userid:D10_API.userid, userhash:D10_API.userhash, param: param },
30    })
31    .done(d => resolve(d))
32    .fail((xhr, st, err) => reject(new Error(st + ' ' + err)))
33    .always(() => _d10End());
34  });
35}
36
37/* ── 1. Device summary list ──────────────────────────────────────── */
38function d10FetchSummary() {
39  return _d10AjaxGet('').then(rows => Array.isArray(rows) ? rows : []);
40}
41
42/* ── 2. Sensor catalog for a device ─────────────────────────────── */
43function d10FetchCatalog(deviceId) {
44  return _d10AjaxGet(deviceId).then(obj => obj && typeof obj === 'object' ? obj : {});
45}
46
47/* ── 3. History for a device+sensor between deltaStart..deltaStop ─
48   The proxy expects deltaStart > deltaStop, both seconds *before now*. */
49function d10FetchHistory(deviceId, sensorKey, deltaStart, deltaStop) {
50  if (deltaStart <= deltaStop) deltaStart = deltaStop + 60;
51  return _d10AjaxGet(deviceId + '/' + sensorKey + '/' + deltaStart + '/' + deltaStop)
52    .then(rows => Array.isArray(rows) ? rows : []);
53}
54
55/* ── 4. Snapshot — value of one sensor across an extent at a unix time ─
56   For history slider when zoomed in. lonMin,latMin,lonMax,latMax. */
57function d10FetchSnapshot(extentLonLat, sensorKey, unixSeconds) {
58  const e = extentLonLat
59    .map(v => Math.round(v*1e4)/1e4)
60    .join(',');
61  const param = 'history/' + e + '/' + sensorKey + '/' + Math.floor(unixSeconds);
62  return _d10AjaxGet(param).then(d => Array.isArray(d) ? d : []);
63}
64
65/* ── 5. Daily averages (for temporal heatmap calendar) ─────────────
66   Returns array of {time, pm25, co2, gas1, ...} — one entry per day.
67   param = DEVICEID/average/deltaStart/deltaStop                     */
68function d10FetchDailyAverages(deviceId, deltaDays, deltaSeconds) {
69  deltaDays = deltaDays || 30;
70  const deltaStart = deltaSeconds || Math.min(deltaDays * 86400, 10368000);
71  return _d10AjaxGet(deviceId + '/average/' + deltaStart + '/0')
72    .then(rows => Array.isArray(rows) ? rows : []);
73}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.