~edwardloveall/scribe

ref: 1dcded9153c482553538fdf9a4f80e7d9361b19c scribe/src/actions/articles/show.cr -rw-r--r-- 688 bytes
1dcded91Edward Loveall Update changelog to mention no DATABASE_URL 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require "json"

class Articles::Show < BrowserAction
  fallback do
    post_id = ArticleIdParser.parse(context.request)
    case post_id
    in Monads::Just
      response = client_class.post_data(post_id.value!)
      page = PageConverter.new.convert(response.data)
      html ShowPage, page: page
    in Monads::Nothing, Monads::Maybe
      html(
        Errors::ParseErrorPage,
        message: "Error parsing the URL",
        status_code: 422,
        original_resource: request.resource,
      )
    end
  end

  def client_class
    if use_local?
      LocalClient
    else
      MediumClient
    end
  end

  def use_local?
    ENV.fetch("USE_LOCAL", "false") == "true"
  end
end