Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Import Modal #1008

Merged
merged 26 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e98c860
Merge branch 'jwrigh/1699/aps-refresh-token' into jwrigh/1732/upgrade…
PepperLola Jul 1, 2024
e3e4b9f
show cached robots and fields in import mira modal
PepperLola Jul 1, 2024
4704878
show default models from assetpack and delete button for cache
PepperLola Jul 1, 2024
7f656d5
add sign-in button and don't try requests when not signed in
PepperLola Jul 1, 2024
a3c0706
temporarily removed hub warning -> error
PepperLola Jul 2, 2024
50ce2b4
automatically fetch all mira files from all projects in all hubs
PepperLola Jul 9, 2024
c78b1bb
Merge remote-tracking branch 'origin/dev' into jwrigh/1732/upgrade-im…
PepperLola Jul 9, 2024
7328314
fix cached asset display
PepperLola Jul 9, 2024
e4af6bb
also try cache key as cached asset name if name prop undefined
PepperLola Jul 9, 2024
fcb0730
Merge remote-tracking branch 'origin/dev' into jwrigh/1732/upgrade-im…
PepperLola Jul 9, 2024
207b9c7
fixed getAuth callback error in ImportMirabufModal
PepperLola Jul 9, 2024
930ceb2
Merge remote-tracking branch 'origin/dev' into jwrigh/1732/upgrade-im…
PepperLola Jul 9, 2024
17d8e9f
Merge remote-tracking branch 'origin/dev' into jwrigh/1732/upgrade-im…
PepperLola Jul 9, 2024
46700e7
implemented dhruv's suggestions and formatted
PepperLola Jul 10, 2024
2e2531e
memoize and add loading vs 0 assets
PepperLola Jul 10, 2024
2a7ea0e
load cached and remote assets in modal (not aps yet)
PepperLola Jul 11, 2024
183a750
So many changes. Still a number of bugs
HunterBarclay Jul 12, 2024
1b48c0a
Finally done I think
HunterBarclay Jul 12, 2024
acdc4db
Merge branch 'dev' into jwrigh/1732/upgrade-import-modal
HunterBarclay Jul 12, 2024
5b447bc
Formatted
HunterBarclay Jul 12, 2024
7bafc68
Ran prettier
Dhruv-0-Arora Jul 12, 2024
b7a8359
Fixed linting error from unnecessary semicolon
Dhruv-0-Arora Jul 12, 2024
b8a9498
Moved import panel to replace spawn modal
HunterBarclay Jul 12, 2024
8dbb8ad
Formatted again
HunterBarclay Jul 12, 2024
30b90d1
Formatted yet again
HunterBarclay Jul 12, 2024
73a3356
Reverted back keys to modals and panels
HunterBarclay Jul 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions fission/.env

This file was deleted.

Binary file removed fission/bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ import DriverStationPanel from "@/panels/simulation/DriverStationPanel"
import ManageAssembliesModal from "@/modals/spawning/ManageAssembliesModal.tsx"
import World from "@/systems/World.ts"
import { AddRobotsModal, AddFieldsModal, SpawningModal } from "@/modals/spawning/SpawningModals.tsx"
import ImportMirabufModal from "@/modals/mirabuf/ImportMirabufModal.tsx"
import ImportLocalMirabufModal from "@/modals/mirabuf/ImportLocalMirabufModal.tsx"
import APS from "./aps/APS.ts"
import ImportMirabufPanel from "@/ui/panels/mirabuf/ImportMirabufPanel.tsx"
import Skybox from "./ui/components/Skybox.tsx"
import PokerPanel from "@/panels/PokerPanel.tsx"

Expand Down Expand Up @@ -209,7 +209,6 @@ const initialModals = [
<MatchModeModal key="match-mode" modalId="match-mode" />,
<ConfigMotorModal key="config-motor" modalId="config-motor" />,
<ManageAssembliesModal key="manage-assemblies" modalId="manage-assemblies" />,
<ImportMirabufModal key="import-mirabuf" modalId="import-mirabuf" />,
<ImportLocalMirabufModal key="import-local-mirabuf" modalId="import-local-mirabuf" />,
]

Expand All @@ -222,6 +221,7 @@ const initialPanels: ReactElement[] = [
<ConfigureShotTrajectoryPanel key="config-shot-trajectory" panelId="config-shot-trajectory" />,
<ScoringZonesPanel key="scoring-zones" panelId="scoring-zones" />,
<ZoneConfigPanel key="zone-config" panelId="zone-config" />,
<ImportMirabufPanel key="import-mirabuf" panelId="import-mirabuf" />,
<PokerPanel key="poker" panelId="poker" />,
]

Expand Down
49 changes: 34 additions & 15 deletions fission/src/aps/APS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ export const APS_USER_INFO_UPDATE_EVENT = "aps_user_info_update"

const CLIENT_ID = "GCxaewcLjsYlK8ud7Ka9AKf9dPwMR3e4GlybyfhAK2zvl3tU"

const ENDPOINT_SYNTHESIS_CODE = `${import.meta.env.VITE_SYNTHESIS_SERVER_PATH}api/aps/code`
export const ENDPOINT_SYNTHESIS_CHALLENGE = `${import.meta.env.VITE_SYNTHESIS_SERVER_PATH}api/aps/challenge`
const ENDPOINT_SYNTHESIS_CODE = `/api/aps/code`
export const ENDPOINT_SYNTHESIS_CHALLENGE = `/api/aps/challenge`

const ENDPOINT_AUTODESK_AUTHENTICATION_AUTHORIZE = "https://developer.api.autodesk.com/authentication/v2/authorize"
const ENDPOINT_AUTODESK_AUTHENTICATION_TOKEN = "https://developer.api.autodesk.com/authentication/v2/token"
const ENDPOINT_AUTODESK_USERINFO = "https://api.userprofile.autodesk.com/userinfo"

interface APSAuth {
export interface APSAuth {
access_token: string
refresh_token: string
expires_in: number
expires_at: number
token_type: number
}

interface APSUserInfo {
export interface APSUserInfo {
name: string
picture: string
givenName: string
Expand Down Expand Up @@ -73,7 +73,14 @@ class APS {
* Returns the auth data of the current user. See {@link APSAuth}
* @returns {(APSAuth | undefined)} Auth data of the current user
*/
static getAuth(): APSAuth | undefined {
static async getAuth(): Promise<APSAuth | undefined> {
const auth = this.auth
if (!auth) return undefined

if (Date.now() > auth.expires_at) {
console.debug("Expired. Refreshing...")
await this.refreshAuthToken(auth.refresh_token, false)
}
return this.auth
}

Expand All @@ -83,10 +90,13 @@ class APS {
*/
static async getAuthOrLogin(): Promise<APSAuth | undefined> {
const auth = this.auth
if (!auth) return undefined
if (!auth) {
this.requestAuthCode()
return undefined
}

if (Date.now() > auth.expires_at) {
await this.refreshAuthToken(auth.refresh_token)
await this.refreshAuthToken(auth.refresh_token, true)
}
return this.auth
}
Expand Down Expand Up @@ -158,9 +168,12 @@ class APS {
/**
* Refreshes the access token using our refresh token.
* @param {string} refresh_token - The refresh token from our auth data
*
* @returns If the promise returns true, that means the auth token is currently available. If not, it means it
* is not readily available, although one may be in the works
*/
static async refreshAuthToken(refresh_token: string) {
await this.requestMutex.runExclusive(async () => {
static async refreshAuthToken(refresh_token: string, shouldRelog: boolean): Promise<boolean> {
return this.requestMutex.runExclusive(async () => {
try {
const res = await fetch(ENDPOINT_AUTODESK_AUTHENTICATION_TOKEN, {
method: "POST",
Expand All @@ -176,23 +189,29 @@ class APS {
})
const json = await res.json()
if (!res.ok) {
MainHUD_AddToast("error", "Error signing in.", json.userMessage)
this.auth = undefined
await this.requestAuthCode()
return
if (shouldRelog) {
MainHUD_AddToast("warning", "Must Re-signin.", json.userMessage)
this.auth = undefined
await this.requestAuthCode()
return false
} else {
return false
}
}
json.expires_at = json.expires_in + Date.now()
json.expires_at = json.expires_in * 1000 + Date.now()
this.auth = json as APSAuth
if (this.auth) {
await this.loadUserInfo(this.auth)
if (APS.userInfo) {
MainHUD_AddToast("info", "ADSK Login", `Hello, ${APS.userInfo.givenName}`)
}
}
return true
} catch (e) {
MainHUD_AddToast("error", "Error signing in.", "Please try again.")
this.auth = undefined
await this.requestAuthCode()
return false
}
})
}
Expand All @@ -212,7 +231,7 @@ class APS {
return
}
const auth_res = json.response as APSAuth
auth_res.expires_at = auth_res.expires_in + Date.now()
auth_res.expires_at = auth_res.expires_in * 1000 + Date.now()
this.auth = auth_res
console.log("Preloading user info")
const auth = await this.getAuth()
Expand Down
Loading
Loading