<commit_before>Node = require '../node'
UploadService = require '../services/upload'

Revision = require './revision'

module.exports = class File extends Node
  relations:
    revisions: Revision

  get: (cb) -> @api.get @nodePath, {}, @buildRelations(cb)

  create: (options, cb) ->
    service = new UploadService(@, options)
    service.perform cb.bind(@)

  delete: (cb) -> @api.delete @nodePath, {}, cb.bind(@)
  move: (to, cb) -> @api.post("#{@nodePath}/move", { to: to }, cb.bind(@))
  rename: @move
<commit_msg>Add md5 to file delete operation<commit_after>Node = require '../node'
UploadService = require '../services/upload'
Md5Service = require '../services/md5'

Revision = require './revision'

module.exports = class File extends Node
  relations:
    revisions: Revision

  get: (cb) -> @api.get @nodePath, {}, @buildRelations(cb)

  create: (options, cb) ->
    service = new UploadService(@, options)
    service.perform cb.bind(@)

  delete: (opts, cb) ->
    if opts.md5?
      md5 = opts.md5
    else if opts.localPath?
      service = new Md5Service(opts.localPath)
      service.calculate (md5) => @delete {md5: md5}, cb
    else
      throw "Deleting a file requires the md5 of the latest revision"

    @api.delete @nodePath, {md5: md5}, cb.bind(@)

  move: (to, cb) -> @api.post("#{@nodePath}/move", { to: to }, cb.bind(@))
  rename: @move

{'fraction_non_alphanumeric': 0.16910688140556368, 'fraction_numerical': 0.00951683748169839, 'mean_word_length': 3.3814102564102564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '7464814', 'n_tokens_mistral': 469, 'n_tokens_neox': 453, 'n_words': 129}