<commit_before>import UpYun from 'upyun';
import tools from 'upyun/tools';
import config from '../config';

const {upyun : upyunConfig} = config;

const upyun = new UpYun(
  upyunConfig.bucket,
  upyunConfig.operator,
  upyunConfig.password,
  upyunConfig.endpoint,
  {apiVersion: 'v2'}
);

export function uploadFile(file) {
  return new Promise((res, rej) => {
    try {
      const remoteKey = `${upyunConfig.uploadFilePrefix}/${Date.now()}-${encodeURIComponent(file.name)}`;
      upyun.putFile(remoteKey,
        file.path,
        file.type,
        true,
        {},
        (err, data) => {
          if (err) throw err;
          res(Object.assign({}, data, {remoteKey: remoteKey}));
        });
    } catch (err) {<commit_msg>Use Webp<commit_after>import UpYun from 'upyun';
import tools from 'upyun/tools';
import config from '../config';

const {upyun : upyunConfig} = config;

const upyun = new UpYun(
  upyunConfig.bucket,
  upyunConfig.operator,
  upyunConfig.password,
  upyunConfig.endpoint,
  {apiVersion: 'v2'}
);

export function uploadFile(file, options) {
  const opt = options || {};
  const useWebp = opt.webp || true;
  const uploadOptions = {};
  uploadOptions['x-gmkerl-thumb'] = '';
  if (useWebp) uploadOptions['x-gmkerl-thumb'] += '/format/webp';
  return new Promise((res, rej) => {
    try {
      const remoteKey = `${upyunConfig.uploadFilePrefix}/${Date.now()}-${encodeURIComponent(file.name)}`;
      upyun.putFile(`${upyunConfig.uploadFilePrefix}/${Date.now()}-${file.name}`,
        file.path,
        file.type,
        true,
        uploadOptions,
        (err, data) => {
          if (err) throw err;
          res(Object.assign({}, data, {remoteKey: remoteKey}));
        });
    } catch (err) {
{'fraction_non_alphanumeric': 0.16062176165803108, 'fraction_numerical': 0.0011514104778353484, 'mean_word_length': 3.1087470449172576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1769688', 'n_tokens_mistral': 600, 'n_tokens_neox': 603, 'n_words': 123}