var angular = require('angular');
require('../modules');

var module = angular.module('flowmodulebase.services');

module.factory('SinoFileService', function($http) {

    /**
     * 获取正文内容
     * @param  {String} fileName 名称
     * @return {Promise}
     */
    function getFileContentByFileName(fileName) {
      return $http({
        method: 'GET',
        url: '/filelist/' + fileName + '/content',
        timeout: 15000
      }).then(function(response){
        return response.data;
      });
    }

    function getInFileContentByFileName(inId) {
      return $http({
        method: 'GET',
        url: '/info/shouwen/content?inId=' + inId,
        timeout: 15000
      }).then(function(response){
        var content = response.data.content == null ? "": response.data.content.toString().trim();
        return {content: content};
      });
    }

    function isHasHongFile(fileName) {
      return $http({
        method: 'GET',
        url: '/filelist/' + fileName + '/info',
        timeout: 15000
      }).then(function(response) {
        return response.data && response.data.fileType;
      });
    }

    return {
      getFileContentByFileName: getFileContentByFileName,
      getInFileContentByFileName: getInFileContentByFileName,
      isHasHongFile: isHasHongFile
    };
});
