Skip to content

Commit

Permalink
Improve Vercel Edge Config performance
Browse files Browse the repository at this point in the history
  • Loading branch information
starscouts committed Aug 11, 2024
1 parent 5f7b5c2 commit f8b6950
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wishing-star"
version = "2.2.2"
version = "2.2.3"
edition = "2021"

[dependencies]
Expand Down
13 changes: 7 additions & 6 deletions app/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ module.exports = {
},
GET: async (request) => {
let url = new URL(request.url);
let config = await get("wishing-star");

if (url.searchParams.has("code")) {
console.log("Got authentication callback code from server");
let res = await fetch("https://account.equestria.dev/hub/api/rest/oauth2/token", {
method: "POST",
headers: {
'Authorization': "Basic " + btoa(await get("id") + ":" + await get("secret")),
'Authorization': "Basic " + btoa(config['id'] + ":" + config['secret']),
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
},
body: "grant_type=authorization_code&redirect_uri=" + encodeURIComponent(await get("redirect")) + "&code=" + url.searchParams.get("code")
body: "grant_type=authorization_code&redirect_uri=" + encodeURIComponent(config['redirect']) + "&code=" + url.searchParams.get("code")
});
let data = await res.json();

Expand All @@ -43,7 +44,7 @@ module.exports = {
}
});
let userData = await res.json();
let allowed = await get("allowed");
let allowed = config['allowed'];

if (!allowed.includes(userData['id'])) {
console.log("User is not allowed: " + userData['id']);
Expand All @@ -64,7 +65,7 @@ module.exports = {
status: 307,
headers: {
Location: "/",
'Set-Cookie': "wishing_token=" + token + "; Path=/; HttpOnly; Expires=" + new Date(new Date().getTime() + (86400 * 730000))
'Set-Cookie': "wishlist_token=" + token + "; Path=/; HttpOnly; Expires=" + new Date(new Date().getTime() + (86400 * 730000))
}
});
}
Expand All @@ -73,7 +74,7 @@ module.exports = {
if (request.headers.has("Cookie")) {
console.log("Found cookies");
let cookie = request.headers.get("Cookie");
let token = getCookie("wishing_token", cookie);
let token = getCookie("wishlist_token", cookie);

if (token.trim() !== "") {
console.log("Found session token");
Expand All @@ -99,7 +100,7 @@ module.exports = {
return new Response(null, {
status: 307,
headers: {
Location: "https://account.equestria.dev/hub/api/rest/oauth2/auth?client_id=" + await get("id") + "&response_type=code&redirect_uri=" + encodeURIComponent(await get("redirect")) + "&scope=Hub&request_credentials=default&access_type=offline"
Location: "https://account.equestria.dev/hub/api/rest/oauth2/auth?client_id=" + config['id'] + "&response_type=code&redirect_uri=" + encodeURIComponent(config['redirect']) + "&scope=Hub&request_credentials=default&access_type=offline"
}
});
}
Expand Down

0 comments on commit f8b6950

Please sign in to comment.