<commit_before>'use strict';

import fs from 'fs';
import path from 'path';
import Base from './base.js';

const THEME_DIR = path.join(think.RESOURCE_PATH, 'theme');

export default class extends Base {
  async getAction(){
    let themes = (await think.promisify(fs.readdir)(THEME_DIR));
    let isExist = think.promisify(fs.exist);
    themes = themes.map(theme => ({id: theme, __info_file: path.join(THEME_DIR, theme, 'package.json')}))
                   .filter(async theme => await isExist(theme.__info_file))
                   .map(({id, __info_file}) => think.extend({id}, think.require(__info_file)));
    return this.success(themes);
  }
}<commit_msg>修复获取主题接口有其它非正常主题文件时的 BUG<commit_after>'use strict';

import fs from 'fs';
import path from 'path';
import Base from './base.js';

const THEME_DIR = path.join(think.RESOURCE_PATH, 'theme');

export default class extends Base {
  async getAction(){
    let themes = (await think.promisify(fs.readdir)(THEME_DIR));

    let result = [];
    for(let theme of themes) {
      let infoFile = path.join(THEME_DIR, theme, 'package.json');
      try {
        let stat = await think.promisify(fs.stat)(infoFile);
        result.push( think.extend({id: theme}, think.require(infoFile)) );
      } catch(e) {
        console.log(e);
      }
    }
    return this.success(result);
  }
}
{'fraction_non_alphanumeric': 0.14895209580838323, 'fraction_numerical': 0.0, 'mean_word_length': 3.4566666666666666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2116558', 'n_tokens_mistral': 447, 'n_tokens_neox': 449, 'n_words': 104}