-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: "microsoft" web page translating source might request authorizat…
…ion for multiple times
- Loading branch information
1 parent
a8244b4
commit 8ede34b
Showing
3 changed files
with
45 additions
and
30 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
15 changes: 13 additions & 2 deletions
15
src/public/web-page-translate/microsoft/getAuthorization.ts
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 |
---|---|---|
@@ -1,8 +1,19 @@ | ||
import { fetchData } from '../../translate/utils'; | ||
|
||
export const getAuthorization = async () => { | ||
let authorization = ''; | ||
let expiry = 0; | ||
|
||
export const getAuthorization = async (force = false) => { | ||
const timestamp = Number(new Date()); | ||
|
||
if (!force && expiry > timestamp && authorization) { return authorization; } | ||
|
||
const url = 'https://edge.microsoft.com/translate/auth'; | ||
|
||
const res = await fetchData(url); | ||
const authorization = await res.text(); | ||
|
||
authorization = await res.text(); | ||
expiry = timestamp + 500000; | ||
|
||
return authorization; | ||
}; |
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