fix: add $autoCancel:false to games API calls
GamesLibrary auto-cancellation error was caused by missing $autoCancel:false on all games.ts PocketBase SDK calls. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+19
-13
@@ -15,7 +15,8 @@ export async function getGroupGames(groupId: string, options?: {
|
|||||||
|
|
||||||
const result = await pb.collection('games').getList(page, limit, {
|
const result = await pb.collection('games').getList(page, limit, {
|
||||||
filter,
|
filter,
|
||||||
sort: '-created'
|
sort: '-created',
|
||||||
|
$autoCancel: false
|
||||||
})
|
})
|
||||||
return { items: result.items as unknown as Game[], total: result.totalItems }
|
return { items: result.items as unknown as Game[], total: result.totalItems }
|
||||||
}
|
}
|
||||||
@@ -33,12 +34,12 @@ export async function addGame(groupId: string, data: {
|
|||||||
group: groupId,
|
group: groupId,
|
||||||
addedBy: user?.id,
|
addedBy: user?.id,
|
||||||
popularCount: 0
|
popularCount: 0
|
||||||
})
|
}, { $autoCancel: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除游戏
|
// 删除游戏
|
||||||
export async function deleteGame(gameId: string) {
|
export async function deleteGame(gameId: string) {
|
||||||
return pb.collection('games').delete(gameId)
|
return pb.collection('games').delete(gameId, { $autoCancel: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入游戏(批量添加)
|
// 导入游戏(批量添加)
|
||||||
@@ -64,7 +65,8 @@ export async function importGames(groupId: string, games: Array<{
|
|||||||
export async function exportGames(groupId: string): Promise<Game[]> {
|
export async function exportGames(groupId: string): Promise<Game[]> {
|
||||||
const result = await pb.collection('games').getFullList({
|
const result = await pb.collection('games').getFullList({
|
||||||
filter: `group="${groupId}"`,
|
filter: `group="${groupId}"`,
|
||||||
sort: '-created'
|
sort: '-created',
|
||||||
|
$autoCancel: false
|
||||||
})
|
})
|
||||||
return result as unknown as Game[]
|
return result as unknown as Game[]
|
||||||
}
|
}
|
||||||
@@ -75,17 +77,18 @@ export async function toggleFavorite(gameId: string): Promise<boolean> {
|
|||||||
if (!user) throw new Error('未登录')
|
if (!user) throw new Error('未登录')
|
||||||
|
|
||||||
const existing = await pb.collection('game_favorites').getList(1, 1, {
|
const existing = await pb.collection('game_favorites').getList(1, 1, {
|
||||||
filter: `game="${gameId}" && user="${user.id}"`
|
filter: `game="${gameId}" && user="${user.id}"`,
|
||||||
|
$autoCancel: false
|
||||||
})
|
})
|
||||||
|
|
||||||
if (existing.items.length > 0) {
|
if (existing.items.length > 0) {
|
||||||
await pb.collection('game_favorites').delete(existing.items[0].id)
|
await pb.collection('game_favorites').delete(existing.items[0].id, { $autoCancel: false })
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
await pb.collection('game_favorites').create({
|
await pb.collection('game_favorites').create({
|
||||||
game: gameId,
|
game: gameId,
|
||||||
user: user.id
|
user: user.id
|
||||||
})
|
}, { $autoCancel: false })
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,7 +99,8 @@ export async function isFavorite(gameId: string): Promise<boolean> {
|
|||||||
if (!user) return false
|
if (!user) return false
|
||||||
|
|
||||||
const result = await pb.collection('game_favorites').getList(1, 1, {
|
const result = await pb.collection('game_favorites').getList(1, 1, {
|
||||||
filter: `game="${gameId}" && user="${user.id}"`
|
filter: `game="${gameId}" && user="${user.id}"`,
|
||||||
|
$autoCancel: false
|
||||||
})
|
})
|
||||||
return result.items.length > 0
|
return result.items.length > 0
|
||||||
}
|
}
|
||||||
@@ -111,7 +115,7 @@ export async function addComment(gameId: string, content: string, rating?: numbe
|
|||||||
author: user.id,
|
author: user.id,
|
||||||
content,
|
content,
|
||||||
rating
|
rating
|
||||||
})
|
}, { $autoCancel: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取游戏评论
|
// 获取游戏评论
|
||||||
@@ -119,7 +123,8 @@ export async function getGameComments(gameId: string): Promise<GameComment[]> {
|
|||||||
const result = await pb.collection('game_comments').getList(1, 50, {
|
const result = await pb.collection('game_comments').getList(1, 50, {
|
||||||
filter: `game="${gameId}"`,
|
filter: `game="${gameId}"`,
|
||||||
sort: '-created',
|
sort: '-created',
|
||||||
expand: 'author'
|
expand: 'author',
|
||||||
|
$autoCancel: false
|
||||||
})
|
})
|
||||||
return result.items as unknown as GameComment[]
|
return result.items as unknown as GameComment[]
|
||||||
}
|
}
|
||||||
@@ -137,7 +142,8 @@ export async function searchGames(query: string, groupId?: string, limit = 20):
|
|||||||
|
|
||||||
const result = await pb.collection('games').getList(1, limit, {
|
const result = await pb.collection('games').getList(1, limit, {
|
||||||
filter,
|
filter,
|
||||||
sort: '-popularCount'
|
sort: '-popularCount',
|
||||||
|
$autoCancel: false
|
||||||
})
|
})
|
||||||
return result.items as unknown as Game[]
|
return result.items as unknown as Game[]
|
||||||
}
|
}
|
||||||
@@ -147,9 +153,9 @@ export async function getPopularGames(limit = 10): Promise<Game[]> {
|
|||||||
const user = pb.authStore.model
|
const user = pb.authStore.model
|
||||||
if (!user) return []
|
if (!user) return []
|
||||||
|
|
||||||
// 获取用户所在群组的游戏
|
|
||||||
const result = await pb.collection('games').getList(1, limit, {
|
const result = await pb.collection('games').getList(1, limit, {
|
||||||
sort: '-popularCount'
|
sort: '-popularCount',
|
||||||
|
$autoCancel: false
|
||||||
})
|
})
|
||||||
return result.items as unknown as Game[]
|
return result.items as unknown as Game[]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user