<commit_before>const fs = require('fs');
let shortid = require('shortid');
const path = require("path");
const url = require('url');

function createDir(filePath) {

  filePath = path.dirname(filePath);
  console.log('create dir ',filePath );

  if (checkExist(filePath)) {
    return true;
  }
  checkExist(filePath);
  fs.mkdirSync(filePath);
}

function checkExist(path) {
  console.log('checkExist ',path );

  try {
    return fs.statSync(path).isDirectory();
  }
  catch (err) {
    return false;
  }
}

class ServerStorage {

  constructor() {
    this.picturesPath = '../../../../dist/stored-pictures';

    this.serverType = 'local';
  }



  savePicture(bodyReqTitle, bodyReqPictureData) {

    return new Promise( (resolve, reject) => {

      //Create base64 decoded buffer
      let picData = bodyReqPictureData.replace(/^data:image\/\w+;base64,/, "");
      let decodedPicData = new Buffer(picData, 'base64');

      let uniqueID = shortid.generate();
      let generatedFileName = bodyReqTitle+''+uniqueID+".jpg";

      let fileName= this.picturesPath+'\\'+generatedFileName;
      let filePath = path.join(__dirname, fileName);

      console.log("write file: ", filePath);

      createDir(filePath);
      //this.picturesPath = storePath;

      fs.writeFile(filePath, decodedPicData, 'base64', (err) => {

        if (err) {
          generatedFileName = null;
          console.log("write error: ", err);
          reject(err);
        }
        else
        {
          resolve({
            id: generatedFileName
          });
        }
      })
    })

  }


  getPicture(fileName) {

    return new Promise( (resolve, reject) => {
      let data = null;
      //console.log('get picture ', this.picturesPath + '/' + fileName);
      fs.readFile(this.picturesPath + '/' + fileName, (err, data) => {
        if (err) {
          reject(console.log('getPicture error:', err))
        }
        else {
          data = data;
          resolve(data)
        }
      })
    })
  }

  getUrl(fileName)
  {
    return '/stored-pictures/' + path.join(fileName);

    //return `${this.picturesPath}/${fileName}`;
  }

};



module.exports = ServerStorage;<commit_msg>Fix gallery<commit_after>const fs = require('fs');
let shortid = require('shortid');
const path = require("path");
const url = require('url');

function createDir(filePath) {

  filePath = path.dirname(filePath);
  console.log('create dir ',filePath );

  if (checkExist(filePath)) {
    return true;
  }
  checkExist(filePath);
  fs.mkdirSync(filePath);
}

function checkExist(path) {
  console.log('checkExist ',path );

  try {
    return fs.statSync(path).isDirectory();
  }
  catch (err) {
    return false;
  }
}

class ServerStorage {

  constructor() {

    this.picturesPath = '../../../../dist/assets/img/';

    this.serverType = 'local';
  }



  savePicture(bodyReqTitle, bodyReqPictureData) {

    return new Promise( (resolve, reject) => {

      //Create base64 decoded buffer
      let picData = bodyReqPictureData.replace(/^data:image\/\w+;base64,/, "");
      let decodedPicData = new Buffer(picData, 'base64');

      let uniqueID = shortid.generate();
      let generatedFileName = bodyReqTitle+''+uniqueID+".jpg";

      let fileName= this.picturesPath+'\\'+generatedFileName;
      let filePath = path.join(__dirname, fileName);

      console.log("write file: ", filePath);

      createDir(filePath);
      //this.picturesPath = storePath;

      fs.writeFile(filePath, decodedPicData, 'base64', (err) => {

        if (err) {
          generatedFileName = null;
          console.log("write error: ", err);
          reject(err);
        }
        else
        {
          resolve({
            id: generatedFileName
          });
        }
      })
    })

  }


  getPicture(fileName) {

    return new Promise( (resolve, reject) => {
      let data = null;
      //console.log('get picture ', this.picturesPath + '/' + fileName);
      fs.readFile(this.picturesPath + '/' + fileName, (err, data) => {
        if (err) {
          reject(console.log('getPicture error:', err))
        }
        else {
          data = data;
          resolve(data)
        }
      })
    })
  }

  getUrl(fileName)
  {
    return '/assets/img/' + path.join(fileName);

    //return `${this.picturesPath}/${fileName}`;
  }

};



module.exports = ServerStorage;
{'fraction_non_alphanumeric': 0.15411116214974735, 'fraction_numerical': 0.0036747818098300414, 'mean_word_length': 2.42374213836478, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1078644', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1347, 'n_words': 262}