<commit_before>#
#
# Author:  Michael 'entropie' Trommer <<EMAIL>>
#

class ApiController < OYController

  map "/api"
  layout :none

  include OY


  def GET(*fragments)
    response[ 'Content-Type' ] = 'application/json'
    page = repos.find_by_fragments(*fragments)
    respond_ok(page.to_hash)
  end

  def POST(*fragments)
    response[ 'Content-Type' ] = 'application/json'

    data, author, msg = request[:data], request[:author], request[:message]

    ext = Markup.extension(request[:markup])

    author = repos.actor_from_string(author)
    fragments.last << ".#{ext}"

    initial = false

    begin
      page = repos.find_by_fragments(*fragments)
    rescue NotFound
      initial = true
      page = Wiki.create_bare(fragments.join("/"))
    end

    page = page.update do |pg|
      pg.actor   = author
      pg.data    = data
      pg.message = msg
    end
    respond_ok(:size => page.size, :url => page.link, :initial => initial)
  end

  def SYNC(*fragments)
    wiki, time = find_by_fragments(*fragments)

    author = "%s <%s>" % [wiki.commit.author.name, wiki.commit.author.email]
    message = "Synced from other Oy!: %s" % wiki.message

    api = OY.api("http://wiki.kommunism.us")
    r = api.post(wiki.ident) do |opts|
      opts[:author]  = author
      opts[:data]    = wiki.raw_data
      opts[:message] = message
    end
    redirect wiki.link<commit_msg>dont use cache for syncing<commit_after>#
#
# Author:  Michael 'entropie' Trommer <<EMAIL>>
#

class ApiController < OYController

  map "/api"
  layout :none

  include OY


  def GET(*fragments)
    response[ 'Content-Type' ] = 'application/json'
    page = repos.find_by_fragments(*fragments)
    respond_ok(page.to_hash)
  end

  def POST(*fragments)
    response[ 'Content-Type' ] = 'application/json'

    data, author, msg = request[:data], request[:author], request[:message]

    ext = Markup.extension(request[:markup])

    author = repos.actor_from_string(author)
    fragments.last << ".#{ext}"

    initial = false

    begin
      page = repos.find_by_fragments(*fragments)
    rescue NotFound
      initial = true
      page = Wiki.create_bare(fragments.join("/"))
    end

    page = page.update do |pg|
      pg.actor   = author
      pg.data    = data
      pg.message = msg
    end
    respond_ok(:size => page.size, :url => page.link, :initial => initial)
  end

  def SYNC(*fragments)
    wiki, time = repos.find_by_fragments(*fragments)

    author = "%s <%s>" % [wiki.commit.author.name, wiki.commit.author.email]
    message = "Synced from other Oy!: %s" % wiki.message

    api = OY.api("http://wiki.kommunism.us")

    r = api.post(wiki.ident) do |opts|
      opts[:author]  = author
      opts[:data]    = wiki.raw_data
      opts[:message] = message
    end
    redirect wiki.link
{'fraction_non_alphanumeric': 0.13759828448892067, 'fraction_numerical': 0.0, 'mean_word_length': 2.8929068150208623, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7209063', 'n_tokens_mistral': 977, 'n_tokens_neox': 930, 'n_words': 209}