UNPKG

csdnsynchexo

Version:

支持csdn/博客园/掘金/segmentfault/腾讯云加社区等平台一键迁移hexo

55 lines (54 loc) 1.43 kB
import axios from 'axios'; import { error, info } from '../log/index.js'; import { transformImg } from '../utils/index.js'; export class Base { config; axios; constructor(config) { this.config = config; this.axios = axios.create(); this.axios.interceptors.request.use((c) => { info(`request: ${c.method} ${c.url}`); if (config.cookie) { Object.assign(this.headers, { cookie: config.cookie, }); } Object.assign(c.headers, this.headers); return c; }); } async run() { const list = await this.getMain(); const resultList = []; for (const id of list) { info(`拉取:${id}`); const result = await this.getDetail(id); if (result) { resultList.push(result); } } return resultList; } async getMain() { error('实现该方法'); return []; } async getDetail(id) { error('实现该方法'); return undefined; } /** * 生成文件后的操作 */ async generateSuccess(file) { if (this.config.imgConfig) { try { await transformImg.call(this, file); } catch (e) { error('图片转存失败', e); } } } }