Bladeren bron

feat: ids: add putProvider, putSolution

Acathur 4 jaren geleden
bovenliggende
commit
3265afae31
6 gewijzigde bestanden met toevoegingen van 190 en 7 verwijderingen
  1. 60 0
      dist/lib/ids.d.ts
  2. 35 2
      dist/lib/ids.js
  3. 1 1
      dist/lib/index.d.ts
  4. 3 1
      dist/lib/index.js
  5. 90 2
      src/lib/ids.ts
  6. 1 1
      src/lib/index.ts

+ 60 - 0
dist/lib/ids.d.ts

@@ -29,6 +29,64 @@ export interface IdsArticle {
     external_like_num?: number;
     external_comment_num?: number;
 }
+export declare enum IdsSource {
+    Manual = 0,
+    User = 1,
+    AliyunMarket = 2,
+    TencentCloudMarket = 3,
+    HuaweiCloudMarket = 4,
+    Xiniu = 6,
+    Website = 7
+}
+export interface IdsProvider {
+    name: string;
+    short_name?: string;
+    tel?: string;
+    email?: string;
+    logo?: string;
+    description?: string;
+    service_time?: string;
+    source: IdsSource;
+    source_pid: string | number;
+    source_url?: string;
+}
+export interface IdsSolutionExtra {
+    api_gateway: {
+        service_id: string;
+        api_id: string;
+        dep_api_id?: string[];
+    };
+    icon_padding?: number;
+}
+export interface IdsSolution {
+    uid: number;
+    title: string;
+    description: string;
+    images: string;
+    details: string;
+    plain_text?: string;
+    service_type?: string[];
+    dimension: 1 | 2;
+    status: number;
+    source: IdsSource;
+    source_id: string;
+    source_pid: string;
+    source_dt?: string;
+    source_url: string;
+    source_tags?: string[];
+    source_labels?: string;
+    ext_sold?: number;
+    ext_score?: number;
+    skus?: any[];
+    api?: any[];
+    doc_path?: string;
+    is_signed?: 1 | 0;
+    type?: 'gateway';
+    min_price?: number;
+    max_price?: number;
+    extra?: IdsSolutionExtra | string;
+}
+export declare const randomtail: () => string;
 export declare class Ids {
     config: IdsConfig;
     constructor(config: IdsConfig);
@@ -39,4 +97,6 @@ export declare class Ids {
         channel: IdsChannel;
     }): Promise<any>;
     putArticle(data: IdsArticle, rule: IdsCrawlRule): Promise<any>;
+    putProvider(data: IdsProvider): Promise<any>;
+    putSolution(data: IdsSolution): Promise<any>;
 }

+ 35 - 2
dist/lib/ids.js

@@ -1,6 +1,6 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.Ids = exports.IdsChannel = void 0;
+exports.Ids = exports.randomtail = exports.IdsSource = exports.IdsChannel = void 0;
 const request_1 = require("./request");
 const crypto_1 = require("crypto");
 var IdsChannel;
@@ -10,6 +10,20 @@ var IdsChannel;
     IdsChannel[IdsChannel["Zhihu"] = 3] = "Zhihu";
     IdsChannel[IdsChannel["Juejin"] = 4] = "Juejin";
 })(IdsChannel = exports.IdsChannel || (exports.IdsChannel = {}));
+var IdsSource;
+(function (IdsSource) {
+    IdsSource[IdsSource["Manual"] = 0] = "Manual";
+    IdsSource[IdsSource["User"] = 1] = "User";
+    IdsSource[IdsSource["AliyunMarket"] = 2] = "AliyunMarket";
+    IdsSource[IdsSource["TencentCloudMarket"] = 3] = "TencentCloudMarket";
+    IdsSource[IdsSource["HuaweiCloudMarket"] = 4] = "HuaweiCloudMarket";
+    IdsSource[IdsSource["Xiniu"] = 6] = "Xiniu";
+    IdsSource[IdsSource["Website"] = 7] = "Website";
+})(IdsSource = exports.IdsSource || (exports.IdsSource = {}));
+const randomtail = () => {
+    return `_=${crypto_1.randomBytes(8).toString('hex')}`;
+};
+exports.randomtail = randomtail;
 class Ids {
     constructor(config) {
         this.config = config;
@@ -57,7 +71,26 @@ class Ids {
         data.external_comment_num = data.external_comment_num || 0;
         return this.request({
             method: 'POST',
-            url: `/api/ids/putArticleData?crawl=${rule}`,
+            url: `/api/ids/putArticleData?crawl=${rule}&${exports.randomtail()}`,
+            data
+        });
+    }
+    putProvider(data) {
+        return this.request({
+            method: 'POST',
+            url: `/api/ids/putSourceData?${exports.randomtail()}`,
+            data
+        });
+    }
+    putSolution(data) {
+        data.ext_sold = data.ext_sold || 0;
+        data.ext_score = data.ext_score || 0;
+        if (data.extra && typeof data.extra === 'object') {
+            data.extra = JSON.stringify(data.extra);
+        }
+        return this.request({
+            method: 'POST',
+            url: `/api/ids/putSolutionData?${exports.randomtail()}`,
             data
         });
     }

+ 1 - 1
dist/lib/index.d.ts

@@ -1,3 +1,3 @@
 export { request } from './request';
-export { Ids, IdsConfig, IdsChannel, IdsCrawlRule, IdsArticle } from './ids';
+export { Ids, IdsConfig, IdsChannel, IdsCrawlRule, IdsArticle, IdsSource, IdsProvider, IdsSolutionExtra, IdsSolution, randomtail } from './ids';
 export { unique, randomRange, autoSleep, sleep } from './misc';

+ 3 - 1
dist/lib/index.js

@@ -1,11 +1,13 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.sleep = exports.autoSleep = exports.randomRange = exports.unique = exports.IdsChannel = exports.Ids = exports.request = void 0;
+exports.sleep = exports.autoSleep = exports.randomRange = exports.unique = exports.randomtail = exports.IdsSource = exports.IdsChannel = exports.Ids = exports.request = void 0;
 var request_1 = require("./request");
 Object.defineProperty(exports, "request", { enumerable: true, get: function () { return request_1.request; } });
 var ids_1 = require("./ids");
 Object.defineProperty(exports, "Ids", { enumerable: true, get: function () { return ids_1.Ids; } });
 Object.defineProperty(exports, "IdsChannel", { enumerable: true, get: function () { return ids_1.IdsChannel; } });
+Object.defineProperty(exports, "IdsSource", { enumerable: true, get: function () { return ids_1.IdsSource; } });
+Object.defineProperty(exports, "randomtail", { enumerable: true, get: function () { return ids_1.randomtail; } });
 var misc_1 = require("./misc");
 Object.defineProperty(exports, "unique", { enumerable: true, get: function () { return misc_1.unique; } });
 Object.defineProperty(exports, "randomRange", { enumerable: true, get: function () { return misc_1.randomRange; } });

+ 90 - 2
src/lib/ids.ts

@@ -1,5 +1,5 @@
 import { request, RequestConfig } from './request'
-import { createHmac } from 'crypto'
+import { createHmac, randomBytes } from 'crypto'
 
 export interface IdsConfig {
   endpoint: string
@@ -36,6 +36,71 @@ export interface IdsArticle {
   external_comment_num?: number
 }
 
+export enum IdsSource {
+  Manual = 0,
+  User = 1,
+  AliyunMarket = 2,
+  TencentCloudMarket = 3,
+  HuaweiCloudMarket = 4,
+  Xiniu = 6,
+  Website = 7,
+}
+
+export interface IdsProvider {
+  name: string
+  short_name?: string
+  tel?: string
+  email?: string
+  logo?: string
+  description?: string
+  service_time?: string
+  source: IdsSource
+  source_pid: string | number
+  source_url?: string
+}
+
+export interface IdsSolutionExtra {
+  api_gateway: {
+    service_id: string
+    api_id: string
+    dep_api_id?: string[]
+  }
+  icon_padding?: number
+}
+
+export interface IdsSolution {
+  uid: number
+  title: string
+  description: string
+  images: string
+  details: string
+  plain_text?: string
+  service_type?: string[]
+  dimension: 1 | 2
+  status: number
+  source: IdsSource
+  source_id: string
+  source_pid: string
+  source_dt?: string
+  source_url: string
+  source_tags?: string[]
+  source_labels?: string
+  ext_sold?: number
+  ext_score?: number
+  skus?: any[]
+  api?: any[]
+  doc_path?: string
+  is_signed?: 1 | 0
+  type?: 'gateway'
+  min_price?: number
+  max_price?: number
+  extra?: IdsSolutionExtra | string
+}
+
+export const randomtail = () => {
+  return `_=${randomBytes(8).toString('hex')}`
+}
+
 export class Ids {
   config: IdsConfig
 
@@ -96,7 +161,30 @@ export class Ids {
 
     return this.request({
       method: 'POST',
-      url: `/api/ids/putArticleData?crawl=${rule}`,
+      url: `/api/ids/putArticleData?crawl=${rule}&${randomtail()}`,
+      data
+    })
+  }
+
+  putProvider(data: IdsProvider) {
+    return this.request({
+      method: 'POST',
+      url: `/api/ids/putSourceData?${randomtail()}`,
+      data
+    })
+  }
+
+  putSolution(data: IdsSolution) {
+    data.ext_sold = data.ext_sold || 0
+    data.ext_score = data.ext_score || 0
+
+    if (data.extra && typeof data.extra === 'object') {
+      data.extra = JSON.stringify(data.extra)
+    }
+
+    return this.request({
+      method: 'POST',
+      url: `/api/ids/putSolutionData?${randomtail()}`,
       data
     })
   }

+ 1 - 1
src/lib/index.ts

@@ -1,3 +1,3 @@
 export { request } from './request'
-export { Ids, IdsConfig, IdsChannel, IdsCrawlRule, IdsArticle } from './ids'
+export { Ids, IdsConfig, IdsChannel, IdsCrawlRule, IdsArticle, IdsSource, IdsProvider, IdsSolutionExtra, IdsSolution, randomtail } from './ids'
 export { unique, randomRange, autoSleep, sleep } from './misc'