<commit_before><?php
/**
 * RemoteStorage base class
 *
 * @author <NAME> <<EMAIL>>
 */

class RemoteStorage {
  private $picturesBaseUrl;
  private $api;
  private $token;
  function __construct($setPicturesBaseUrl, $setApi, $setToken) {
    $this->picturesBaseUrl = $setPicturesBaseUrl;
    $this->api = $setApi;
    $this->token = $setToken;
  }
  function doCurl($verb, $remotePath, $dataFile=null) {
    getLogger()->warn("doCurl {$verb} {$this->picturesBaseUrl} {$remotePath} {$dataFile}");
    $ch = curl_init($this->picturesBaseUrl.$remotePath);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$this->token));
    curl_setopt($ch, CURLOPT_HEADER, 0);
    if($verb=='PUT') {
      curl_setopt($ch, CURLOPT_PUT, 1);
      $fp = fopen($dataFile, 'r');
      if($fp) {
        curl_setopt($ch, CURLOPT_INFILE, $fp);
        curl_setopt($ch, CURLOPT_INFILESIZE, filesize($dataFile));
      } else {
        return false;
      }
    } else if($verb=='GET') {
      $fp = fopen($dataFile, 'w');
      if($fp) {
        curl_setopt($ch, CURLOPT_FILE, $fp);
      } else {
        return false;
      }
    } else {
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $verb);
    }
    $result = curl_exec($ch);
    $resultCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    var_dump($result);
    var_dump($resultCode);
    return $result;
  }
  private function adaptForLegacyStorage($remotePath) {
     return '/'.implode('_', explode('/', implode('__', explode('_', substr($remotePath, 1)))));
  }
  function deleteItem($remotePath) {
    $remotePath = $this->adaptForLegacyStorage($remotePath);
    getLogger()->warn("deleteItem {$remotePath}");
    $result = $this->doCurl('DELETE', $remotePath);
    //return $result;
    return true; 
  }
  function fetchItem($remotePath, $localPath) {
    $remotePath = $this->adaptForLegacyStorage($remotePath);
    getLogger()->warn("fetchItemSync {$remotePath} {$localPath}");
    $result = $this->doCurl('GET', $remotePath, $localPath);
    return $result;
  }
  function pushItem($localPath, $remotePath) {
    $remotePath = $this->adaptForLegacyStorage($remotePath);
    getLogger()->warn("pushItemSync {$localPath} {$remotePath}");
    $result = $this->doCurl('PUT', $remotePath, $localPath);
    return $result;
  }
}
<commit_msg>log instead of var_dump CURL resposne<commit_after><?php
/**
 * RemoteStorage base class
 *
 * @author <NAME> <<EMAIL>>
 */

class RemoteStorage {
  private $picturesBaseUrl;
  private $api;
  private $token;
  function __construct($setPicturesBaseUrl, $setApi, $setToken) {
    $this->picturesBaseUrl = $setPicturesBaseUrl;
    $this->api = $setApi;
    $this->token = $setToken;
  }
  function doCurl($verb, $remotePath, $dataFile=null) {
    getLogger()->warn("doCurl {$verb} {$this->picturesBaseUrl} {$remotePath} {$dataFile}");
    $ch = curl_init($this->picturesBaseUrl.$remotePath);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$this->token));
    curl_setopt($ch, CURLOPT_HEADER, 0);
    if($verb=='PUT') {
      curl_setopt($ch, CURLOPT_PUT, 1);
      $fp = fopen($dataFile, 'r');
      if($fp) {
        curl_setopt($ch, CURLOPT_INFILE, $fp);
        curl_setopt($ch, CURLOPT_INFILESIZE, filesize($dataFile));
      } else {
        return false;
      }
    } else if($verb=='GET') {
      $fp = fopen($dataFile, 'w');
      if($fp) {
        curl_setopt($ch, CURLOPT_FILE, $fp);
      } else {
        return false;
      }
    } else {
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $verb);
    }
    $result = curl_exec($ch);
    $resultCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    getLogger()->warn('result '.var_export($resultCode, true).': '.var_export($result, true));
    return $result;
  }
  private function adaptForLegacyStorage($remotePath) {
     return '/'.implode('_', explode('/', implode('__', explode('_', substr($remotePath, 1)))));
  }
  function deleteItem($remotePath) {
    $remotePath = $this->adaptForLegacyStorage($remotePath);
    getLogger()->warn("deleteItem {$remotePath}");
    $result = $this->doCurl('DELETE', $remotePath);
    //return $result;
    return true; 
  }
  function fetchItem($remotePath, $localPath) {
    $remotePath = $this->adaptForLegacyStorage($remotePath);
    getLogger()->warn("fetchItemSync {$remotePath} {$localPath}");
    $result = $this->doCurl('GET', $remotePath, $localPath);
    return $result;
  }
  function pushItem($localPath, $remotePath) {
    $remotePath = $this->adaptForLegacyStorage($remotePath);
    getLogger()->warn("pushItemSync {$localPath} {$remotePath}");
    $result = $this->doCurl('PUT', $remotePath, $localPath);
    return $result;
  }
}

{'fraction_non_alphanumeric': 0.17538332283133795, 'fraction_numerical': 0.0016803192606595252, 'mean_word_length': 3.986387434554974, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 42, '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': '7554429', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1600, 'n_words': 288}