site/controllers/projects.moon

41 lines
1.1 KiB
Plaintext
Raw Normal View History

config = require("lapis.config").get!
discount = require "discount"
lapis = require "lapis"
http = require "lapis.nginx.http"
oleg = require "lib/oleg"
require "base64"
gh = require('github').new({access_token: os.getenv "GITHUB_TOKEN", httpclient_driver: 'httpclient.ngx_driver'})
2015-02-01 08:17:40 +00:00
class Projects extends lapis.Application
2015-02-04 17:33:24 +00:00
[projects: "/projects"]: =>
2015-02-07 00:33:34 +00:00
@title = "Projects"
2015-02-01 08:17:40 +00:00
render: true
[readme: "/projects/:name"]: =>
2015-02-07 00:33:34 +00:00
@title = "Readme for #{@params.name}"
2015-02-07 00:42:44 +00:00
@name = @params.name
@ret, @err = oleg.get "readmes", @params.name
if @err
ngx.log ngx.NOTICE, "Need to download readme for #{@params.name}"
reply, err = gh\authed_request "/repos/Xe/#{@params.name}/contents/README.md"
readme = base64.decode reply.content
if code == 404
return render: "notfound", status_code: 404
oleg.set "readmes", @params.name, readme
@ret = readme
elseif @err
@err = "OlegDB returned code #{@err}."
return render: "error", status_code: 500
@doc = discount @ret, "toc", "nopants", "autolink"
render: true