<commit_before>'use strict';

import Base from './base.js';

var fs = require('fs');
var path = require('path');

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
  async indexAction() {
    let videos = await this.model('video').limit(10).select();

    return this.success({
      videoList: videos
    });

  }

  async uploadAction(){
    //这里的 key 需要和 form 表单里的 name 值保持一致
    var file = think.extend({}, this.file('video'));
	let title = this.post('title');
    let create_time = this.post('create_time');
    let longitude = this.post('longitude');
    let latitude = this.post('latitude');
    let address = this.post('address');
    let creator_photo = this.post('creator_photo');
    let creator_name = this.post('creator_name');
    let creator_gender = this.post('creator_gender');
	console.log(create_time);
	
    var filepath = file.path;
	console.log(file);
	console.log(filepath);

    //文件上传后，需要将文件移动到项目其他地方，否则会在请求结束时删除掉该文件
    var uploadPath = think.RESOURCE_PATH + '/static';
    think.mkdir(uploadPath);
    var basename = path.basename(filepath);
    fs.renameSync(filepath, uploadPath + '/' + basename);

    file.path = uploadPath + '/' + basename;

    if(think.isFile(file.path)){
      console.log('is file')
    }else{
      console.log('not exist')
    }

    this.assign('fileInfo', file);
	console.log(file.path);
	
	var fileUrl = "http://47.93.241.248/static/" + basename;
	
	let user = await this.model('user').where({photo_url: creator_photo, name: creator_name}).find();
	if (think.isEmpty(user)) {
	    let userResult = await this.model('user').add({
            gender: creator_gender,
            account: 'Wx'+creator_name,
            name: creator_name,
            photo_url: creator_photo,
            reg_time: parseInt(new Date().getTime() / 1000)
        });
	    console.log(userResult);
		user = await this.model('user').where({photo_url: creator_photo, name: creator_name}).find();
	}
	
	let news = await this.model('news').where({latitude: latitude, longitude: longitude}).find();
	if (think.isEmpty(news)) {
	    let newsResult = await this.model('news').add({
            title: title,
            create_time: create_time,
            longitude: longitude,
            latitude: latitude,
            location: address
        });
	    console.log(newsResult);
		news = await this.model('news').where({latitude: latitude, longitude: longitude}).find();
	}
	
	let videoResult = await this.model('user').add({
        creator: user[0].id,
		title: title,
        news_id: news[0].id,
        create_time: create_time,
        longitude: longitude,
        latitude: latitude,
		poster_url: '',
        video_url: fileUrl
    });
	console.log(videoResult);

    this.display();
  }
}<commit_msg>Testt<commit_after>'use strict';

import Base from './base.js';

var fs = require('fs');
var path = require('path');

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
  async indexAction() {
    let videos = await this.model('video').limit(10).select();

    return this.success({
      videoList: videos
    });

  }

  async uploadAction(){
    //这里的 key 需要和 form 表单里的 name 值保持一致
    var file = think.extend({}, this.file('video'));
	let title = this.post('title');
    let create_time = this.post('create_time');
    let longitude = this.post('longitude');
    let latitude = this.post('latitude');
    let address = this.post('address');
    let creator_photo = this.post('creator_photo');
    let creator_name = this.post('creator_name');
    let creator_gender = this.post('creator_gender');
	console.log(create_time);
	
    var filepath = file.path;
	console.log(file);
	console.log(filepath);

    //文件上传后，需要将文件移动到项目其他地方，否则会在请求结束时删除掉该文件
    var uploadPath = think.RESOURCE_PATH + '/static';
    think.mkdir(uploadPath);
    var basename = path.basename(filepath);
    fs.renameSync(filepath, uploadPath + '/' + basename);

    file.path = uploadPath + '/' + basename;

    if(think.isFile(file.path)){
      console.log('is file')
    }else{
      console.log('not exist')
    }

    this.assign('fileInfo', file);
	console.log(file.path);
	
	var fileUrl = "http://47.93.241.248/static/" + basename;
	console.log(fileUrl);
	
	let user = await this.model('user').where({photo_url: creator_photo, name: creator_name}).find();
	if (think.isEmpty(user)) {
	    let userResult = await this.model('user').add({
            gender: creator_gender,
            account: 'Wx'+creator_name,
            name: creator_name,
            photo_url: creator_photo,
            reg_time: parseInt(new Date().getTime() / 1000)
        });
	    console.log(userResult);
		user = await this.model('user').where({photo_url: creator_photo, name: creator_name}).find();
	}
	console.log(user);
	
	let news = await this.model('news').where({latitude: latitude, longitude: longitude}).find();
	if (think.isEmpty(news)) {
	    let newsResult = await this.model('news').add({
            title: title,
            create_time: create_time,
            longitude: longitude,
            latitude: latitude,
            location: address
        });
	    console.log(newsResult);
		news = await this.model('news').where({latitude: latitude, longitude: longitude}).find();
	}
	console.log(news);
	
	let videoResult = await this.model('user').add({
        creator: user.id,
		title: title,
        news_id: news.id,
        create_time: create_time,
        longitude: longitude,
        latitude: latitude,
		poster_url: 'https://tva3.sinaimg.cn/crop.0.0.1125.1125.180/cc981db8jw8f1oifzwvxqj20v90v941q.jpg',
        video_url: fileUrl
    });
	console.log(videoResult);

    this.display();
  }
}
{'fraction_non_alphanumeric': 0.15264633718892395, 'fraction_numerical': 0.01069050122677883, 'mean_word_length': 3.024682651622003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6245869', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1858, 'n_words': 374}