Skip to content

Commit

Permalink
feat: check authorize was expired or not when refresh info (#6)
Browse files Browse the repository at this point in the history
enpitsuLin authored Apr 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 3204d38 commit 70c7665
Showing 4 changed files with 62 additions and 6 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/submit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release

on:
workflow_dispatch:

jobs:
submit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v3
with:
version: latest

- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm

- name: Install dependencies
run: pnpm install

- name: Zip extensions
run: |
pnpm zip
- name: Submit to stores
run: |
pnpm wxt submit \
--chrome-zip .output/*-chrome.zip
env:
CHROME_EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }}
CHROME_CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }}
CHROME_CLIENT_SECRET: ${{ secrets.CHROME_CLIENT_SECRET }}
CHROME_REFRESH_TOKEN: ${{ secrets.CHROME_REFRESH_TOKEN }}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@
"name": "rhodes-headquarters",
"displayName": "罗德岛远程指挥部",
"type": "module",
"version": "0.1.0-beta.1",
"publishVersion": "0.1.0.1",
"version": "0.1.0-beta.2",
"publishVersion": "0.1.0.2",
"private": true,
"packageManager": "[email protected]",
"description": "一款用于监控罗德岛运行状态的浏览器扩展",
@@ -33,6 +33,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"date-fns": "^3.6.0",
"https-proxy-agent": "^7.0.4",
"idb-keyval": "^6.2.1",
"js-md5": "^0.8.3",
"ofetch": "^1.3.4",
5 changes: 3 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -28,6 +28,13 @@ async function grantAuthorizeCode({
accounts.push(newAccount)
}

async function checkAccount({ accountMapping, account }: { accountMapping: Record<string, Authorize>, account: Account }) {
const credData = accountMapping[account.id]
if (!credData)
throw new Error(`unexpected error: ID ${account.id} has no its credData`)
return API.skland.checkAccessToken(credData)
}

async function refreshAccount({ accountMapping, account, token }: { token: string, accountMapping: Record<string, Authorize>, account: Account }) {
const credData = accountMapping[account.id]
if (!credData)
@@ -72,11 +79,21 @@ export async function logInOrRefreshAccount(token: string) {
}

export async function refreshCharacterInfo() {
const accounts = await accountsStorage.getValue()
const uid = await currentChararcterUidStorage.getValue()
const currentAccount = await currentAccountStorage.getValue()
const currentAccountId = await currentAccountStorage.getValue()
const account = accounts.find(account => account.id === currentAccountId)
if (!account)
throw new Error(`Unexpected Error: account with id [${currentAccountId}] not found`)
const accountMapping = await authorizeMappingStorage.getValue()

const authorizeData = accountMapping[currentAccount]
const valid = await checkAccount({ accountMapping, account })
if (!valid) {
const authorizeCode = await API.hypergrayph.grantAuthorizeCode(account.token)
const { userId, ...credData } = await API.skland.generateCredByCode(authorizeCode)
accountMapping[userId] = credData
}
const authorizeData = accountMapping[currentAccountId]
const info = await API.skland.getBindingInfo({ ...authorizeData, uid })
chararcterStorage.setValue(info)
}

0 comments on commit 70c7665

Please sign in to comment.