Update ai suggest

This commit is contained in:
Joseph Le 2026-06-30 17:11:14 +10:00
parent 64948505e7
commit e14c504d01
3 changed files with 12 additions and 11 deletions

View File

@ -67,7 +67,7 @@ export default class EbayScraperService {
/** Đóng browser dùng chung (gọi khi command/worker tắt). */
static async close(): Promise<void> {
if (this._browser) {
await this._browser.close().catch(() => {})
await this._browser.close().catch(() => { })
this._browser = null
}
}
@ -127,7 +127,7 @@ export default class EbayScraperService {
// QUAN TRỌNG: eBay chặn truy cập trực tiếp vào /sch/i.html (trả Error Page).
// Phải vào homepage trước để lấy cookie/session, rồi mới điều hướng tới search.
const origin = new URL(url).origin
await page.goto(origin + '/', { waitUntil: 'domcontentloaded', timeout }).catch(() => {})
await page.goto(origin + '/', { waitUntil: 'domcontentloaded', timeout }).catch(() => { })
await wait(1500)
await page.goto(url, { waitUntil: 'networkidle2', timeout })
@ -142,9 +142,9 @@ export default class EbayScraperService {
html.includes('Something went wrong on our end')
if (blocked) {
// Bị chặn -> quay lại homepage rồi vào lại search.
await page.goto(new URL(url).origin + '/', { waitUntil: 'domcontentloaded', timeout }).catch(() => {})
await page.goto(new URL(url).origin + '/', { waitUntil: 'domcontentloaded', timeout }).catch(() => { })
await wait(1500)
await page.goto(url, { waitUntil: 'networkidle2', timeout }).catch(() => {})
await page.goto(url, { waitUntil: 'networkidle2', timeout }).catch(() => { })
retries++
continue
}
@ -190,6 +190,7 @@ export default class EbayScraperService {
const idMatch = it.link_detail.match(/\/itm\/(\d+)/)
const id = idMatch ? idMatch[1] : it.listingId
if (!id) return null
if (!it.title?.includes(sku)) return null
const { amount, currency } = this.parsePrice(it.priceText)
if (!Number.isFinite(amount) || amount <= 0) return null
@ -226,7 +227,7 @@ export default class EbayScraperService {
logger.error({ err, url }, `eBay scrape lỗi cho SKU ${sku}`)
return []
} finally {
if (page) await page.close().catch(() => {})
if (page) await page.close().catch(() => { })
}
}

View File

@ -144,7 +144,7 @@ export default class EbayService {
marketplace: string
) {
const response = await fetch(
`${baseUrl.replace(/\/$/, '')}/buy/browse/v1/item_summary/search?q=${encodeURIComponent(sku)}&filter=conditionIds:{${conditionId}}&limit=100`,
`${baseUrl.replace(/\/$/, '')}/buy/browse/v1/item_summary/search?q=${encodeURIComponent(sku)}&filter=conditionIds:{${conditionId}}&limit=50`,
{
headers: {
Authorization: `Bearer ${token}`,

View File

@ -20,7 +20,7 @@ const Product = (await import('#models/product')).default
const EbayService = (await import('#services/ebay_service')).default
async function runSyncServiceTest() {
const product = await Product.query().first()
const product = await Product.query().where('id', 182).first()
if (!product) {
throw new Error('Không có sản phẩm nào trong database để test AI suggest')
}