| … | … | @@ -14,6 +14,22 @@ if (!await apds.pubkey()) { |
| 14 | 14 | |
| 15 | 15 | const apdsbot = async (ws) => { |
| 16 | 16 | ws.onopen = async () => { |
| 17 | setTimeout(async () => { |
| 18 | const q = await apds.query() |
| 19 | for (const m of q) { |
| 20 | if (m.text) { |
| 21 | const yaml = await apds.parseYaml(m.text) |
| 22 | if (yaml.image) { |
| 23 | const get = await apds.get(yaml.image) |
| 24 | if (!get) { |
| 25 | ws.send(yaml.image) |
| 26 | } |
| 27 | } |
| 28 | //console.log(yaml) |
| 29 | } |
| 30 | } |
| 31 | //console.log(q) |
| 32 | }, 1000) |
| 17 | 33 | console.log('CONNECTED!') |
| 18 | 34 | } |
| 19 | 35 | ws.onmessage = async (m) => { |
| … | … | @@ -27,6 +43,22 @@ const apdsbot = async (ws) => { |
| 27 | 43 | if (m.data.length != 44) { |
| 28 | 44 | await apds.make(m.data) |
| 29 | 45 | await apds.add(m.data) |
| 46 | const opened = await apds.open(m.data) |
| 47 | if (opened) { |
| 48 | const content = await apds.get(opened.substring(13)) |
| 49 | if (!content) { |
| 50 | console.log('no content') |
| 51 | ws.send(opened.substring(13)) |
| 52 | } |
| 53 | } |
| 54 | const yaml = await apds.parseYaml(m.data) |
| 55 | if (yaml.previous) { |
| 56 | const prev = await apds.get(yaml.previous) |
| 57 | if (!prev) { |
| 58 | console.log('no previous') |
| 59 | ws.send(yaml.previous) |
| 60 | } |
| 61 | } |
| 30 | 62 | } |
| 31 | 63 | } |
| 32 | 64 | ws.onclose = () => { |