use client-side wiki fetch for batch preview imports
This commit is contained in:
parent
34db76fbdc
commit
5c870b148e
4 changed files with 60 additions and 9 deletions
|
|
@ -1192,13 +1192,21 @@ export class EntityAdapter extends BaseAdapter {
|
||||||
* Fetches wiki data and suggestions for multiple character wiki pages
|
* Fetches wiki data and suggestions for multiple character wiki pages
|
||||||
* Requires editor role (>= 7)
|
* Requires editor role (>= 7)
|
||||||
* @param wikiPages - Array of wiki page names (max 10)
|
* @param wikiPages - Array of wiki page names (max 10)
|
||||||
|
* @param wikiData - Optional pre-fetched wiki text keyed by page name
|
||||||
*/
|
*/
|
||||||
async batchPreviewCharacters(
|
async batchPreviewCharacters(
|
||||||
wikiPages: string[]
|
wikiPages: string[],
|
||||||
|
wikiData?: Record<string, string>
|
||||||
): Promise<BatchPreviewResponse<CharacterSuggestions>> {
|
): Promise<BatchPreviewResponse<CharacterSuggestions>> {
|
||||||
|
const body: { wiki_pages: string[]; wiki_data?: Record<string, string> } = {
|
||||||
|
wiki_pages: wikiPages
|
||||||
|
}
|
||||||
|
if (wikiData) {
|
||||||
|
body.wiki_data = wikiData
|
||||||
|
}
|
||||||
return this.request<BatchPreviewResponse<CharacterSuggestions>>('/characters/batch_preview', {
|
return this.request<BatchPreviewResponse<CharacterSuggestions>>('/characters/batch_preview', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { wiki_pages: wikiPages }
|
body
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1206,13 +1214,21 @@ export class EntityAdapter extends BaseAdapter {
|
||||||
* Fetches wiki data and suggestions for multiple weapon wiki pages
|
* Fetches wiki data and suggestions for multiple weapon wiki pages
|
||||||
* Requires editor role (>= 7)
|
* Requires editor role (>= 7)
|
||||||
* @param wikiPages - Array of wiki page names (max 10)
|
* @param wikiPages - Array of wiki page names (max 10)
|
||||||
|
* @param wikiData - Optional pre-fetched wiki text keyed by page name
|
||||||
*/
|
*/
|
||||||
async batchPreviewWeapons(
|
async batchPreviewWeapons(
|
||||||
wikiPages: string[]
|
wikiPages: string[],
|
||||||
|
wikiData?: Record<string, string>
|
||||||
): Promise<BatchPreviewResponse<WeaponSuggestions>> {
|
): Promise<BatchPreviewResponse<WeaponSuggestions>> {
|
||||||
|
const body: { wiki_pages: string[]; wiki_data?: Record<string, string> } = {
|
||||||
|
wiki_pages: wikiPages
|
||||||
|
}
|
||||||
|
if (wikiData) {
|
||||||
|
body.wiki_data = wikiData
|
||||||
|
}
|
||||||
return this.request<BatchPreviewResponse<WeaponSuggestions>>('/weapons/batch_preview', {
|
return this.request<BatchPreviewResponse<WeaponSuggestions>>('/weapons/batch_preview', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { wiki_pages: wikiPages }
|
body
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1220,13 +1236,21 @@ export class EntityAdapter extends BaseAdapter {
|
||||||
* Fetches wiki data and suggestions for multiple summon wiki pages
|
* Fetches wiki data and suggestions for multiple summon wiki pages
|
||||||
* Requires editor role (>= 7)
|
* Requires editor role (>= 7)
|
||||||
* @param wikiPages - Array of wiki page names (max 10)
|
* @param wikiPages - Array of wiki page names (max 10)
|
||||||
|
* @param wikiData - Optional pre-fetched wiki text keyed by page name
|
||||||
*/
|
*/
|
||||||
async batchPreviewSummons(
|
async batchPreviewSummons(
|
||||||
wikiPages: string[]
|
wikiPages: string[],
|
||||||
|
wikiData?: Record<string, string>
|
||||||
): Promise<BatchPreviewResponse<SummonSuggestions>> {
|
): Promise<BatchPreviewResponse<SummonSuggestions>> {
|
||||||
|
const body: { wiki_pages: string[]; wiki_data?: Record<string, string> } = {
|
||||||
|
wiki_pages: wikiPages
|
||||||
|
}
|
||||||
|
if (wikiData) {
|
||||||
|
body.wiki_data = wikiData
|
||||||
|
}
|
||||||
return this.request<BatchPreviewResponse<SummonSuggestions>>('/summons/batch_preview', {
|
return this.request<BatchPreviewResponse<SummonSuggestions>>('/summons/batch_preview', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { wiki_pages: wikiPages }
|
body
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { entityAdapter, type CharacterSuggestions } from '$lib/api/adapters/entity.adapter'
|
import { entityAdapter, type CharacterSuggestions } from '$lib/api/adapters/entity.adapter'
|
||||||
|
import { fetchWikiPages, buildWikiDataMap } from '$lib/api/wiki'
|
||||||
import { getCharacterImage, getPlaceholderImage } from '$lib/utils/images'
|
import { getCharacterImage, getPlaceholderImage } from '$lib/utils/images'
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
|
|
@ -174,7 +175,15 @@
|
||||||
selectedWikiPage = pages[0] ?? null
|
selectedWikiPage = pages[0] ?? null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await entityAdapter.batchPreviewCharacters(pages)
|
// Step 1: Fetch wiki data client-side (bypasses CloudFlare)
|
||||||
|
const wikiResults = await fetchWikiPages(pages)
|
||||||
|
const wikiData = buildWikiDataMap(wikiResults)
|
||||||
|
|
||||||
|
// Update pages array with any redirects
|
||||||
|
const finalPages = wikiResults.map((r) => r.wikiPage)
|
||||||
|
|
||||||
|
// Step 2: Send to API for parsing (with pre-fetched wiki data)
|
||||||
|
const response = await entityAdapter.batchPreviewCharacters(finalPages, wikiData)
|
||||||
|
|
||||||
// Update entities with results
|
// Update entities with results
|
||||||
const updatedEntities = new Map<string, EntityState>()
|
const updatedEntities = new Map<string, EntityState>()
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { entityAdapter, type SummonSuggestions } from '$lib/api/adapters/entity.adapter'
|
import { entityAdapter, type SummonSuggestions } from '$lib/api/adapters/entity.adapter'
|
||||||
|
import { fetchWikiPages, buildWikiDataMap } from '$lib/api/wiki'
|
||||||
import { getSummonImage, getPlaceholderImage } from '$lib/utils/images'
|
import { getSummonImage, getPlaceholderImage } from '$lib/utils/images'
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
|
|
@ -164,7 +165,15 @@
|
||||||
selectedWikiPage = pages[0] ?? null
|
selectedWikiPage = pages[0] ?? null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await entityAdapter.batchPreviewSummons(pages)
|
// Step 1: Fetch wiki data client-side (bypasses CloudFlare)
|
||||||
|
const wikiResults = await fetchWikiPages(pages)
|
||||||
|
const wikiData = buildWikiDataMap(wikiResults)
|
||||||
|
|
||||||
|
// Update pages array with any redirects
|
||||||
|
const finalPages = wikiResults.map((r) => r.wikiPage)
|
||||||
|
|
||||||
|
// Step 2: Send to API for parsing (with pre-fetched wiki data)
|
||||||
|
const response = await entityAdapter.batchPreviewSummons(finalPages, wikiData)
|
||||||
|
|
||||||
// Update entities with results
|
// Update entities with results
|
||||||
const updatedEntities = new Map<string, EntityState>()
|
const updatedEntities = new Map<string, EntityState>()
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { entityAdapter, type WeaponSuggestions } from '$lib/api/adapters/entity.adapter'
|
import { entityAdapter, type WeaponSuggestions } from '$lib/api/adapters/entity.adapter'
|
||||||
|
import { fetchWikiPages, buildWikiDataMap } from '$lib/api/wiki'
|
||||||
import { getWeaponImage, getPlaceholderImage } from '$lib/utils/images'
|
import { getWeaponImage, getPlaceholderImage } from '$lib/utils/images'
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
|
|
@ -166,7 +167,15 @@
|
||||||
selectedWikiPage = pages[0] ?? null
|
selectedWikiPage = pages[0] ?? null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await entityAdapter.batchPreviewWeapons(pages)
|
// Step 1: Fetch wiki data client-side (bypasses CloudFlare)
|
||||||
|
const wikiResults = await fetchWikiPages(pages)
|
||||||
|
const wikiData = buildWikiDataMap(wikiResults)
|
||||||
|
|
||||||
|
// Update pages array with any redirects
|
||||||
|
const finalPages = wikiResults.map((r) => r.wikiPage)
|
||||||
|
|
||||||
|
// Step 2: Send to API for parsing (with pre-fetched wiki data)
|
||||||
|
const response = await entityAdapter.batchPreviewWeapons(finalPages, wikiData)
|
||||||
|
|
||||||
// Update entities with results
|
// Update entities with results
|
||||||
const updatedEntities = new Map<string, EntityState>()
|
const updatedEntities = new Map<string, EntityState>()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue