<commit_before>@Files = FileCollection
  resumable: true
  resumableIndexName: 'files'
  http: [
    method: 'get'
    path: '/id/:_id'
    lookup: (params, query) ->
      _id: params._id
  ]

if Meteor.isServer
  Files._ensureIndex [
    ['metadata.group', 1]
    ['metadata._Resumable', 1]
  ]

@fileUrlPrefix = "/file/"

## If given object has a `file` but no `_id` field, then we make a link
## to the internal file object instead of the file associated with a message.
## This lets History work with files.
@urlToFile = (id) ->
  id = id._id if id._id?
  if id.file?
    urlToInternalFile id
  else
    Meteor.absoluteUrl "#{fileUrlPrefix[1..]}#{id}"

@url2file = (url) ->
  if url[...fileUrlPrefix.length] == fileUrlPrefix
    url[fileUrlPrefix.length..]
  else
    absolutePrefix = Meteor.absoluteUrl fileUrlPrefix[1..]
    if url[...absolutePrefix.length] == absolutePrefix<commit_msg>Most of file upload on Cordova #253<commit_after>corsHandler = (req, res, next) ->
  if req.headers?.origin
    res.setHeader 'Access-Control-Allow-Origin', req.headers.origin
    res.setHeader 'Access-Control-Allow-Credentials', true
  next()

@Files = FileCollection
  resumable: true
  resumableIndexName: 'files'
  http: [
    method: 'get'
    path: '/id/:_id'
    lookup: (params, query) ->
      _id: params._id
    handler: corsHandler
  ,
    method: 'post'
    path: '/_resumable'
    lookup: -> {}
    handler: corsHandler
  ,
    method: 'head'
    path: '/_resumable'
    lookup: -> {}
    handler: corsHandler
  ,
    method: 'options'
    path: '/_resumable'
    lookup: -> {}
    handler: (req, res, next) ->
      res.writeHead 200,
        'Content-Type': 'text/plain'
        'Access-Control-Allow-Origin': req.headers.origin
        'Access-Control-Allow-Credentials': true
        'Access-Control-Allow-Headers': 'x-auth-token, user-agent'
        'Access-Control-Allow-Methods': 'GET, POST, HEAD, OPTIONS'
      res.end()
  ]

if Meteor.isServer
  Files._ensureIndex [
    ['metadata.group', 1]
    ['metadata._Resumable', 1]
  ]

@fileUrlPrefix = "/file/"

## If given object has a `file` but no `_id` field, then we make a link
## to the internal file object instead of the file associated with a message.
## This lets History work with files.
@urlToFile = (id) ->
  id = id._id if id._id?
  if id.file?
    urlToInternalFile id
  else
    Meteor.absoluteUrl "#{fileUrlPrefix[1..]}#{id}"

@url2file = (url) ->
  if url[...fileUrlPrefix.length] == fileUrlPrefix
    url[fileUrlPrefix.length..]
  else
    absolutePrefix = Meteor.absoluteUrl fileUrlPrefix[1..]
    if url[...absolutePrefix.length] == absolutePrefix
{'fraction_non_alphanumeric': 0.1410110224249335, 'fraction_numerical': 0.006081337894336754, 'mean_word_length': 3.0244648318042815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '1019011', 'n_tokens_mistral': 898, 'n_tokens_neox': 884, 'n_words': 230}