Use actual funkos in the admin backend

This commit is contained in:
Roberto Alsina 2024-07-02 16:56:19 -03:00
parent 3d0dc1539a
commit a4f722a1e0
2 changed files with 4 additions and 16 deletions

View File

@ -1,25 +1,11 @@
require "docr" require "docr"
require "kemal" require "kemal"
require "../funko.cr"
module Funkos module Funkos
struct Funko
include JSON::Serializable
property name : String
def initialize(@name : String)
end
end
get "/funkos/" do |env| get "/funkos/" do |env|
docker_api = Docr::API.new(Docr::Client.new) funkos : Array(Funko) = Funko.from_docker
containers = docker_api.containers.list(all: true)
funkos = [] of Funko
containers.each { |container|
names = container.names.select &.starts_with? "/faaso-"
next if names.empty?
funkos << Funko.new(name: names[0][7..])
}
funkos.sort! { |a, b| a.name <=> b.name } funkos.sort! { |a, b| a.name <=> b.name }
if env.params.query.fetch("format", "json") == "html" if env.params.query.fetch("format", "json") == "html"

View File

@ -1,5 +1,7 @@
<%- funkos.each do |funko| -%> <%- funkos.each do |funko| -%>
<tr>
<td><%= funko.name %></td> <td><%= funko.name %></td>
<td>sarasa</td> <td>sarasa</td>
<td><button>DOSTUFF</button></td> <td><button>DOSTUFF</button></td>
</tr>
<%- end -%> <%- end -%>