<commit_before>import fs from 'fs';
import Base from './base';
import request from 'request';

request.defaults({
  strictSSL: false,
  rejectUnauthorized: false
});

const getFileContent = think.promisify(request.get, request);
const putFileContent = think.promisify(fs.writeFile, fs);

export default class extends Base {
  async uploadMethod(url, {name}) {
    let result = await getFileContent({
      url,
      headers: {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) Chrome/47.0.2526.111 Safari/537.36"
      },
      strictSSL: false,
      timeout: 1000,
      encoding: 'binary'
    }).catch(() => throw Error("UPLOAD_URL_ERROR"));

    if(result.headers["content-type"].indexOf('image') === -1) {
      throw Error('UPLOAD_TYPE_ERROR');
    }

    let destDir = this.formatNow();
    let basename = (name ? name : think.md5(result.body)) + path.extname(url);
    let destPath = path.join( think.UPLOAD_PATH, destDir );

    if( !think.isDir(destPath) ) {
      think.mkdir(destPath);
    }

    result = await putFileContent( path.join(destPath, basename), result.body, 'binary');
    return path.join('/static/upload', destDir, basename);
  }

  async run(file, config) {
    return await this.uploadMethod(file, config);
  }
}<commit_msg>fix 语法问题 (#191)<commit_after>import fs from 'fs';
import Base from './base';
import request from 'request';

request.defaults({
  strictSSL: false,
  rejectUnauthorized: false
});

const getFileContent = think.promisify(request.get, request);
const putFileContent = think.promisify(fs.writeFile, fs);

export default class extends Base {
  async uploadMethod(url, {name}) {
    let result = await getFileContent({
      url,
      headers: {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) Chrome/47.0.2526.111 Safari/537.36"
      },
      strictSSL: false,
      timeout: 1000,
      encoding: 'binary'
    }).catch(() => { throw Error("UPLOAD_URL_ERROR"); });

    if(result.headers["content-type"].indexOf('image') === -1) {
      throw Error('UPLOAD_TYPE_ERROR');
    }

    let destDir = this.formatNow();
    let basename = (name ? name : think.md5(result.body)) + path.extname(url);
    let destPath = path.join( think.UPLOAD_PATH, destDir );

    if( !think.isDir(destPath) ) {
      think.mkdir(destPath);
    }

    result = await putFileContent( path.join(destPath, basename), result.body, 'binary');
    return path.join('/static/upload', destDir, basename);
  }

  async run(file, config) {
    return await this.uploadMethod(file, config);
  }
}
{'fraction_non_alphanumeric': 0.14849550605705353, 'fraction_numerical': 0.023055881203595155, 'mean_word_length': 3.499121265377856, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4493568', 'n_tokens_mistral': 874, 'n_tokens_neox': 838, 'n_words': 196}