| 1 | /// <reference path="../pb_data/types.d.ts" /> |
| 2 | |
| 3 | routerAdd("GET", ' |
| 4 | // if (!c.auth) return c.json(401, { message: "Please login and try again" }) |
| 5 | const iata = |
| 6 | const icao = |
| 7 | const searchedDate = |
| 8 | if (!iata || |
| 9 | const date = |
| 10 | date.setUTCHours(0, |
| 11 | const nextDate = |
| 12 | nextDate.setDate( |
| 13 | date.getDate() + |
| 14 | ) |
| 15 | const collection = |
| 16 | /** |
| 17 | * `(call_sign = "${id}" || flight_no = "${id}") && date>="${date |
| 18 | .toISOString() |
| 19 | .replace("T", " ") |
| 20 | .replace(".000Z", "")}" && date <= "${nextDate.toISOString().replace("T", " ").replace(".000Z", "")}"` |
| 21 | */ |
| 22 | const records = |
| 23 | "flight", |
| 24 | `(call_sign = "${iata}" || flight_no = "${ |
| 25 | "-created", |
| 26 | 200, |
| 27 | 0 |
| 28 | ); |
| 29 | if (records.length) |
| 30 | console.log("from db |
| 31 | return c.json |
| 32 | } |
| 33 | const apiKey = |
| 34 | const url = |
| 35 | }?withAircraftImage=true&withLocation=true` |
| 36 | const res = |
| 37 | url, |
| 38 | method: "GET", |
| 39 | headers: { |
| 40 | "X-RapidAPI-Key": apiKey, |
| 41 | "X-RapidAPI-Host": "aerodatabox.p.rapidapi.com", |
| 42 | } |
| 43 | }) |
| 44 | const json = |
| 45 | if (json == |
| 46 | |
| 47 | const record = |
| 48 | record.set("flight_no |
| 49 | record.set("call_sign |
| 50 | record.set("aircraft |
| 51 | record.set("airline |
| 52 | record.set("arrival |
| 53 | record.set("cargo |
| 54 | record.set("greatCircleDistance |
| 55 | record.set("date |
| 56 | record.set("image |
| 57 | if (json.length |
| 58 | record.set("departure |
| 59 | } |
| 60 | else { |
| 61 | record.set("departure |
| 62 | } |
| 63 | $app.save(record |
| 64 | const aircraft = |
| 65 | "aircraft", |
| 66 | `hex_icao = ${json[0] |
| 67 | ) |
| 68 | if(aircraft){ |
| 69 | return |
| 70 | } |
| 71 | return c.json |
| 72 | }) |