mirror of
https://github.com/pionxzh/chatgpt-exporter.git
synced 2026-07-23 09:00:51 -05:00
fix: adapt remix version and try to reduce call to session api
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import urlcat from 'urlcat'
|
||||
import { apiUrl, baseUrl } from './constants'
|
||||
import { getChatIdFromUrl, getConversationFromSharePage, isSharePage } from './page'
|
||||
import { getChatIdFromUrl, getConversationFromSharePage, getPageAccessToken, isSharePage } from './page'
|
||||
import { blobToDataURL } from './utils/dom'
|
||||
import { memorize } from './utils/memorize'
|
||||
|
||||
@@ -450,6 +450,9 @@ async function _fetchSession(): Promise<ApiSession> {
|
||||
const fetchSession = memorize(_fetchSession)
|
||||
|
||||
async function getAccessToken(): Promise<string> {
|
||||
const pageAccessToken = getPageAccessToken()
|
||||
if (pageAccessToken) return pageAccessToken
|
||||
|
||||
const session = await fetchSession()
|
||||
return session.accessToken
|
||||
}
|
||||
|
||||
34
src/page.ts
34
src/page.ts
@@ -39,6 +39,34 @@ declare global {
|
||||
}
|
||||
}
|
||||
}
|
||||
__remixContext: {
|
||||
basename: string
|
||||
future: {}
|
||||
state: {
|
||||
loaderData: {
|
||||
root: {
|
||||
clientBootstrap: {
|
||||
accountStatus: null
|
||||
session: {
|
||||
accessToken: string
|
||||
authProvider: string
|
||||
expires: string
|
||||
user: {
|
||||
email: string
|
||||
group: unknown[]
|
||||
id: string
|
||||
image: string
|
||||
intercom_hash: string
|
||||
mfa: boolean
|
||||
name: string
|
||||
picture: string
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +74,12 @@ export function getHistoryDisabled(): boolean {
|
||||
return localStorage.getItem(KEY_OAI_HISTORY_DISABLED) === '"true"'
|
||||
}
|
||||
|
||||
export function getPageAccessToken(): string | null {
|
||||
return unsafeWindow?.__remixContext?.state?.loaderData?.root?.clientBootstrap?.session?.accessToken ?? null
|
||||
}
|
||||
|
||||
function getUserProfile() {
|
||||
const user = unsafeWindow?.__NEXT_DATA__?.props?.pageProps?.user
|
||||
const user = unsafeWindow?.__NEXT_DATA__?.props?.pageProps?.user ?? unsafeWindow?.__remixContext?.state?.loaderData?.root?.clientBootstrap?.session?.user
|
||||
if (!user) throw new Error('No user found.')
|
||||
return user
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user