@jetthai/cuora 1.0.7 → 1.0.9
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.
- package/CHANGELOG.md +4 -0
- package/README.md +11 -0
- package/index.js +1 -1
- package/package.json +1 -1
- package/plugin/activity.js +5 -5
- package/plugin/core.js +22 -19
- package/plugin/game.js +17 -17
- package/plugin/inbox.js +3 -3
- package/plugin/job/network.js +5 -5
- package/plugin/payment.js +13 -13
- package/plugin/request.js +107 -107
- package/plugin/search.js +7 -7
- package/plugin/user.js +15 -15
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.0.9](https://github.com/jetthai/cuora-module/compare/v1.0.8...v1.0.9) (2021-08-11)
|
|
6
|
+
|
|
7
|
+
### [1.0.8](https://github.com/jetthai/cuora-module/compare/v1.0.7...v1.0.8) (2021-08-10)
|
|
8
|
+
|
|
5
9
|
### [1.0.7](https://github.com/jetthai/cuora-module/compare/v1.0.6...v1.0.7) (2021-08-10)
|
|
6
10
|
|
|
7
11
|
### [1.0.6](https://github.com/jetthai/cuora-module/compare/v1.0.5...v1.0.6) (2021-08-09)
|
package/README.md
ADDED
package/index.js
CHANGED
package/package.json
CHANGED
package/plugin/activity.js
CHANGED
|
@@ -212,7 +212,7 @@ function createStore({$request}) {
|
|
|
212
212
|
actions: {
|
|
213
213
|
async getActivityTypes({ commit }) {
|
|
214
214
|
try {
|
|
215
|
-
const types = await $request(api.getActivityTypes({ appSecret: clientSecret }))
|
|
215
|
+
const types = await $request.send(api.getActivityTypes({ appSecret: clientSecret }))
|
|
216
216
|
commit(`setActivities`, { types: types?.data || {} })
|
|
217
217
|
} catch (err) {
|
|
218
218
|
console.log(err)
|
|
@@ -220,7 +220,7 @@ function createStore({$request}) {
|
|
|
220
220
|
},
|
|
221
221
|
async getActivityList({ commit, getters, dispatch }) {
|
|
222
222
|
try {
|
|
223
|
-
const activities = await $request(api.getActivityList({ appSecret: clientSecret, include: 'cl' }))
|
|
223
|
+
const activities = await $request.send(api.getActivityList({ appSecret: clientSecret, include: 'cl' }))
|
|
224
224
|
commit(`setActivities`, { list: activities?.data || {} })
|
|
225
225
|
const activitiesById = {}
|
|
226
226
|
activities.data.forEach((val, index) => {
|
|
@@ -239,7 +239,7 @@ function createStore({$request}) {
|
|
|
239
239
|
}
|
|
240
240
|
},
|
|
241
241
|
async getActivityDetail({ commit }, activityNo) {
|
|
242
|
-
const { data } = await $request(api.getActivityDetail({ activityNo, appSecret: clientSecret }))
|
|
242
|
+
const { data } = await $request.send(api.getActivityDetail({ activityNo, appSecret: clientSecret }))
|
|
243
243
|
commit(`setSingleActivities`, { key: activityNo, data })
|
|
244
244
|
return data
|
|
245
245
|
},
|
|
@@ -253,7 +253,7 @@ function createStore({$request}) {
|
|
|
253
253
|
async fetchAchievements({ rootGetters, commit }, pageIdx = 0) {
|
|
254
254
|
try {
|
|
255
255
|
if (rootGetters[`core/isAuthorized`] && !rootGetters['user/isInline']) {
|
|
256
|
-
const achievements = await $request(
|
|
256
|
+
const achievements = await $request.send(
|
|
257
257
|
api.getAchievements({
|
|
258
258
|
limit: 10,
|
|
259
259
|
page: pageIdx,
|
|
@@ -267,7 +267,7 @@ function createStore({$request}) {
|
|
|
267
267
|
}
|
|
268
268
|
},
|
|
269
269
|
async getAchievementDetail({}, achievementNo) {
|
|
270
|
-
const { data } = await $request(api.getAchievementsProgress({ achievementNo, appSecret: clientSecret }))
|
|
270
|
+
const { data } = await $request.send(api.getAchievementsProgress({ achievementNo, appSecret: clientSecret }))
|
|
271
271
|
return data
|
|
272
272
|
},
|
|
273
273
|
},
|
package/plugin/core.js
CHANGED
|
@@ -15,7 +15,7 @@ const api = {
|
|
|
15
15
|
feeds: () => ({ url: 'feeds', method: 'get', params: { appSecret: clientSecret }, public: true }),
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function createStore({ $request
|
|
18
|
+
function createStore({ $request }) {
|
|
19
19
|
return {
|
|
20
20
|
namespaced: true,
|
|
21
21
|
state: () => ({
|
|
@@ -329,10 +329,10 @@ function createStore({ $request, $ignoreErrorRequest, $loadingRequest, $updateSo
|
|
|
329
329
|
},
|
|
330
330
|
async login({ state, commit, getters, rootGetters, dispatch }, data) {
|
|
331
331
|
try {
|
|
332
|
-
const loginResult = await $
|
|
332
|
+
const loginResult = await $request.sendWithLoading(api.login(data))
|
|
333
333
|
const token = loginResult.token
|
|
334
|
-
$cookie.setToken(token)
|
|
335
|
-
$cookie.setUser(data.username)
|
|
334
|
+
$request.cookie.setToken(token)
|
|
335
|
+
$request.cookie.setUser(data.username)
|
|
336
336
|
await dispatch('checkAuth')
|
|
337
337
|
return loginResult
|
|
338
338
|
} catch (err) {
|
|
@@ -341,10 +341,13 @@ function createStore({ $request, $ignoreErrorRequest, $loadingRequest, $updateSo
|
|
|
341
341
|
throw err
|
|
342
342
|
}
|
|
343
343
|
},
|
|
344
|
-
async checkAuth({ state, commit, getters, dispatch }) {
|
|
344
|
+
async checkAuth({ state, commit, getters, dispatch }, token) {
|
|
345
345
|
try {
|
|
346
346
|
commit('setLoading', true)
|
|
347
|
-
|
|
347
|
+
if (token) {
|
|
348
|
+
$request.cookie.setToken(token)
|
|
349
|
+
}
|
|
350
|
+
// if ($request.cookie.getToken()) {
|
|
348
351
|
await dispatch('fetchUserInfo')
|
|
349
352
|
commit('setAuthorized', true)
|
|
350
353
|
dispatch('game/examineGame', null, { root: true })
|
|
@@ -364,7 +367,7 @@ function createStore({ $request, $ignoreErrorRequest, $loadingRequest, $updateSo
|
|
|
364
367
|
async fetchUserInfo({ state, commit, getters, dispatch, rootGetters }) {
|
|
365
368
|
try {
|
|
366
369
|
await dispatch('user/getUserInfo', null, { root: true })
|
|
367
|
-
$cookie.prolongToken()
|
|
370
|
+
$request.cookie.prolongToken()
|
|
368
371
|
dispatch(`checkVerification`)
|
|
369
372
|
// todo test inline
|
|
370
373
|
if (rootGetters['user/userInfo']?.rank < 10) {
|
|
@@ -390,10 +393,10 @@ function createStore({ $request, $ignoreErrorRequest, $loadingRequest, $updateSo
|
|
|
390
393
|
clearInterval(state.keepFreshTimer)
|
|
391
394
|
clearInterval(rootGetters['game/getGameTimer'])
|
|
392
395
|
|
|
393
|
-
$
|
|
396
|
+
$request.sourceUpdate()
|
|
394
397
|
commit('setAuthorized', false)
|
|
395
398
|
commit('payment/setRefreshBank', false, { root: true })
|
|
396
|
-
$cookie.removeToken()
|
|
399
|
+
$request.cookie.removeToken()
|
|
397
400
|
|
|
398
401
|
// Reset Store
|
|
399
402
|
commit(`activity/resetActivities`, null, { root: true })
|
|
@@ -424,8 +427,8 @@ function createStore({ $request, $ignoreErrorRequest, $loadingRequest, $updateSo
|
|
|
424
427
|
},
|
|
425
428
|
async signUp({ state, commit, getters, dispatch, rootGetters }, data) {
|
|
426
429
|
try {
|
|
427
|
-
const signUpResult = await $
|
|
428
|
-
$cookie.setUser(data.username)
|
|
430
|
+
const signUpResult = await $request.sendWithLoading(api.register(data))
|
|
431
|
+
$request.cookie.setUser(data.username)
|
|
429
432
|
return signUpResult
|
|
430
433
|
} catch (err) {
|
|
431
434
|
console.log('[ERR] Signup Fail')
|
|
@@ -434,16 +437,16 @@ function createStore({ $request, $ignoreErrorRequest, $loadingRequest, $updateSo
|
|
|
434
437
|
},
|
|
435
438
|
async logout({ state, commit, getters, dispatch, rootGetters }) {
|
|
436
439
|
try {
|
|
437
|
-
|
|
438
|
-
await $request(api.logout())
|
|
439
|
-
dispatch('detachToken')
|
|
440
|
+
await $request.send(api.logout())
|
|
440
441
|
} catch (err) {
|
|
441
|
-
console.log('[ERR] Logout Fail')
|
|
442
|
+
console.log('[ERR] Logout Fail', err)
|
|
443
|
+
} finally {
|
|
444
|
+
dispatch('detachToken')
|
|
442
445
|
}
|
|
443
446
|
},
|
|
444
447
|
async fetchSiteConfig({ state, commit, getters, dispatch, rootGetters }) {
|
|
445
448
|
try {
|
|
446
|
-
const { config } = await $request(api.getConfig({ appSecret: clientSecret }))
|
|
449
|
+
const { config } = await $request.send(api.getConfig({ appSecret: clientSecret }))
|
|
447
450
|
const configObj = JSON.parse(window.atob(config))
|
|
448
451
|
commit('payment/setPaymentMethods', configObj?.paymentMethods || {}, { root: true })
|
|
449
452
|
commit('setSiteConfig', configObj)
|
|
@@ -464,7 +467,7 @@ function createStore({ $request, $ignoreErrorRequest, $loadingRequest, $updateSo
|
|
|
464
467
|
commit('setUA', parser.getResult())
|
|
465
468
|
},
|
|
466
469
|
async getFeeds({ commit, dispatch }) {
|
|
467
|
-
const data = await $request(api.feeds())
|
|
470
|
+
const data = await $request.send(api.feeds())
|
|
468
471
|
commit('information/setAnnouncements', data.announcementList, { root: true })
|
|
469
472
|
commit('information/setBroadcasts', data.broadcastList, { root: true })
|
|
470
473
|
const type = await dispatch('inbox/setSummary', data.mailBoxInfo, { root: true })
|
|
@@ -510,6 +513,6 @@ function createStore({ $request, $ignoreErrorRequest, $loadingRequest, $updateSo
|
|
|
510
513
|
}
|
|
511
514
|
|
|
512
515
|
export default (ctx, inject) => {
|
|
513
|
-
const { store, $request
|
|
514
|
-
store.registerModule('core', createStore({ $request
|
|
516
|
+
const { store, $request } = ctx
|
|
517
|
+
store.registerModule('core', createStore({ $request }))
|
|
515
518
|
}
|
package/plugin/game.js
CHANGED
|
@@ -11,7 +11,7 @@ const api = {
|
|
|
11
11
|
logoutGame: ({ uid_site, provider_id }) => ({ url: 'game/logout', method: 'get', params: { uid_site, provider_id } }),
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
function createStore({$request
|
|
14
|
+
function createStore({ $request }) {
|
|
15
15
|
return {
|
|
16
16
|
namespaced: true,
|
|
17
17
|
state: () => ({
|
|
@@ -205,7 +205,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
205
205
|
if (isPlayingGame(currentPath)) return
|
|
206
206
|
|
|
207
207
|
const oldSHA = rootGetters['localStorage/getGameV2SHA']
|
|
208
|
-
const newSHA = await $request(api.getGameSHA())
|
|
208
|
+
const newSHA = await $request.send(api.getGameSHA())
|
|
209
209
|
const isGameChanged = newSHA?.status !== oldSHA?.status
|
|
210
210
|
const isCategoryChanged = newSHA?.category !== oldSHA?.category
|
|
211
211
|
|
|
@@ -213,7 +213,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
213
213
|
console.log(`[Gamehall] game changed`, newSHA?.status)
|
|
214
214
|
commit(`localStorage/setGameV2SHA`, newSHA, { root: true })
|
|
215
215
|
const oldStatus = rootGetters['localStorage/getGameV2Status']
|
|
216
|
-
const newStatus = await $request(api.getGameStatus())
|
|
216
|
+
const newStatus = await $request.send(api.getGameStatus())
|
|
217
217
|
const infoChangedList = extractInfoChangedGames(oldStatus, newStatus)
|
|
218
218
|
commit(`localStorage/setGameV2Status`, newStatus, { root: true })
|
|
219
219
|
|
|
@@ -244,7 +244,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
244
244
|
}
|
|
245
245
|
},
|
|
246
246
|
async addGameOption({ getters, commit, dispatch }, code) {
|
|
247
|
-
const option = await $request(api.getGameMap(code))
|
|
247
|
+
const option = await $request.send(api.getGameMap(code))
|
|
248
248
|
if (Object.keys(option || {}).length > 0) {
|
|
249
249
|
commit('_appendGameMap', { key: code, value: option })
|
|
250
250
|
commit('_appendInverseGameMap', { key: code, value: option })
|
|
@@ -266,9 +266,9 @@ function createStore({$request, $loadingRequest}) {
|
|
|
266
266
|
if (!isInLocalStorage || fullScan === true) {
|
|
267
267
|
// 首次使用
|
|
268
268
|
const [newSHA, newStatus, option] = await Promise.all([
|
|
269
|
-
$request(api.getGameSHA()),
|
|
270
|
-
$request(api.getGameStatus()),
|
|
271
|
-
$request(api.getGameMap()),
|
|
269
|
+
$request.send(api.getGameSHA()),
|
|
270
|
+
$request.send(api.getGameStatus()),
|
|
271
|
+
$request.send(api.getGameMap()),
|
|
272
272
|
])
|
|
273
273
|
commit('localStorage/setGameV2SHA', newSHA, { root: true })
|
|
274
274
|
commit('localStorage/setGameV2Status', newStatus, { root: true })
|
|
@@ -287,7 +287,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
287
287
|
|
|
288
288
|
if (isInGamehall(currentPath)) {
|
|
289
289
|
commit('_setCategoryId', id)
|
|
290
|
-
const category = await $request(api.getGameCategory({ id }))
|
|
290
|
+
const category = await $request.send(api.getGameCategory({ id }))
|
|
291
291
|
const categoryChildren = category?.list || []
|
|
292
292
|
|
|
293
293
|
if (state.primaryCategoryList.map((item) => item.category).includes(category.name)) {
|
|
@@ -299,7 +299,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
299
299
|
} else {
|
|
300
300
|
commit('game/_setPrimaryCategoryList', categoryChildren, { root: true })
|
|
301
301
|
const favoriteId = categoryChildren.find((item) => item.category === 'SYSTEM_MY_FAVORITE').id
|
|
302
|
-
const category = await $request(api.getGameCategory({ id: favoriteId }))
|
|
302
|
+
const category = await $request.send(api.getGameCategory({ id: favoriteId }))
|
|
303
303
|
const list = category?.list || []
|
|
304
304
|
commit('_setFavorite', { ...state.favorite, code: favoriteId, list: list.map((item) => item.g) })
|
|
305
305
|
}
|
|
@@ -309,7 +309,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
309
309
|
try {
|
|
310
310
|
const appendedList = [...getters.getFavoriteList, code]
|
|
311
311
|
commit('_setFavoriteList', appendedList)
|
|
312
|
-
await $request(api.addFavoriteGame({ games: [code] }))
|
|
312
|
+
await $request.send(api.addFavoriteGame({ games: [code] }))
|
|
313
313
|
} catch (err) {
|
|
314
314
|
console.log(err)
|
|
315
315
|
const restoredList = getters.getFavoriteList.filter((item) => item !== code)
|
|
@@ -320,7 +320,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
320
320
|
try {
|
|
321
321
|
const reservedList = getters.getFavoriteList.filter((item) => item !== code)
|
|
322
322
|
commit('_setFavoriteList', reservedList)
|
|
323
|
-
await $request(api.removeFavoriteGame({ games: [code] }))
|
|
323
|
+
await $request.send(api.removeFavoriteGame({ games: [code] }))
|
|
324
324
|
} catch (err) {
|
|
325
325
|
console.log(err)
|
|
326
326
|
const restoredList = [...getters.getFavoriteList, code]
|
|
@@ -330,7 +330,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
330
330
|
async getStatements({ state, commit, getters, dispatch, rootState, rootGetters }) {
|
|
331
331
|
try {
|
|
332
332
|
commit(`core/setLoading`, true, { root: true })
|
|
333
|
-
const data = await $request(api.getStatements())
|
|
333
|
+
const data = await $request.send(api.getStatements())
|
|
334
334
|
commit(`setStatements`, data)
|
|
335
335
|
commit(`core/setLoading`, false, { root: true })
|
|
336
336
|
return data
|
|
@@ -340,7 +340,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
340
340
|
}
|
|
341
341
|
},
|
|
342
342
|
async setPreference({}, defaultCategory) {
|
|
343
|
-
return await $request(api.setPreference({ defaultCategory }))
|
|
343
|
+
return await $request.send(api.setPreference({ defaultCategory }))
|
|
344
344
|
},
|
|
345
345
|
// executeGameTimer({ state, commit, dispatch }) {
|
|
346
346
|
// clearInterval(state.gameTimer)
|
|
@@ -354,7 +354,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
354
354
|
const uid_site = rootGetters['user/userInfo'].uid_site
|
|
355
355
|
const provider_id = rootGetters['gameStore/getCurrentProvider']
|
|
356
356
|
if (provider_id) {
|
|
357
|
-
await $
|
|
357
|
+
await $request.sendWithLoading(api.logoutGame({ uid_site, provider_id }))
|
|
358
358
|
}
|
|
359
359
|
commit('setCurrentProvider', null)
|
|
360
360
|
commit('setCurrentGameId', null)
|
|
@@ -386,7 +386,7 @@ function createStore({$request, $loadingRequest}) {
|
|
|
386
386
|
? `${window.location.origin}/return`
|
|
387
387
|
: window.location.href, // For providers to return.
|
|
388
388
|
}
|
|
389
|
-
const data = await $request(api.playGame(params))
|
|
389
|
+
const data = await $request.send(api.playGame(params))
|
|
390
390
|
commit('gameMatching', false)
|
|
391
391
|
const targetUrl = data.redirect_url
|
|
392
392
|
commit('setGameURL', targetUrl)
|
|
@@ -408,8 +408,8 @@ function createStore({$request, $loadingRequest}) {
|
|
|
408
408
|
}
|
|
409
409
|
|
|
410
410
|
export default (ctx, inject) => {
|
|
411
|
-
const { store, $request
|
|
412
|
-
store.registerModule('game', createStore({$request
|
|
411
|
+
const { store, $request } = ctx
|
|
412
|
+
store.registerModule('game', createStore({ $request }))
|
|
413
413
|
}
|
|
414
414
|
|
|
415
415
|
function extractInfoChangedGames(oldStatus, newStatus) {
|
package/plugin/inbox.js
CHANGED
|
@@ -94,7 +94,7 @@ function createStore({$request}) {
|
|
|
94
94
|
},
|
|
95
95
|
actions: {
|
|
96
96
|
async initialize({ state, getters, commit, dispatch }) {
|
|
97
|
-
const { data = [] } = await $request(api.getMessageTypes())
|
|
97
|
+
const { data = [] } = await $request.send(api.getMessageTypes())
|
|
98
98
|
const tabList = data?.map((item) => item.type)
|
|
99
99
|
const inbox = tabList.map((type) => ({ tab: type, data: [], page: -1 }))
|
|
100
100
|
commit('_setTabList', tabList)
|
|
@@ -112,7 +112,7 @@ function createStore({$request}) {
|
|
|
112
112
|
|
|
113
113
|
if (!totalPage || maxIndex > nextIndex) {
|
|
114
114
|
try {
|
|
115
|
-
const data = await $request(api.getMessageList({ type: tab, page: nextIndex }))
|
|
115
|
+
const data = await $request.send(api.getMessageList({ type: tab, page: nextIndex }))
|
|
116
116
|
if (data.data.length === 0) {
|
|
117
117
|
complete()
|
|
118
118
|
return
|
|
@@ -204,7 +204,7 @@ function createStore({$request}) {
|
|
|
204
204
|
}
|
|
205
205
|
})
|
|
206
206
|
commit('_setInbox', cloneInbox)
|
|
207
|
-
$request(api.updateMessage({ groupId: message.groupId, isRead: true }))
|
|
207
|
+
$request.send(api.updateMessage({ groupId: message.groupId, isRead: true }))
|
|
208
208
|
},
|
|
209
209
|
},
|
|
210
210
|
}
|
package/plugin/job/network.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const timeout = 60 * 1000
|
|
2
|
-
export default async ({
|
|
3
|
-
if (!$
|
|
2
|
+
export default async ({ $request }, inject) => {
|
|
3
|
+
if (!$request.config) {
|
|
4
4
|
throw Error('network plugin must be after CuoraConfig module')
|
|
5
5
|
}
|
|
6
|
-
const url = `https://storage.googleapis.com/btc-storage-rd/site_resources/${$
|
|
6
|
+
const url = `https://storage.googleapis.com/btc-storage-rd/site_resources/${$request.config.clientId}/target/target.json`
|
|
7
7
|
const networkTester = new NetworkTester(url)
|
|
8
|
-
$
|
|
8
|
+
$request.config.apiURL = await networkTester.test()
|
|
9
9
|
setInterval(async () => {
|
|
10
|
-
$
|
|
10
|
+
$request.config.apiURL = await networkTester.test()
|
|
11
11
|
}, timeout)
|
|
12
12
|
inject('networkTester', networkTester)
|
|
13
13
|
}
|
package/plugin/payment.js
CHANGED
|
@@ -31,7 +31,7 @@ const api = {
|
|
|
31
31
|
mergeWallet: () => ({ url: 'payment/mergeWallet', method: 'post' }),
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function createStore({ $request
|
|
34
|
+
function createStore({ $request }) {
|
|
35
35
|
return {
|
|
36
36
|
namespaced: true,
|
|
37
37
|
state: () => ({
|
|
@@ -99,7 +99,7 @@ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
|
|
|
99
99
|
async getPaymentHistory({ commit, getters }) {
|
|
100
100
|
try {
|
|
101
101
|
commit(`core/setLoading`, true, { root: true })
|
|
102
|
-
const data = await $request(api.getPaymentHistory())
|
|
102
|
+
const data = await $request.send(api.getPaymentHistory())
|
|
103
103
|
commit(`core/setLoading`, false, { root: true })
|
|
104
104
|
return data
|
|
105
105
|
} catch (err) {
|
|
@@ -110,7 +110,7 @@ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
|
|
|
110
110
|
async sentAward({ commit, getters, dispatch }, rewardTarget) {
|
|
111
111
|
try {
|
|
112
112
|
commit(`core/setLoading`, true, { root: true })
|
|
113
|
-
const { data } = await $request(api.sentAward({ appSecret: clientSecret, ...rewardTarget }))
|
|
113
|
+
const { data } = await $request.send(api.sentAward({ appSecret: clientSecret, ...rewardTarget }))
|
|
114
114
|
await dispatch('activity/fetchActivities', null, { root: true })
|
|
115
115
|
commit(`core/setLoading`, false, { root: true })
|
|
116
116
|
return data
|
|
@@ -122,7 +122,7 @@ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
|
|
|
122
122
|
async getReward({ commit, getters, dispatch }, rewardTarget) {
|
|
123
123
|
try {
|
|
124
124
|
commit(`core/setLoading`, true, { root: true })
|
|
125
|
-
const { data } = await $request(api.getReward({ appSecret: clientSecret, ...rewardTarget }))
|
|
125
|
+
const { data } = await $request.send(api.getReward({ appSecret: clientSecret, ...rewardTarget }))
|
|
126
126
|
await dispatch('activity/fetchActivities', null, { root: true })
|
|
127
127
|
commit(`core/setLoading`, false, { root: true })
|
|
128
128
|
return data
|
|
@@ -133,7 +133,7 @@ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
|
|
|
133
133
|
},
|
|
134
134
|
async getRewardList({ commit }) {
|
|
135
135
|
try {
|
|
136
|
-
const rewards = await $request(api.getRewardList({ count: 30, appSecret: clientSecret }))
|
|
136
|
+
const rewards = await $request.send(api.getRewardList({ count: 30, appSecret: clientSecret }))
|
|
137
137
|
commit(`activity/setActivities`, { rewards: rewards?.data || {} }, { root: true })
|
|
138
138
|
} catch (err) {
|
|
139
139
|
console.log(err)
|
|
@@ -142,7 +142,7 @@ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
|
|
|
142
142
|
async getPaymentInfo({ commit }) {
|
|
143
143
|
try {
|
|
144
144
|
commit(`core/setLoading`, true, { root: true })
|
|
145
|
-
const paymentInfo = await $request(api.getPaymentInfo())
|
|
145
|
+
const paymentInfo = await $request.send(api.getPaymentInfo())
|
|
146
146
|
commit(`core/setLoading`, false, { root: true })
|
|
147
147
|
return paymentInfo
|
|
148
148
|
} catch (err) {
|
|
@@ -157,7 +157,7 @@ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
|
|
|
157
157
|
},
|
|
158
158
|
async fetchAvailableBanks({ commit }, paymentMethod = 'amb') {
|
|
159
159
|
try {
|
|
160
|
-
const data = await $request(api.getBankList(paymentMethod))
|
|
160
|
+
const data = await $request.send(api.getBankList(paymentMethod))
|
|
161
161
|
commit(`setAvailableBanks`, data)
|
|
162
162
|
return data
|
|
163
163
|
} catch (err) {
|
|
@@ -169,7 +169,7 @@ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
|
|
|
169
169
|
const status = await dispatch('core/checkStatus', null, { root: true })
|
|
170
170
|
if (status === true) {
|
|
171
171
|
commit(`core/setLoading`, true, { root: true })
|
|
172
|
-
const data = await $request(api.makeTransaction({ type, payload, paymentMethod }))
|
|
172
|
+
const data = await $request.send(api.makeTransaction({ type, payload, paymentMethod }))
|
|
173
173
|
commit(`core/setLoading`, false, { root: true })
|
|
174
174
|
return data
|
|
175
175
|
} else {
|
|
@@ -183,13 +183,13 @@ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
|
|
|
183
183
|
const done = getters.getRefreshBank
|
|
184
184
|
if (!done) {
|
|
185
185
|
commit('setRefreshBank', true)
|
|
186
|
-
await $
|
|
186
|
+
await $request.sendIgnoreError(api.makeTransaction( { type: 'DEPOSIT', payload: null, paymentMethod: 'amb' }))
|
|
187
187
|
}
|
|
188
188
|
},
|
|
189
189
|
async checkTransaction({ commit, dispatch }, paymentMethod) {
|
|
190
190
|
try {
|
|
191
191
|
commit(`core/setLoading`, true, { root: true })
|
|
192
|
-
const data = await $request(api.checkTransaction(paymentMethod))
|
|
192
|
+
const data = await $request.send(api.checkTransaction(paymentMethod))
|
|
193
193
|
commit(`core/setLoading`, false, { root: true })
|
|
194
194
|
return data
|
|
195
195
|
} catch (err) {
|
|
@@ -216,7 +216,7 @@ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
|
|
|
216
216
|
return await $loadingRequest(api.setBonusSetting({ bonus: data }))
|
|
217
217
|
},
|
|
218
218
|
async getCurrentWithdrawRule({ commit, dispatch }) {
|
|
219
|
-
const currentRule = await $request(api.getCurrentWithdrawRule())
|
|
219
|
+
const currentRule = await $request.send(api.getCurrentWithdrawRule())
|
|
220
220
|
return ruleFormatter(currentRule.rules)
|
|
221
221
|
},
|
|
222
222
|
async convertFreeCredit({ dispatch }, exchangeType) {
|
|
@@ -234,8 +234,8 @@ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
export default (ctx, inject) => {
|
|
237
|
-
const { store, $request
|
|
238
|
-
store.registerModule('payment', createStore({ $request
|
|
237
|
+
const { store, $request } = ctx
|
|
238
|
+
store.registerModule('payment', createStore({ $request }))
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
function ruleFormatter(rules) {
|
package/plugin/request.js
CHANGED
|
@@ -83,127 +83,127 @@ class Cookie {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
config.headers['X-TH1GAMES-PLATFORM'] = cuoraConfig.product
|
|
103
|
-
if (cookie.getToken()) {
|
|
104
|
-
config.headers.Authorization = cookie.getToken()
|
|
105
|
-
}
|
|
106
|
-
return config
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
$axios.interceptors.response.use(
|
|
110
|
-
function (response) {
|
|
111
|
-
if (response.data.error) {
|
|
112
|
-
return Promise.reject(response.data.error)
|
|
86
|
+
class Request {
|
|
87
|
+
constructor(axios, store, config, cookie) {
|
|
88
|
+
this.axios = axios
|
|
89
|
+
this.store = store
|
|
90
|
+
this.source = axios.CancelToken.source()
|
|
91
|
+
this.config = config
|
|
92
|
+
this.cookie = cookie
|
|
93
|
+
this.initialize()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
initialize() {
|
|
97
|
+
this.axios.interceptors.request.use((config) => {
|
|
98
|
+
config.headers['X-TH1GAMES-VERSION'] = this.config.version
|
|
99
|
+
config.headers['X-TH1GAMES-PLATFORM'] = this.config.product
|
|
100
|
+
if (this.cookie.getToken()) {
|
|
101
|
+
config.headers.Authorization = this.cookie.getToken()
|
|
113
102
|
}
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
normal: async (req, customToken) => {
|
|
126
|
-
try {
|
|
127
|
-
const cancelToken = customToken || source.token
|
|
128
|
-
checkToken(req, cookie.getToken())
|
|
129
|
-
const config = createConfig(cuoraConfig, req, cancelToken)
|
|
130
|
-
const { data } = await $axios.request(config)
|
|
131
|
-
return data
|
|
132
|
-
} catch (error) {
|
|
133
|
-
if (error.code) {
|
|
134
|
-
store.commit('core/setGlobalError', error)
|
|
103
|
+
return config
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
this.axios.interceptors.response.use(
|
|
107
|
+
function (response) {
|
|
108
|
+
if (response.data.error) {
|
|
109
|
+
return Promise.reject(response.data.error)
|
|
135
110
|
}
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
store.commit('core/setLoading', true)
|
|
142
|
-
const cancelToken = customToken || source.token
|
|
143
|
-
checkToken(req, cookie.getToken())
|
|
144
|
-
const config = createConfig(cuoraConfig, req, cancelToken)
|
|
145
|
-
const { data } = await $axios.request(config)
|
|
146
|
-
return data
|
|
147
|
-
} catch (error) {
|
|
148
|
-
if (error.code) {
|
|
149
|
-
store.commit('core/setGlobalError', error)
|
|
111
|
+
return Promise.resolve(response)
|
|
112
|
+
},
|
|
113
|
+
function (error) {
|
|
114
|
+
if (error.message === 'Network Error' || error.message === 'Request failed with status code 404') {
|
|
115
|
+
return Promise.reject({ code: 'ERR_998' })
|
|
150
116
|
}
|
|
151
|
-
|
|
152
|
-
} finally {
|
|
153
|
-
store.commit('core/setLoading', false)
|
|
117
|
+
return Promise.reject(error.response?.data?.error || error)
|
|
154
118
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async send(req, customToken) {
|
|
123
|
+
try {
|
|
124
|
+
const cancelToken = customToken || this.source.token
|
|
125
|
+
this._checkToken(req, this.cookie.getToken())
|
|
126
|
+
const config = this._createConfig(req, cancelToken)
|
|
127
|
+
const { data } = await this.axios.request(config)
|
|
128
|
+
return data
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (error.code) {
|
|
131
|
+
this.store.commit('core/setGlobalError', error)
|
|
165
132
|
}
|
|
166
|
-
|
|
167
|
-
updateSource: () => {
|
|
168
|
-
source.cancel('Requests Cancelled')
|
|
169
|
-
source = CancelToken.source()
|
|
170
|
-
},
|
|
171
|
-
generateSource: () => {
|
|
172
|
-
return CancelToken.source()
|
|
133
|
+
throw error
|
|
173
134
|
}
|
|
174
135
|
}
|
|
175
|
-
}
|
|
176
136
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
137
|
+
async sendWithLoading(req, customToken) {
|
|
138
|
+
try {
|
|
139
|
+
this.store.commit('core/setLoading', true)
|
|
140
|
+
const cancelToken = customToken || this.source.token
|
|
141
|
+
this._checkToken(req, this.cookie.getToken())
|
|
142
|
+
const config = this._createConfig(req, cancelToken)
|
|
143
|
+
const { data } = await this.axios.request(config)
|
|
144
|
+
return data
|
|
145
|
+
} catch (error) {
|
|
146
|
+
if (error.code) {
|
|
147
|
+
this.store.commit('core/setGlobalError', error)
|
|
148
|
+
}
|
|
149
|
+
throw error
|
|
150
|
+
} finally {
|
|
151
|
+
this.store.commit('core/setLoading', false)
|
|
152
|
+
}
|
|
184
153
|
}
|
|
185
|
-
return config
|
|
186
|
-
}
|
|
187
154
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
155
|
+
async sendIgnoreError(req, customToken) {
|
|
156
|
+
try {
|
|
157
|
+
const cancelToken = customToken || this.source.token
|
|
158
|
+
this._checkToken(req, this.cookie.getToken())
|
|
159
|
+
const config = this._createConfig(req, cancelToken)
|
|
160
|
+
const { data } = await this.axios.request(config)
|
|
161
|
+
return data
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.log('[ Ignore Error ] ', error)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
sourceUpdate() {
|
|
168
|
+
this.source.cancel('Requests Cancelled')
|
|
169
|
+
this.source = this.axios.CancelToken.source()
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
sourceGenerate() {
|
|
173
|
+
return this.axios.CancelToken.source()
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_createConfig(req, cancelToken) {
|
|
177
|
+
const { method, url, params } = req
|
|
178
|
+
const config = { baseURL: this.config.fullURL, method, url, cancelToken, public: req.public }
|
|
179
|
+
if (method.toUpperCase() === 'GET') {
|
|
180
|
+
config.params = pickBy(params, this._checkValuable)
|
|
181
|
+
} else {
|
|
182
|
+
config.data = pickBy(params, this._checkValuable)
|
|
183
|
+
}
|
|
184
|
+
return config
|
|
185
|
+
}
|
|
191
186
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
187
|
+
_checkValuable(value) {
|
|
188
|
+
return value !== undefined && value !== null
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
_checkToken(req, token) {
|
|
192
|
+
if (!req.public && !token) {
|
|
193
|
+
throw { code: 'ERR_A103', url: req.url }
|
|
194
|
+
}
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
export default (ctx, inject) => {
|
|
199
199
|
const { $axios, store } = ctx
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
inject('
|
|
200
|
+
const cuoraConfig = new CuoraConfig({
|
|
201
|
+
apiURL: process.env.API_URL,
|
|
202
|
+
apiVersion: process.env.API_VERSION,
|
|
203
|
+
clientId: process.env.CLIENT_ID,
|
|
204
|
+
product: 'pwa',
|
|
205
|
+
version: 'v<%= options.version %>'
|
|
206
|
+
})
|
|
207
|
+
const cookie = new Cookie(`cuora_${cuoraConfig.clientId}`)
|
|
208
|
+
inject('request', new Request($axios, store, cuoraConfig, cookie))
|
|
209
209
|
}
|
package/plugin/search.js
CHANGED
|
@@ -22,7 +22,7 @@ const api = {
|
|
|
22
22
|
|
|
23
23
|
let source = null
|
|
24
24
|
|
|
25
|
-
function createStore({$request
|
|
25
|
+
function createStore({$request}) {
|
|
26
26
|
return {
|
|
27
27
|
namespaced: true,
|
|
28
28
|
state: () => ({
|
|
@@ -229,14 +229,14 @@ function createStore({$request, $generateSource}) {
|
|
|
229
229
|
if (source) {
|
|
230
230
|
source.cancel('Requests Cancelled')
|
|
231
231
|
}
|
|
232
|
-
source = $
|
|
233
|
-
return
|
|
232
|
+
source = $request.sourceGenerate()
|
|
233
|
+
return $request.send(api.getGameTags({ q }), source.token)
|
|
234
234
|
},
|
|
235
235
|
async getGameSearchList({}, { id, index, q, click, clickDefault }) {
|
|
236
|
-
return
|
|
236
|
+
return $request.send(api.getGameSearchList({ id, index, q, click, clickDefault }))
|
|
237
237
|
},
|
|
238
238
|
async setGameSearchTrace({}, { traceId, tagId, tagIndex, gameCode, gameCodeIndex, query, click }) {
|
|
239
|
-
return
|
|
239
|
+
return $request.send(
|
|
240
240
|
api.setGameSearchTrace({
|
|
241
241
|
traceId,
|
|
242
242
|
tagId,
|
|
@@ -253,8 +253,8 @@ function createStore({$request, $generateSource}) {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
export default (ctx, inject) => {
|
|
256
|
-
const { store, $request
|
|
257
|
-
store.registerModule('search', createStore({$request
|
|
256
|
+
const { store, $request } = ctx
|
|
257
|
+
store.registerModule('search', createStore({$request}))
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
function wait(interval, fn) {
|
package/plugin/user.js
CHANGED
|
@@ -25,7 +25,7 @@ const api = {
|
|
|
25
25
|
acknowledge: ({ requestId, code }) => ({ url: 'acknowledge', method: 'post', params: { requestId, code } }),
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function createStore({ $request
|
|
28
|
+
function createStore({ $request }) {
|
|
29
29
|
return {
|
|
30
30
|
namespaced: true,
|
|
31
31
|
state: () => ({
|
|
@@ -112,7 +112,7 @@ function createStore({ $request, $loadingRequest, $fullURL }) {
|
|
|
112
112
|
actions: {
|
|
113
113
|
async modifyUserInfo({ commit }, payload) {
|
|
114
114
|
try {
|
|
115
|
-
return await $
|
|
115
|
+
return await $request.sendWithLoading(api.updateUserInfo(payload))
|
|
116
116
|
} catch (err) {
|
|
117
117
|
console.log(err)
|
|
118
118
|
}
|
|
@@ -120,7 +120,7 @@ function createStore({ $request, $loadingRequest, $fullURL }) {
|
|
|
120
120
|
async getUserInfo({ state, getters, commit }) {
|
|
121
121
|
if (!state.userInfoFlag) {
|
|
122
122
|
commit('setUserInfoFlag', true)
|
|
123
|
-
const userInfo = await $request(api.getUserInfo())
|
|
123
|
+
const userInfo = await $request.send(api.getUserInfo())
|
|
124
124
|
commit('setUserInfo', userInfo)
|
|
125
125
|
commit('setInline', !!userInfo.rank)
|
|
126
126
|
if (getters[`getSavedLevel`] === null) {
|
|
@@ -131,12 +131,12 @@ function createStore({ $request, $loadingRequest, $fullURL }) {
|
|
|
131
131
|
}
|
|
132
132
|
},
|
|
133
133
|
async changePassword({ commit }, payload) {
|
|
134
|
-
return await $
|
|
134
|
+
return await $request.sendWithLoading(api.changePassword(payload))
|
|
135
135
|
},
|
|
136
136
|
async resetOTP({ commit }, { requestId, number }) {
|
|
137
137
|
try {
|
|
138
138
|
commit(`core/setLoading`, true, { root: true })
|
|
139
|
-
const data = await $request(api.reset({ requestId, number }))
|
|
139
|
+
const data = await $request.send(api.reset({ requestId, number }))
|
|
140
140
|
commit(`core/setVerificationData`, data, { root: true })
|
|
141
141
|
} catch (err) {
|
|
142
142
|
console.log(err)
|
|
@@ -145,30 +145,30 @@ function createStore({ $request, $loadingRequest, $fullURL }) {
|
|
|
145
145
|
}
|
|
146
146
|
},
|
|
147
147
|
async getAffiliate({}) {
|
|
148
|
-
return
|
|
148
|
+
return $request.send(api.getAffiliate())
|
|
149
149
|
},
|
|
150
150
|
async postAffiliate({}, affiliateCode) {
|
|
151
|
-
return
|
|
151
|
+
return $request.send(api.postAffiliate({ affiliateCode }))
|
|
152
152
|
},
|
|
153
153
|
async passwordAbandon({ commit }, number) {
|
|
154
|
-
await $request(api.passwordAbandon({ number }))
|
|
154
|
+
await $request.send(api.passwordAbandon({ number }))
|
|
155
155
|
commit(`setRecoveryData`, {})
|
|
156
156
|
},
|
|
157
157
|
async passwordRecovery({ commit }, recoveryData) {
|
|
158
|
-
const data = await $request(api.passwordRecovery(recoveryData))
|
|
158
|
+
const data = await $request.send(api.passwordRecovery(recoveryData))
|
|
159
159
|
commit(`setRecoveryData`, data)
|
|
160
160
|
},
|
|
161
161
|
async passwordAcknowledge({ commit }, acknowledgeData) {
|
|
162
|
-
await $request(api.passwordAcknowledge(acknowledgeData))
|
|
162
|
+
await $request.send(api.passwordAcknowledge(acknowledgeData))
|
|
163
163
|
commit(`setRecoveryData`, {})
|
|
164
164
|
},
|
|
165
165
|
async verify({ commit }) {
|
|
166
|
-
const data = await $
|
|
166
|
+
const data = await $request.sendWithLoading(api.verify())
|
|
167
167
|
commit(`core/setVerificationData`, data, { root: true })
|
|
168
168
|
return data
|
|
169
169
|
},
|
|
170
170
|
async acknowledge({}, requestId, code) {
|
|
171
|
-
return $
|
|
171
|
+
return $request.sendWithLoading(api.acknowledge({ requestId, code }))
|
|
172
172
|
},
|
|
173
173
|
socialLogin({}, method) {
|
|
174
174
|
const supports = ['line', 'facebook', 'qq', 'wechat', 'weibo', 'zalo', 'google', 'telegram']
|
|
@@ -177,7 +177,7 @@ function createStore({ $request, $loadingRequest, $fullURL }) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
const url = urljoin(
|
|
180
|
-
$fullURL,
|
|
180
|
+
$request.config.fullURL,
|
|
181
181
|
'login',
|
|
182
182
|
'?' + qs.stringify({
|
|
183
183
|
provider: method,
|
|
@@ -193,6 +193,6 @@ function createStore({ $request, $loadingRequest, $fullURL }) {
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
export default (ctx, inject) => {
|
|
196
|
-
const { store, $request
|
|
197
|
-
store.registerModule('user', createStore({ $request
|
|
196
|
+
const { store, $request } = ctx
|
|
197
|
+
store.registerModule('user', createStore({ $request }))
|
|
198
198
|
}
|