@bagelink/vue 1.14.0 → 1.14.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -210,8 +210,8 @@ export type { ShowdownConverter, ShowdownOptions } from './showdown'
210
210
 
211
211
  const URL_REGEX = /^https?:\/\/|^\/\//
212
212
 
213
- export function pathKeyToURL(pathKey?: string) {
214
- if (pathKey === undefined || pathKey === '' || URL_REGEX.test(pathKey)) {
213
+ export function pathKeyToURL(pathKey?: string | null) {
214
+ if (pathKey == null || pathKey === '' || URL_REGEX.test(pathKey)) {
215
215
  return pathKey
216
216
  }
217
217
 
@@ -1,11 +1,24 @@
1
1
  import axios from 'axios'
2
2
 
3
+ let pendingRequest: Promise<any> | null = null
4
+
3
5
  export async function ipapi() {
4
- let apiData = sessionStorage.getItem('ipapi')
5
- if (!apiData) {
6
- apiData = (await axios.get('https://ipapi.co/json/')).data
7
- apiData = JSON.stringify(apiData)
8
- sessionStorage.setItem('ipapi', apiData)
6
+ const apiData = sessionStorage.getItem('ipapi')
7
+ if (apiData) {
8
+ return JSON.parse(apiData)
9
+ }
10
+
11
+ // Deduplicate concurrent calls — share a single in-flight request
12
+ if (!pendingRequest) {
13
+ pendingRequest = axios.get('https://ipapi.co/json/').then(res => {
14
+ const data = JSON.stringify(res.data)
15
+ sessionStorage.setItem('ipapi', data)
16
+ pendingRequest = null
17
+ return res.data
18
+ }).catch(err => {
19
+ pendingRequest = null
20
+ throw err
21
+ })
9
22
  }
10
- return JSON.parse(apiData)
23
+ return pendingRequest
11
24
  }