-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09fd513
commit 4195445
Showing
5 changed files
with
90 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,21 @@ | |
"lock": false, | ||
"tasks": { | ||
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx", | ||
"start": "deno run -A --watch=static/,routes/ dev.ts", | ||
"start": "deno run -A --watch=static/,routes/ --unstable dev.ts", | ||
"build": "deno run -A dev.ts build", | ||
"preview": "deno run -A main.ts", | ||
"update": "deno run -A -r https://fresh.deno.dev/update ." | ||
}, | ||
"lint": { | ||
"rules": { | ||
"tags": [ | ||
"recommended" | ||
], | ||
"exclude": ["prefer-const"] | ||
}, | ||
"exclude": [ | ||
"_fresh" | ||
] | ||
"rules": { "tags": ["recommended", "fresh"], "exclude": ["prefer-const"] } | ||
}, | ||
"imports": { | ||
"$fresh/": "https://deno.land/x/fresh@1.4.3/", | ||
"preact": "https://esm.sh/preact@10.15.1", | ||
"preact/": "https://esm.sh/preact@10.15.1/", | ||
"preact-render-to-string": "https://esm.sh/*[email protected].1", | ||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3", | ||
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.2.3", | ||
"$fresh/": "https://deno.land/x/fresh@1.5.4/", | ||
"preact": "https://esm.sh/preact@10.18.1", | ||
"preact/": "https://esm.sh/preact@10.18.1/", | ||
"preact-render-to-string": "https://esm.sh/*[email protected].2", | ||
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.1", | ||
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.0", | ||
"twind": "https://esm.sh/[email protected]", | ||
"twind/": "https://esm.sh/[email protected]/", | ||
"$std/": "https://deno.land/[email protected]/", | ||
|
@@ -38,15 +30,10 @@ | |
"utils/": "./utils/", | ||
"api": "./utils/api.js", | ||
"islands/": "./islands/", | ||
"juani/": "https://esm.sh/gh/juanidambrosio/smileshelper/" | ||
"juani/": "https://esm.sh/gh/juanidambrosio/smileshelper/", | ||
"cachified": "https://esm.sh/[email protected]", | ||
"@libsql/client": "https://esm.sh/@libsql/[email protected]" | ||
}, | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "preact" | ||
}, | ||
"fmt": { | ||
"exclude": [ | ||
"_fresh" | ||
] | ||
} | ||
"compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" }, | ||
"exclude": ["**/_fresh/*"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { cachified, verboseReporter } from 'cachified'; | ||
import makeCache from 'utils/cache.js'; | ||
|
||
const client = Deno.createHttpClient({ | ||
proxy: { | ||
basicAuth: {username: Deno.env.get('PROXY_USER'), password: Deno.env.get('PROXY_PW')}, | ||
url: `socks5h://pr.oxylabs.io:7777` } | ||
}); | ||
|
||
const headers = { | ||
authorization: | ||
"Bearer Ghlpz2Fv1P5k9zGSUz2Z3l5jdVmy0aNECen0CV5v1sevBwTX9cA9kc", | ||
"x-api-key": "aJqPU7xNHl9qN3NVZnPaJ208aPo2Bh2p2ZV844tw", | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
region: "ARGENTINA", | ||
}; | ||
|
||
function searchCached(params) { | ||
return cachified({ | ||
reporter: verboseReporter(), | ||
key: `${params.get('originAirportCode')}:${params.get('destinationAirportCode')}:${params.get('departureDate')}`, | ||
cache: makeCache('smiles'), | ||
getFreshValue() { | ||
return fetch('https://api-air-flightsearch-prd.smiles.com.br/v1/airlines/search?' + params.toString(), { | ||
client, | ||
headers | ||
}).then(res => res.json()); | ||
}, | ||
// good for 12 hours | ||
ttl: 1000 * 60 * 60 * 12, | ||
// one year | ||
swr: 1000 * 60 * 60 * 24 * 365 | ||
}); | ||
} | ||
|
||
export async function handler(req) { | ||
const url = new URL(req.url); | ||
const value = await searchCached(url.searchParams); | ||
return new Response(JSON.stringify(value), { | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createClient } from '@libsql/client'; | ||
|
||
const client = createClient({ | ||
url: Deno.env.get('DB_URL'), | ||
authToken: Deno.env.get('DB_AUTH_TOKEN') | ||
}); | ||
|
||
export default function makeCache(prefix) { | ||
return { | ||
async set(key, value) { | ||
await client.execute({ | ||
sql: "insert into cache values (:key, :value)", | ||
args: { key: prefix + ':' + key, value: JSON.stringify(value) } | ||
}); | ||
}, | ||
async get(key) { | ||
const { rows: [cacheRow]} = await client.execute({ | ||
sql: 'select value from cache where key = :key', | ||
args: { key: prefix + ':' + key } | ||
}); | ||
if (!cacheRow) return null; | ||
return JSON.parse(cacheRow.value) | ||
}, | ||
async delete(key) { | ||
await client.execute({ | ||
sql: 'delete from cache where key = :key', | ||
args: { key: prefix + ':' + key } | ||
}); | ||
} | ||
}; | ||
} |
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