<commit_before>import React, { Component } from 'react'
import classNames from 'classnames'
import filesize from 'filesize'
import { Link } from 'react-router'

import styles from '../styles/table'
import { translate } from '../lib/I18n'
import FilenameInput from '../components/FilenameInput'

const splitFilename = filename => {
  let dotIdx = filename.lastIndexOf('.') - 1 >>> 0
  return {
    extension: filename.slice(dotIdx + 1),
    filename: filename.slice(0, dotIdx + 1)
  }
}

const isDir = attrs => attrs.type === 'directory'

const getClassFromMime = attrs => {
  if (isDir(attrs)) {
    return styles['fil-file-folder']
  }
  return styles['fil-file-' + attrs.mime.split('/')[0]] || styles['fil-file-files']
}

class File extends Component {
  constructor (props) {
    super(props)
    this.state = {
      editing: props.attributes.isNew === true
    }
  }

  componentWillReceiveProps (newProps) {
    if (newProps.attributes.isNew === true && !this.props.attributes.isNew) {
      this.setState({
        editing: true
      })
    }
  }

  edit (value) {
    this.props.onEdit(value, this.props.attributes)
    this.setState({
      editing: false
    })
  }

  render ({ t, f, attributes, isFetching }, { editing }) {
    return (
      <tr>
        {this.renderFilenameCell(attributes, editing, isFetching)}
        <td>
          <time datetime=''>{ f(attributes.created_at, 'MMM D, YYYY') }</time>
        </td>
        <td>
          {isDir(attributes)
            ? '-'
            : filesize(attributes.size)}
        </td>
        <td>—</td>
      </tr>
    )
  }

  renderFilenameCell (attributes, editing, isFetching) {
    const { filename, extension } = splitFilename(attributes.name)
    const classes = classNames(styles['fil-content-file'], getClassFromMime(attributes))
    if (editing) {
      return (
        <td class={classes}>
          <FilenameInput name={attributes.name} onSubmit={val => this.edit(val)} />
        </td>
      )
    }
    return isDir(attributes)
      ? (
        <td class={classes}>
          <Link to={`/files/${attributes.id}`}>
            {attributes.name}
            {isFetching && <div class={styles['fil-loading']} />}
          </Link>
        </td>
      )
      : <td class={classes}><a target='_blank' href={`http://cozy.local:8080/files/download/${attributes.id}`}>{filename}<span class={styles['fil-content-ext']}>{extension}</span></a></td>
  }
}

export default translate()(File)
<commit_msg>[fix] Use base 10 for file size computing<commit_after>import React, { Component } from 'react'
import classNames from 'classnames'
import filesize from 'filesize'
import { Link } from 'react-router'

import styles from '../styles/table'
import { translate } from '../lib/I18n'
import FilenameInput from '../components/FilenameInput'

const splitFilename = filename => {
  let dotIdx = filename.lastIndexOf('.') - 1 >>> 0
  return {
    extension: filename.slice(dotIdx + 1),
    filename: filename.slice(0, dotIdx + 1)
  }
}

const isDir = attrs => attrs.type === 'directory'

const getClassFromMime = attrs => {
  if (isDir(attrs)) {
    return styles['fil-file-folder']
  }
  return styles['fil-file-' + attrs.mime.split('/')[0]] || styles['fil-file-files']
}

class File extends Component {
  constructor (props) {
    super(props)
    this.state = {
      editing: props.attributes.isNew === true
    }
  }

  componentWillReceiveProps (newProps) {
    if (newProps.attributes.isNew === true && !this.props.attributes.isNew) {
      this.setState({
        editing: true
      })
    }
  }

  edit (value) {
    this.props.onEdit(value, this.props.attributes)
    this.setState({
      editing: false
    })
  }

  render ({ t, f, attributes, isFetching }, { editing }) {
    return (
      <tr>
        {this.renderFilenameCell(attributes, editing, isFetching)}
        <td>
          <time datetime=''>{ f(attributes.created_at, 'MMM D, YYYY') }</time>
        </td>
        <td>
          {isDir(attributes)
            ? '-'
            : filesize(attributes.size, {base: 10})}
        </td>
        <td>—</td>
      </tr>
    )
  }

  renderFilenameCell (attributes, editing, isFetching) {
    const { filename, extension } = splitFilename(attributes.name)
    const classes = classNames(styles['fil-content-file'], getClassFromMime(attributes))
    if (editing) {
      return (
        <td class={classes}>
          <FilenameInput name={attributes.name} onSubmit={val => this.edit(val)} />
        </td>
      )
    }
    return isDir(attributes)
      ? (
        <td class={classes}>
          <Link to={`/files/${attributes.id}`}>
            {attributes.name}
            {isFetching && <div class={styles['fil-loading']} />}
          </Link>
        </td>
      )
      : <td class={classes}><a target='_blank' href={`http://cozy.local:8080/files/download/${attributes.id}`}>{filename}<span class={styles['fil-content-ext']}>{extension}</span></a></td>
  }
}

export default translate()(File)

{'fraction_non_alphanumeric': 0.1637239165329053, 'fraction_numerical': 0.0056179775280898875, 'mean_word_length': 2.6654411764705883, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4590820', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1579, 'n_words': 321}