Sha256: 6deac3b7c11edf5f684d64c61deec69b9df9b6344ffb4a0e1185719b5ddc685f

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

class MainController < Nephos::Controller

  def root
    cookies["a"] = "b"
    cookies.delete("b").to_h
    puts cookies
    {
      json: {
        list: $dataset,
        add: '/add',
        rm: '/rm',
      }
    }
  end

  def add_url
    url = params["url"]
    if url
      Dataset << url
      return {plain: "#{url} added"}
    else
      return {plain: "url argument required"}
    end
  end

  def rm_url
    url = params[:url]
    if url
      Dataset.rm url
      return {plain: "#{url} removed"}
    else
      return {plain: "url argument required"}
    end
  end

  def hello
    {html: "<html><body><h1>hello world</h1><p>lol</p></body></html>"}
  end

  AUTH_IMG_EXT = %w(.jpg .jpeg .png .gif)
  def image
    dir = File.expand_path('controllers/')
    file = File.expand_path(params["image"], dir)
    if not file[0..(dir.size-1)] == dir or not AUTH_IMG_EXT.include?(File.extname(file))
      return {status: 500, content: "invalid path #{params['image']}"}
    elsif not File.exists? file
      return {status: 404, content: "invalid path #{params['image']}"}
    else
      return {type: 'image/jpeg', content: File.read(file)}
    end
  end

  require 'pry'
  def debug
    binding.pry
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nephos-server-0.5.2 app/main.rb