<commit_before>require! [ './db.ls' ]

apps = null

handlers =

  #########################################################################

  # TODO: Limit info length and further validate input
  post-app: (session, data, callback) !->
    unless session.id?
      callback error: 22
      return

    entry =
      data
      uploader:
        id:       session.user._id
        username: session.user.username
      upload-date: new Date!
      downloads: 0

    unless entry.data?
      callback error: 21
      return

    # TODO: Copy needed values from data; this is dangerous
    err <-! apps.insert entry
    if err then throw err

    callback success: true

  #########################################################################

  get-all-apps: (session, data, callback) !-><commit_msg>Fix logged in check on /app/postApp<commit_after>require! [ './db.ls' ]

apps = null

handlers =

  #########################################################################

  # TODO: Limit info length and further validate input
  post-app: (session, data, callback) !->
    unless session.user?
      callback error: 22
      return

    # TODO: Only let verified users post
    # TODO: Consider marking all apps hidden to public by default (or warning)

    entry =
      data
      uploader:
        id:       session.user._id
        username: session.user.username
      upload-date: new Date!
      downloads: 0

    unless entry.data?
      callback error: 21
      return

    # TODO: Copy needed values from data; this is dangerous
    err <-! apps.insert entry
    if err then throw err

    callback success: true

  #########################################################################

  get-all-apps: (session, data, callback) !->
{'fraction_non_alphanumeric': 0.23958927552766685, 'fraction_numerical': 0.005704506560182544, 'mean_word_length': 2.821350762527233, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4339024', 'n_tokens_mistral': 476, 'n_tokens_neox': 431, 'n_words': 153}