forked from kenmingwang/azusa-player
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from lovegaoshi/dev-noxplayer
feat: github sync
- Loading branch information
Showing
7 changed files
with
545 additions
and
117 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
Submodule azusa-player-mobile
updated
9 files
+24 −2 | android/app/src/main/java/com/noxplay/noxplayer/MainActivity.kt | |
+6 −6 | package.json | |
+12 −11 | src/components/background/MainBackground.tsx | |
+11 −132 | src/components/setting/sync/GithubAuth.ts | |
+1 −0 | src/enums/Sync.ts | |
+5 −4 | src/stores/useApp.ts | |
+2 −2 | src/utils/sync/Gitee.ts | |
+93 −0 | src/utils/sync/Github.ts | |
+40 −40 | yarn.lock |
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
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,69 @@ | ||
import { | ||
checkAuthentication, | ||
noxBackup, | ||
noxRestore, | ||
} from '@APM/utils/sync/Github'; | ||
import { logger } from '@utils/Logger'; | ||
import GenericSyncButton, { GenericPropsR } from './GenericSyncButton'; | ||
|
||
let authToken = ''; | ||
const clientId = process.env.GITHUB_KEY; | ||
const clientSecret = process.env.GITHUB_SECRET; | ||
const redirectURI = chrome.identity.getRedirectURL(); | ||
|
||
export const getAuth = async ( | ||
callback = (_v?: string) => checkAuthentication(authToken).then(console.log), | ||
errorHandling = logger.error, | ||
) => | ||
chrome.identity.launchWebAuthFlow( | ||
{ | ||
url: `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectURI}&scope=repo,user,administration:write`, | ||
interactive: true, | ||
}, | ||
async (responseUrl) => { | ||
if (responseUrl === undefined) { | ||
errorHandling('no response url returned. auth aborted by user.'); | ||
} else { | ||
const authCode = new URL(responseUrl).searchParams.get('code'); | ||
const res = await fetch( | ||
`https://github.com/login/oauth/access_token?code=${authCode}&client_id=${clientId}&redirect_uri=${redirectURI}&client_secret=${clientSecret} | ||
`, | ||
{ method: 'POST' }, | ||
); | ||
authToken = new URL( | ||
`https://foo.com/bar?${await res.text()}`, | ||
).searchParams.get('access_token')!; | ||
callback(responseUrl); | ||
} | ||
}, | ||
); | ||
|
||
const login = async ( | ||
callback: () => Promise<void> = async () => undefined, | ||
errorCallback = logger.error, | ||
) => { | ||
try { | ||
if (!(await checkAuthentication())) { | ||
logger.debug('github token expired, need to log in'); | ||
await getAuth(callback, errorCallback); | ||
} else { | ||
callback(); | ||
} | ||
return true; | ||
} catch (e) { | ||
logger.warn('github fail'); | ||
errorCallback(e); | ||
return false; | ||
} | ||
}; | ||
|
||
const GiteeSyncButton = ({ restoreFromUint8Array, sx }: GenericPropsR) => | ||
GenericSyncButton({ | ||
restoreFromUint8Array, | ||
noxBackup: (v) => noxBackup(v, authToken), | ||
noxRestore: () => noxRestore(authToken), | ||
login, | ||
sx, | ||
}); | ||
|
||
export default GiteeSyncButton; |
Oops, something went wrong.