@gt6/sdk 1.0.24 → 1.0.25

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.
@@ -103,6 +103,12 @@ class ArticlesAPI {
103
103
  async getArticle(articleId) {
104
104
  return this.client.request(`/articles/${articleId}.json`);
105
105
  }
106
+ /**
107
+ * 1.1 根据文章ID获取文章详情(使用上级平台ID)
108
+ */
109
+ async getArticle_p(articleId) {
110
+ return this.client.request(`/parentarticles/${articleId}.json`);
111
+ }
106
112
  /**
107
113
  * 2. 获取文章分类列表
108
114
  */
@@ -112,6 +118,15 @@ class ArticlesAPI {
112
118
  const response = await this.client.request(`/article-categories/platform-${config.platformId}-root-${categoryId}.json`);
113
119
  return response.categories;
114
120
  }
121
+ /**
122
+ * 2.1 获取文章分类列表(使用下级平台ID)
123
+ */
124
+ async getCategories_p(rootCategoryId_p) {
125
+ const config = this.client.getConfig();
126
+ const categoryId = rootCategoryId_p || config.rootCategoryId_p || '671920';
127
+ const response = await this.client.request(`/article-categories/platform-${config.platformId_p}-root-${categoryId}.json`);
128
+ return response.categories;
129
+ }
115
130
  /**
116
131
  * 3. 获取文章标签列表
117
132
  */
@@ -121,6 +136,15 @@ class ArticlesAPI {
121
136
  const response = await this.client.request(`/article-tags/platform-${config.platformId}-${alias}.json`);
122
137
  return response.tags;
123
138
  }
139
+ /**
140
+ * 3.1 获取文章标签列表(使用下级平台ID)
141
+ */
142
+ async getTags_p(tagAlias_p) {
143
+ const config = this.client.getConfig();
144
+ const alias = tagAlias_p || config.tagAlias_p || '001';
145
+ const response = await this.client.request(`/article-tags/platform-${config.platformId_p}-${alias}.json`);
146
+ return response.tags;
147
+ }
124
148
  /**
125
149
  * 4. 根据分类ID获取文章列表
126
150
  * 支持单个分类ID或分类ID数组
@@ -167,6 +191,98 @@ class ArticlesAPI {
167
191
  limit
168
192
  };
169
193
  }
194
+ /**
195
+ * 4.1 根据分类ID获取文章列表
196
+ * 支持单个分类ID或分类ID数组
197
+ */
198
+ async getArticlesByCategory_p(categoryId, options) {
199
+ // 获取分类数据
200
+ const categories = await this.getCategories_p();
201
+ // 将单个分类ID转换为数组
202
+ const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
203
+ // 收集所有指定分类下的文章ID
204
+ const allArticleIds = [];
205
+ categoryIds.forEach(id => {
206
+ const targetCategory = categories.find(cat => cat.categoryId === id);
207
+ if (targetCategory) {
208
+ allArticleIds.push(...targetCategory.articleIds);
209
+ }
210
+ });
211
+ // 去重
212
+ const uniqueArticleIds = [...new Set(allArticleIds)];
213
+ if (uniqueArticleIds.length === 0) {
214
+ return {
215
+ articles: [],
216
+ total: 0,
217
+ page: options?.page || 1,
218
+ limit: options?.limit || 10
219
+ };
220
+ }
221
+ // 应用分页
222
+ const page = options?.page || 1;
223
+ const limit = options?.limit || 10;
224
+ const offset = (page - 1) * limit;
225
+ const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
226
+ // 获取文章详情
227
+ const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
228
+ // 应用状态过滤
229
+ let filteredArticles = articles;
230
+ if (options?.status) {
231
+ filteredArticles = articles.filter(article => article.status === options.status);
232
+ }
233
+ return {
234
+ articles: filteredArticles,
235
+ total: uniqueArticleIds.length,
236
+ page,
237
+ limit
238
+ };
239
+ }
240
+ /**
241
+ * 4.2 根据分类ID获取文章列表
242
+ * 支持单个分类ID或分类ID数组
243
+ */
244
+ async getArticlesByCategory_t(categoryId, options) {
245
+ // 获取分类数据
246
+ const categories = await this.getCategories();
247
+ // 将单个分类ID转换为数组
248
+ const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
249
+ // 收集所有指定分类下的文章ID
250
+ const allArticleIds = [];
251
+ categoryIds.forEach(id => {
252
+ const targetCategory = categories.find(cat => cat.categoryId === id);
253
+ if (targetCategory) {
254
+ allArticleIds.push(...targetCategory.articleIds);
255
+ }
256
+ });
257
+ // 去重
258
+ const uniqueArticleIds = [...new Set(allArticleIds)];
259
+ if (uniqueArticleIds.length === 0) {
260
+ return {
261
+ articles: [],
262
+ total: 0,
263
+ page: options?.page || 1,
264
+ limit: options?.limit || 10
265
+ };
266
+ }
267
+ // 应用分页
268
+ const page = options?.page || 1;
269
+ const limit = options?.limit || 10;
270
+ const offset = (page - 1) * limit;
271
+ const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
272
+ // 获取文章详情
273
+ const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
274
+ // 应用状态过滤
275
+ let filteredArticles = articles;
276
+ if (options?.status) {
277
+ filteredArticles = articles.filter(article => article.status === options.status);
278
+ }
279
+ return {
280
+ articles: filteredArticles,
281
+ total: uniqueArticleIds.length,
282
+ page,
283
+ limit
284
+ };
285
+ }
170
286
  /**
171
287
  * 5. 根据标签ID获取文章列表
172
288
  * 支持单个标签ID或标签ID数组
@@ -213,6 +329,98 @@ class ArticlesAPI {
213
329
  limit
214
330
  };
215
331
  }
332
+ /**
333
+ * 5.1 根据标签ID获取文章列表
334
+ * 支持单个标签ID或标签ID数组
335
+ */
336
+ async getArticlesByTag_p(tagId, options) {
337
+ // 获取标签数据,传递tagAlias参数
338
+ const tags = await this.getTags_p(options?.tagAlias);
339
+ // 将单个标签ID转换为数组
340
+ const tagIds = Array.isArray(tagId) ? tagId : [tagId];
341
+ // 收集所有指定标签下的文章ID
342
+ const allArticleIds = [];
343
+ tagIds.forEach(id => {
344
+ const targetTag = tags.find(tag => tag.tagId === id);
345
+ if (targetTag) {
346
+ allArticleIds.push(...targetTag.articleIds);
347
+ }
348
+ });
349
+ // 去重
350
+ const uniqueArticleIds = [...new Set(allArticleIds)];
351
+ if (uniqueArticleIds.length === 0) {
352
+ return {
353
+ articles: [],
354
+ total: 0,
355
+ page: options?.page || 1,
356
+ limit: options?.limit || 10
357
+ };
358
+ }
359
+ // 应用分页
360
+ const page = options?.page || 1;
361
+ const limit = options?.limit || 10;
362
+ const offset = (page - 1) * limit;
363
+ const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
364
+ // 获取文章详情
365
+ const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
366
+ // 应用状态过滤
367
+ let filteredArticles = articles;
368
+ if (options?.status) {
369
+ filteredArticles = articles.filter(article => article.status === options.status);
370
+ }
371
+ return {
372
+ articles: filteredArticles,
373
+ total: uniqueArticleIds.length,
374
+ page,
375
+ limit
376
+ };
377
+ }
378
+ /**
379
+ * 5.2 根据标签ID获取文章列表
380
+ * 支持单个标签ID或标签ID数组
381
+ */
382
+ async getArticlesByTag_t(tagId, options) {
383
+ // 获取标签数据,传递tagAlias参数
384
+ const tags = await this.getTags(options?.tagAlias);
385
+ // 将单个标签ID转换为数组
386
+ const tagIds = Array.isArray(tagId) ? tagId : [tagId];
387
+ // 收集所有指定标签下的文章ID
388
+ const allArticleIds = [];
389
+ tagIds.forEach(id => {
390
+ const targetTag = tags.find(tag => tag.tagId === id);
391
+ if (targetTag) {
392
+ allArticleIds.push(...targetTag.articleIds);
393
+ }
394
+ });
395
+ // 去重
396
+ const uniqueArticleIds = [...new Set(allArticleIds)];
397
+ if (uniqueArticleIds.length === 0) {
398
+ return {
399
+ articles: [],
400
+ total: 0,
401
+ page: options?.page || 1,
402
+ limit: options?.limit || 10
403
+ };
404
+ }
405
+ // 应用分页
406
+ const page = options?.page || 1;
407
+ const limit = options?.limit || 10;
408
+ const offset = (page - 1) * limit;
409
+ const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
410
+ // 获取文章详情
411
+ const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
412
+ // 应用状态过滤
413
+ let filteredArticles = articles;
414
+ if (options?.status) {
415
+ filteredArticles = articles.filter(article => article.status === options.status);
416
+ }
417
+ return {
418
+ articles: filteredArticles,
419
+ total: uniqueArticleIds.length,
420
+ page,
421
+ limit
422
+ };
423
+ }
216
424
  /**
217
425
  * 6. 根据分类ID获取该分类的层级路径
218
426
  * 用于前端面包屑导航
@@ -2329,30 +2537,72 @@ class GT6SDK {
2329
2537
  async getArticle(articleId) {
2330
2538
  return this.articles.getArticle(articleId);
2331
2539
  }
2540
+ /**
2541
+ * 1.1. 便捷方法:根据文章ID获取文章详情(使用上级平台ID)
2542
+ */
2543
+ async getArticle_p(articleId) {
2544
+ return this.articles.getArticle_p(articleId);
2545
+ }
2332
2546
  /**
2333
2547
  * 2. 便捷方法:获取文章分类列表
2334
2548
  */
2335
2549
  async getCategories(rootCategoryId) {
2336
2550
  return this.articles.getCategories(rootCategoryId);
2337
2551
  }
2552
+ /**
2553
+ * 2.1. 便捷方法:获取文章分类列表(使用下级平台ID)
2554
+ */
2555
+ async getCategories_p(rootCategoryId_p) {
2556
+ return this.articles.getCategories_p(rootCategoryId_p);
2557
+ }
2338
2558
  /**
2339
2559
  * 3. 便捷方法:获取文章标签列表
2340
2560
  */
2341
2561
  async getTags(tagAlias) {
2342
2562
  return this.articles.getTags(tagAlias);
2343
2563
  }
2564
+ /**
2565
+ * 3.1. 便捷方法:获取文章标签列表(使用下级平台ID)
2566
+ */
2567
+ async getTags_p(tagAlias_p) {
2568
+ return this.articles.getTags_p(tagAlias_p);
2569
+ }
2344
2570
  /**
2345
2571
  * 4. 便捷方法:根据分类ID获取文章列表
2346
2572
  */
2347
2573
  async getArticlesByCategory(categoryId, options) {
2348
2574
  return this.articles.getArticlesByCategory(categoryId, options);
2349
2575
  }
2576
+ /**
2577
+ * 4.1. 便捷方法:根据分类ID获取文章列表(使用下级平台ID)
2578
+ */
2579
+ async getArticlesByCategory_p(categoryId, options) {
2580
+ return this.articles.getArticlesByCategory_p(categoryId, options);
2581
+ }
2582
+ /**
2583
+ * 4.2. 便捷方法:根据分类ID获取文章列表(使用当前分类数据)
2584
+ */
2585
+ async getArticlesByCategory_t(categoryId, options) {
2586
+ return this.articles.getArticlesByCategory_t(categoryId, options);
2587
+ }
2350
2588
  /**
2351
2589
  * 5. 便捷方法:根据标签ID获取文章列表
2352
2590
  */
2353
2591
  async getArticlesByTag(tagId, options) {
2354
2592
  return this.articles.getArticlesByTag(tagId, options);
2355
2593
  }
2594
+ /**
2595
+ * 5.1. 便捷方法:根据标签ID获取文章列表(使用下级平台ID)
2596
+ */
2597
+ async getArticlesByTag_p(tagId, options) {
2598
+ return this.articles.getArticlesByTag_p(tagId, options);
2599
+ }
2600
+ /**
2601
+ * 5.2. 便捷方法:根据标签ID获取文章列表(使用当前标签数据)
2602
+ */
2603
+ async getArticlesByTag_t(tagId, options) {
2604
+ return this.articles.getArticlesByTag_t(tagId, options);
2605
+ }
2356
2606
  /**
2357
2607
  * 6. 便捷方法:根据分类ID获取该分类的层级路径
2358
2608
  */