zksu
/
API
forked from yoone/API
1
0
Fork 0

refactor(service): 统一使用site.apiUrl并优化产品同步逻辑

移除对wpApiUrl的兼容处理,统一使用apiUrl
修复产品同步查询的分页问题,使用Infinity获取全部数据
优化代码格式和缩进
This commit is contained in:
tikkhun 2025-11-24 09:24:55 +08:00
parent c7480ccc8a
commit a64e611294
3 changed files with 43 additions and 44 deletions

View File

@ -36,9 +36,8 @@ export class WPService {
* @param namespace API wc/v3 wcs/v1
*/
private createApi(site: any, namespace: WooCommerceRestApiVersion = 'wc/v3') {
const url = site.wpApiUrl ?? site.apiUrl; // 中文注释:兼容数据库 Site 与 WpSite 结构
return new WooCommerceRestApi({
url,
url: site.apiUrl,
consumerKey: site.consumerKey,
consumerSecret: site.consumerSecret,
version: namespace,
@ -86,7 +85,7 @@ export class WPService {
param: Record<string, any> = {}
): Promise<T> {
try {
const apiUrl = site.wpApiUrl ?? site.apiUrl;
const apiUrl = site.apiUrl;
const { consumerKey, consumerSecret } = site;
// 构建 URL规避多/或少/问题
const url = this.buildURL(apiUrl, '/wp-json', endpoint);
@ -247,7 +246,7 @@ export class WPService {
site: any,
data: Record<string, any>
): Promise<Boolean> {
const apiUrl = site.wpApiUrl ?? site.apiUrl;
const apiUrl = site.apiUrl;
const { consumerKey, consumerSecret } = site;
const auth = Buffer.from(`${consumerKey}:${consumerSecret}`).toString(
'base64'
@ -347,7 +346,7 @@ export class WPService {
orderId: string,
data: Record<string, any>
) {
const apiUrl = site.wpApiUrl ?? site.apiUrl;
const apiUrl = site.apiUrl;
const { consumerKey, consumerSecret } = site;
const auth = Buffer.from(`${consumerKey}:${consumerSecret}`).toString(
'base64'
@ -375,7 +374,7 @@ export class WPService {
orderId: string,
trackingId: string,
): Promise<Boolean> {
const apiUrl = site.wpApiUrl ?? site.apiUrl;
const apiUrl = site.apiUrl;
const { consumerKey, consumerSecret } = site;
const auth = Buffer.from(`${consumerKey}:${consumerSecret}`).toString(
'base64'

View File

@ -33,7 +33,7 @@ export class WpProductService {
async syncAllSites() {
// 中文注释:从数据库获取所有启用的站点,并逐站点同步产品与变体
const { items } = await this.siteService.list({ current: 1, pageSize: 1000, isDisabled: false }, true);
const { items } = await this.siteService.list({ current: 1, pageSize: Infinity, isDisabled: false }, true);
for (const s of items as any[]) {
const site: WpSite = {
id: String(s.id),
@ -54,7 +54,7 @@ export class WpProductService {
}
}
}
// 同步一个网站
async syncSite(siteId: string) {
// 中文注释:通过数据库获取站点并转换为 WpSite用于后续 WooCommerce 同步
const site = await this.siteService.get(Number(siteId), true);