<commit_before># Components.utils.importGlobalProperties(['Blob'])

Zotero_BetterBibTeX_ErrorReport = new class
  constructor: ->
    @form = JSON.parse(Zotero.File.getContentsFromURL("resource://zotero-better-bibtex/logs/s3.json"))

  submit: (filename, data, callback) ->
    fd = new FormData()
    for own name, value of @form.fields
      fd.append(name, value)

    file = new Blob([data], { type: 'text/plain'})
    fd.append('file', file, "#{@timestamp}-#{@key}-#{filename}")

    request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance()
    request.open('POST', @form.action, true)

    request.onload = (e) ->
      Zotero.debug("BBT.error.submit.onload: #{request.readystate}")
      return unless request.readystate == 4
        callback(request)
    request.onerror = (e) ->
      callback(request)
    request.send(fd)

  init: ->
    Zotero.debug('BBT.error.init')
    @key = Zotero.Utilities.generateObjectKey()
    @timestamp = (new Date()).toISOString().replace(/\..*/, '').replace(/:/g, '.')
    Zotero.debug("BBT.error.init: #{@key}")

    wizard = document.getElementById('zotero-error-report')
    continueButton = wizard.getButton('next')
    continueButton.disabled = true
    document.getElementById('zotero-references').hidden = true

    Zotero.debug("BBT.error.init: here we go")

    Zotero.getSystemInfo((info) =>
      @errorLog = {
        full: Zotero.getErrors(true).join('\n') + "\n\n" + info + "\n\n"
      }
      @errorLog.truncated = @errorLog.full

      maxSize = if @form.maxSize then (@form.maxSize - @errorLog.full.length) * 0.95 else null
      debug = Zotero.Debug.get()
      debug = debug.slice(-1 * maxSize) if maxSize && debug.length > maxSize
      @errorLog.full += debug

      debug = debug.split("\n")
      debug = debug.slice(0, 5000) # max 5k lines
      debug = (Zotero.Utilities.ellipsize(line, 80, true) for line in debug) # trim lines
      debug = debug.join("\n")
      @errorLog.truncated += debug
<commit_msg>log bbt schema<commit_after># Components.utils.importGlobalProperties(['Blob'])

Zotero_BetterBibTeX_ErrorReport = new class
  constructor: ->
    @form = JSON.parse(Zotero.File.getContentsFromURL("resource://zotero-better-bibtex/logs/s3.json"))

  submit: (filename, data, callback) ->
    fd = new FormData()
    for own name, value of @form.fields
      fd.append(name, value)

    file = new Blob([data], { type: 'text/plain'})
    fd.append('file', file, "#{@timestamp}-#{@key}-#{filename}")

    request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance()
    request.open('POST', @form.action, true)

    request.onload = (e) ->
      Zotero.debug("BBT.error.submit.onload: #{request.readystate}")
      return unless request.readystate == 4
        callback(request)
    request.onerror = (e) ->
      callback(request)
    request.send(fd)

  init: ->
    Zotero.debug('BBT.error.init')
    @key = Zotero.Utilities.generateObjectKey()
    @timestamp = (new Date()).toISOString().replace(/\..*/, '').replace(/:/g, '.')
    Zotero.debug("BBT.error.init: #{@key}")

    wizard = document.getElementById('zotero-error-report')
    continueButton = wizard.getButton('next')
    continueButton.disabled = true
    document.getElementById('zotero-references').hidden = true

    Zotero.debug("BBT.error.init: here we go")

    Zotero.getSystemInfo((info) =>
      schema = {}
      for table in Zotero.DB.columnQuery("SELECT name FROM betterbibtex.sqlite_master WHERE type='table' AND name <> 'schema' ORDER BY name") || []
        schema[table] = Zotero.BetterBibTeX.table_info(table)
      schema = "Better BibTeX schema #{Zotero.DB.valueQuery('select version from betterbibtex.schema') || '<new>'}: #{JSON.stringify(schema)}"
      info += "\n\n#{schema}"

      @errorLog = {
        full: Zotero.getErrors(true).join('\n') + "\n\n" + info + "\n\n"
      }
      @errorLog.truncated = @errorLog.full

      maxSize = if @form.maxSize then (@form.maxSize - @errorLog.full.length) * 0.95 else null
      debug = Zotero.Debug.get()
      debug = debug.slice(-1 * maxSize) if maxSize && debug.length > maxSize
      @errorLog.full += debug

      debug = debug.split("\n")
      debug = debug.slice(0, 5000) # max 5k lines
      debug = (Zotero.Utilities.ellipsize(line, 80, true) for line in debug) # trim lines
      debug = debug.join("\n")
      @errorLog.truncated += debug

{'fraction_non_alphanumeric': 0.16685533167308128, 'fraction_numerical': 0.006791940230925968, 'mean_word_length': 3.2644787644787643, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3222690', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1455, 'n_words': 276}