12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.Ids = exports.IdsChannel = void 0;
- const request_1 = require("./request");
- const crypto_1 = require("crypto");
- var IdsChannel;
- (function (IdsChannel) {
- IdsChannel[IdsChannel["Csdn"] = 1] = "Csdn";
- IdsChannel[IdsChannel["Wechat"] = 2] = "Wechat";
- IdsChannel[IdsChannel["Zhihu"] = 3] = "Zhihu";
- IdsChannel[IdsChannel["Juejin"] = 4] = "Juejin";
- })(IdsChannel = exports.IdsChannel || (exports.IdsChannel = {}));
- class Ids {
- constructor(config) {
- this.config = config;
- }
- async request(config) {
- const { endpoint, accessKeyId, accessKeySecret } = this.config;
- config.baseURL = endpoint;
- config.url = config.url || '/';
- const timestamp = Math.floor(Date.now() / 1000);
- const data = config.url.toLowerCase() + timestamp;
- const signature = crypto_1.createHmac('sha256', accessKeySecret).update(data).digest('base64');
- config.headers = config.headers || {};
- config.headers['Authorization'] = `IDS-HMAC-SHA256 Credential=${accessKeyId}/${timestamp},Signature=${signature}`;
- const res = await request_1.request(config);
- if (res.data.status != 1) {
- console.error(res.data);
- throw new Error(`[${res.data.status}] ${res.data.info}`);
- }
- return res.data;
- }
- getCrawlAuthors(channel) {
- return this.request({
- method: 'POST',
- url: '/api/ids/getCrawlAuthors',
- data: {
- code: channel
- }
- });
- }
- getCrawlArticleRules(params) {
- const { ids, channel } = params;
- return this.request({
- method: 'POST',
- url: '/api/ids/getCrawlArticleRules',
- data: {
- code: channel,
- sn_codes: ids
- }
- });
- }
- putArticle(data, rule) {
- return this.request({
- method: 'POST',
- url: '/api/ids/putArticleData',
- params: {
- crawl: rule
- },
- data
- });
- }
- }
- exports.Ids = Ids;
|