<commit_before>var account = new Vue({
  el: '#account',

  data: {
    id: '',
    username: '',
    avatar: '',
    has_error: false,
    flash: []
  },

  computed: {
    has_error: function() {
      if (typeof this.new_password === 'undefined') {
        if (this.password == this.confirm && this.password != '') return false;
        return true;
      } else {
        if (this.password != '') return false;
        return true;
      }
    },
    has_confirm_error: function() {
      if (typeof this.new_password !== 'undefined') {
        if (this.new_password == this.confirm && this.new_password != '') return false;
        return true;
      } else {
        if (this.password == this.confirm && this.password != '') return false;
        return true;
      }
    },
    has_avatar: function() {
      if (this.avatar) return true;
      return false;
    }
  },

  created: function() {
    var _this = this;
    io.socket.get('/user/current', function (res) {
      _this.id = res.id;
      _this.username = res.username;
      _this.avatar = res.avatar;
    });
  },

  methods: {
    create: function(e) {
      e.preventDefault();

      var fd = new FormData();

      if (typeof avatarFile.files[0] !== 'undefined') {
        var base64 = avatar.src;
        // Base64からバイナリへ変換
        var bin = atob(base64.replace(/^.*,/, ''));
        var buffer = new Uint8Array(bin.length);
        for (var i = 0; i < bin.length; i++) {
          buffer[i] = bin.charCodeAt(i);
        }
        // Blobを作成
        var blob = new Blob([buffer.buffer], { type: 'image/png' });
        fd.append('avatar', blob, 'avatar.png');
      }

      // フォームのavatar以外全ての入力値をFormDataに追加
      var formArray = $(e.target).serializeArray();
      $.each(formArray, function(i, field) {
        fd.append(field['name'], field['value']);
      });

      // サーバに POST /user/create としてリクエストする
      // io.socket 経由だとFormDataを送れないため、xhrで
      var xhr = new XMLHttpRequest();
      var _this = this;
      xhr.open('POST', '/user/create');
      xhr.setRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8');
      xhr.setRequestHeader('Cache-Control', 'max-age=0');
      xhr.onload = function(evt) {
        if (xhr.status == 200) {
          _this.flash.push({ notice: JSON.parse(xhr.response).flash, status: 'alert-success' });
        } else {
          _this.flash.push({ notice: JSON.parse(xhr.response).error, status: 'alert-danger' });
          console.error(JSON.parse(xhr.response).error);
        }
      };
      xhr.send(fd);
    },

    update: function(e) {
      e.preventDefault();

      var fd = new FormData();

      if (typeof avatarFile.files[0] !== 'undefined') {
        var base64 = avatar.src;
        // Base64からバイナリへ変換
        var bin = atob(base64.replace(/^.*,/, ''));
        var buffer = new Uint8Array(bin.length);
        for (var i = 0; i < bin.length; i++) {
          buffer[i] = bin.charCodeAt(i);
        }
        // Blobを作成
        var blob = new Blob([buffer.buffer], { type: 'image/png' });
        fd.append('avatar', blob, 'avatar.png');
      }

      // フォームのavatar以外全ての入力値をFormDataに追加
      var formArray = $(e.target).serializeArray();
      $.each(formArray, function(i, field) {
        fd.append(field['name'], field['value']);
      });
<commit_msg>io.socket POST でリクエストヘッダのチェック<commit_after>var account = new Vue({
  el: '#account',

  data: {
    id: '',
    username: '',
    avatar: '',
    has_error: false,
    flash: []
  },

  computed: {
    has_error: function() {
      if (typeof this.new_password === 'undefined') {
        if (this.password == this.confirm && this.password != '') return false;
        return true;
      } else {
        if (this.password != '') return false;
        return true;
      }
    },
    has_confirm_error: function() {
      if (typeof this.new_password !== 'undefined') {
        if (this.new_password == this.confirm && this.new_password != '') return false;
        return true;
      } else {
        if (this.password == this.confirm && this.password != '') return false;
        return true;
      }
    },
    has_avatar: function() {
      if (this.avatar) return true;
      return false;
    }
  },

  created: function() {
    var _this = this;
    io.socket.get('/user/current', function (res) {
      _this.id = res.id;
      _this.username = res.username;
      _this.avatar = res.avatar;
    });
  },

  methods: {
    create: function(e) {
      e.preventDefault();

      var fd = new FormData();

      if (typeof avatarFile.files[0] !== 'undefined') {
        var base64 = avatar.src;
        // Base64からバイナリへ変換
        var bin = atob(base64.replace(/^.*,/, ''));
        var buffer = new Uint8Array(bin.length);
        for (var i = 0; i < bin.length; i++) {
          buffer[i] = bin.charCodeAt(i);
        }
        // Blobを作成
        var blob = new Blob([buffer.buffer], { type: 'image/png' });
        fd.append('avatar', blob, 'avatar.png');
      }

      // フォームのavatar以外全ての入力値をFormDataに追加
      var formArray = $(e.target).serializeArray();
      $.each(formArray, function(i, field) {
        fd.append(field['name'], field['value']);
      });

      // サーバに POST /user/create としてリクエストする
      // io.socket 経由だとFormDataを送れないため、xhrで
      // var xhr = new XMLHttpRequest();
      // var _this = this;
      // xhr.open('POST', '/user/create');
      // xhr.onload = function(evt) {
      //   if (xhr.status == 200) {
      //     _this.flash.push({ notice: JSON.parse(xhr.response).flash, status: 'alert-success' });
      //   } else {
      //     _this.flash.push({ notice: JSON.parse(xhr.response).error, status: 'alert-danger' });
      //     console.error(JSON.parse(xhr.response).error);
      //   }
      // };
      // xhr.send(fd);
      io.socket.post('/user/create', fd, function (res) {
        if (res.error) return console.error(res.error);
      });
    },

    update: function(e) {
      e.preventDefault();

      var fd = new FormData();

      if (typeof avatarFile.files[0] !== 'undefined') {
        var base64 = avatar.src;
        // Base64からバイナリへ変換
        var bin = atob(base64.replace(/^.*,/, ''));
        var buffer = new Uint8Array(bin.length);
        for (var i = 0; i < bin.length; i++) {
          buffer[i] = bin.charCodeAt(i);
        }
        // Blobを作成
        var blob = new Blob([buffer.buffer], { type: 'image/png' });
        fd.append('avatar', blob, 'avatar.png');
      }

      // フォームのavatar以外全ての入力値をFormDataに追加
      var formArray = $(e.target).serializeArray();
      $.each(formArray, function(i, field) {
        fd.append(field['name'], field['value']);
      });

{'fraction_non_alphanumeric': 0.1696562032884903, 'fraction_numerical': 0.007025411061285501, 'mean_word_length': 2.1005560704355886, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '729639', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2272, 'n_words': 442}