Browse Source

Ready to go, I think.

master
Ashley 1 year ago
parent
commit
093a9c3773
8 changed files with 288 additions and 56 deletions
  1. 4
    1
      Settings.toml
  2. 97
    0
      assets/css/style.css
  3. BIN
      assets/favicon.ico
  4. 115
    0
      log/requests.log
  5. 27
    30
      src/controller.rs
  6. 7
    7
      src/images.rs
  7. 30
    10
      src/main.rs
  8. 8
    8
      templates/index.html

+ 4
- 1
Settings.toml View File

@@ -1,3 +1,6 @@
base_http_url="http://cdn.shibe.online/"
base_https_url="https://cdn.shibe.online/"
port = 6767
port = 6767

[endpoints]
shibes = "content/shibes/*"

+ 97
- 0
assets/css/style.css View File

@@ -0,0 +1,97 @@
html,body
{
color: #333333;
background: #333333;
height: 100%;
font-size: 14px;
font-family: "Open Sans", "Trebuchet MS", sans-serif;
}

a
{
color: #dd0000;
text-decoration: none;
}

a:hover
{
color: #990000;
}

pre
{
background: #f5f5f5;
border: 1px solid #cccccc;
padding: 10px;
}

table
{
width: 100%;
border-color: #808080;
border-collapse: collapse;
border-spacing: 0;
}

th
{
text-align: left;
line-height: 40px;
}

tbody tr
{
border-top: 1px solid #dddddd;
line-height: 35px;
font-size: 14px;
}

tbody tr:first-child
{
border-top: 2px solid #cccccc;
}

.shibe__header
{
text-align: center;
height: 250px;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}

.shibe__header h1
{
color: white;
font-weight: 800;
font-size: 2.2em;
margin: 0;
}

.shibe__header h2
{
color: white;
font-weight: normal;
font-size: 1.8em;
margin: 0;
}

.shibe__container
{
background: #ffffff;
padding: 15px;
padding-top: 1px;
width: 1080px;
margin: auto;
}

.shibe__image__container
{
text-align: center;
}

.shibe__image
{
max-width: 100%;
}

BIN
assets/favicon.ico View File


+ 115
- 0
log/requests.log View File

@@ -17,3 +17,118 @@
2018-08-21T06:26:50.792477900-04:00 - 127.0.0.1:54145 "GET /api/shibes?count=10&urls=true&httpsUrls=false HTTP/1.1" 200 209 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T06:26:53.003453500-04:00 - 127.0.0.1:54145 "GET /api/shibes?count=10&urls=true HTTP/1.1" 200 211 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T06:26:55.134541100-04:00 - 127.0.0.1:54145 "GET /api/shibes?count=10 HTTP/1.1" 200 258 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001001
2018-08-21T07:47:04.515625200-04:00 - 127.0.0.1:52243 "GET /api/shibes?count=10 HTTP/1.1" 200 190 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001989
2018-08-21T07:47:07.171613100-04:00 - 127.0.0.1:52243 "GET / HTTP/1.1" 200 1701 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000998
2018-08-21T07:47:07.188604600-04:00 - 127.0.0.1:52243 "GET /css/bootstrap.min.css HTTP/1.1" 404 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T07:47:07.188604600-04:00 - 127.0.0.1:52244 "GET /css/style.css HTTP/1.1" 404 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T07:47:07.481815500-04:00 - 127.0.0.1:52244 "GET /favicon.ico?v=1.1 HTTP/1.1" 404 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:00:06.541293500-04:00 - 127.0.0.1:54538 "GET / HTTP/1.1" 200 1709 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001986
2018-08-21T08:00:06.577281900-04:00 - 127.0.0.1:54538 "GET /assets/css/bootstrap.min.css HTTP/1.1" 200 125681 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.018998
2018-08-21T08:00:06.580272100-04:00 - 127.0.0.1:54538 "GET /assets/css/style.css HTTP/1.1" 200 513 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001002
2018-08-21T08:00:07.298366600-04:00 - 127.0.0.1:54538 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.003999
2018-08-21T08:00:36.127890200-04:00 - 127.0.0.1:54538 "GET / HTTP/1.1" 200 1708 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000981
2018-08-21T08:00:36.563416-04:00 - 127.0.0.1:54538 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:03:07.076333500-04:00 - 127.0.0.1:54538 "GET / HTTP/1.1" 200 1708 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:03:55.864918800-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001999
2018-08-21T08:03:56.346988400-04:00 - 127.0.0.1:55270 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001999
2018-08-21T08:03:57.951757-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:03:58.098671500-04:00 - 127.0.0.1:55270 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:03:58.686893500-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000998
2018-08-21T08:03:59.014031400-04:00 - 127.0.0.1:55270 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001002
2018-08-21T08:04:29.888765300-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1745 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:04:30.287369100-04:00 - 127.0.0.1:55270 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:04:30.548452400-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:04:30.869375200-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:04:31.040277600-04:00 - 127.0.0.1:55270 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001999
2018-08-21T08:04:31.089248300-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1745 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:04:31.261150200-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:04:31.432050900-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:04:32.121655100-04:00 - 127.0.0.1:55270 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001998
2018-08-21T08:04:40.481081700-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1748 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001005
2018-08-21T08:04:40.503056600-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 631 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:04:52.531703300-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001003
2018-08-21T08:04:52.553689200-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 649 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:05:26.793732400-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:05:26.818719700-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 711 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.002001
2018-08-21T08:05:40.218794400-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001013
2018-08-21T08:05:40.239771300-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 730 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001001
2018-08-21T08:06:14.334460400-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1745 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:06:14.358447400-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 769 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001999
2018-08-21T08:06:28.584215800-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1748 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000998
2018-08-21T08:06:28.612199300-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 802 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:06:38.594382300-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001012
2018-08-21T08:06:38.617357100-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 802 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001999
2018-08-21T08:07:48.776616500-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000989
2018-08-21T08:07:48.798604100-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 860 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001001
2018-08-21T08:08:27.992507700-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:08:28.014495600-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 906 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001999
2018-08-21T08:09:34.230710100-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1742 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000987
2018-08-21T08:09:34.253697600-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 941 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001998
2018-08-21T08:10:16.668300500-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:10:16.688288200-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 984 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000998
2018-08-21T08:10:26.196376900-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1745 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:10:26.218363300-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 984 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.002998
2018-08-21T08:10:40.355194200-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:10:40.380180700-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 990 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:10:41.293668200-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001011
2018-08-21T08:10:41.320640-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 304 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:11:08.428071-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001011
2018-08-21T08:11:08.451046200-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1051 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001997
2018-08-21T08:11:15.356493700-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1742 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:11:15.376482200-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1051 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:11:28.235582600-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1748 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:11:28.257570500-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1075 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001998
2018-08-21T08:12:10.827726100-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:12:10.851711900-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1095 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000998
2018-08-21T08:12:35.447183900-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:12:35.470170600-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1095 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:12:50.223653-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1748 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:12:50.245641800-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1115 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.002001
2018-08-21T08:12:51.197630300-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000987
2018-08-21T08:12:51.218620300-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 304 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:13:14.867348200-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001012
2018-08-21T08:13:14.889323500-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1118 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001998
2018-08-21T08:13:32.093652200-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000989
2018-08-21T08:13:32.121636900-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1118 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.002000
2018-08-21T08:13:38.083394500-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1745 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:13:38.105382800-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1118 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:13:53.133863700-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000989
2018-08-21T08:13:53.155849700-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1139 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.002000
2018-08-21T08:13:57.897383600-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:13:57.918361-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1139 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:14:12.874155700-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1748 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:14:12.895144200-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1157 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:14:25.363585900-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1742 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:14:25.386573800-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1172 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001998
2018-08-21T08:14:35.601570400-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000987
2018-08-21T08:14:35.623558400-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1139 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001986
2018-08-21T08:14:54.662246100-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 304 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001011
2018-08-21T08:15:23.524536100-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:15:23.547523100-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1223 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001999
2018-08-21T08:15:47.111330200-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1745 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:15:47.137317400-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1247 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001999
2018-08-21T08:17:37.087475100-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1744 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:17:37.120446300-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 200 1210 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.011993
2018-08-21T08:17:38.053664200-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1748 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000998
2018-08-21T08:17:38.077651900-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 304 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:17:38.640517900-04:00 - 127.0.0.1:55270 "GET / HTTP/1.1" 200 1747 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000986
2018-08-21T08:17:38.660507200-04:00 - 127.0.0.1:55270 "GET /assets/css/style.css HTTP/1.1" 304 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:18:01.226427-04:00 - 127.0.0.1:58053 "GET / HTTP/1.1" 200 1737 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:18:01.246406400-04:00 - 127.0.0.1:58053 "GET /assets/css/style.css HTTP/1.1" 304 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:18:19.832269300-04:00 - 127.0.0.1:58053 "GET /assets/css/style.css HTTP/1.1" 304 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:19:07.515095100-04:00 - 127.0.0.1:58053 "GET / HTTP/1.1" 200 1738 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001001
2018-08-21T08:19:07.542068400-04:00 - 127.0.0.1:58053 "GET /assets/css/style.css HTTP/1.1" 200 1210 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.007996
2018-08-21T08:19:17.721356900-04:00 - 127.0.0.1:58053 "GET / HTTP/1.1" 200 1737 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001012
2018-08-21T08:19:17.752326800-04:00 - 127.0.0.1:58053 "GET /assets/css/style.css HTTP/1.1" 200 1232 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.010994
2018-08-21T08:20:03.154464100-04:00 - 127.0.0.1:58053 "GET / HTTP/1.1" 200 1735 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000000
2018-08-21T08:20:03.173453-04:00 - 127.0.0.1:58053 "GET /assets/css/style.css HTTP/1.1" 304 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:20:03.568298800-04:00 - 127.0.0.1:58053 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:41:18.902226100-04:00 - 127.0.0.1:62471 "GET / HTTP/1.1" 200 1725 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001998
2018-08-21T08:41:18.935207600-04:00 - 127.0.0.1:62471 "GET /assets/css/style.css HTTP/1.1" 304 0 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001000
2018-08-21T08:41:19.978172500-04:00 - 127.0.0.1:62471 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001999
2018-08-21T08:41:20.605079800-04:00 - 127.0.0.1:62471 "GET / HTTP/1.1" 200 1725 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:41:20.814551100-04:00 - 127.0.0.1:62471 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.002000
2018-08-21T08:41:21.349996800-04:00 - 127.0.0.1:62471 "GET / HTTP/1.1" 200 1725 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.000999
2018-08-21T08:41:21.488916800-04:00 - 127.0.0.1:62471 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.002000
2018-08-21T08:41:21.878307400-04:00 - 127.0.0.1:62471 "GET / HTTP/1.1" 200 1724 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.001001
2018-08-21T08:41:22.411566200-04:00 - 127.0.0.1:62471 "GET /assets/favicon.ico?v=1.1 HTTP/1.1" 200 1406 "http://localhost:6767/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 0.002000

+ 27
- 30
src/controller.rs View File

@@ -6,7 +6,6 @@ use actix_web::dev::HttpResponseBuilder;
use actix_web::http::ContentEncoding;
use askama::Template;
use images::{Endpoints, ImageManager};
use std::error::Error;

pub struct AppParams
{
@@ -26,12 +25,14 @@ impl AppParams
}
}

pub struct Controller<'a>
pub struct AppState
{
endpoints: Endpoints<'a>,
settings: AppParams
pub endpoints: Endpoints,
pub settings: AppParams
}

pub struct Controller { }

struct ApiParams
{
count: usize,
@@ -47,7 +48,7 @@ struct IndexTemplate<'a>
}

// gets the value of the query string as a usize, or returns the default
fn get_query_usize(req: &HttpRequest, key: &'static str, default: usize) -> usize
fn get_query_usize(req: &HttpRequest<AppState>, key: &'static str, default: usize) -> usize
{
let query = req.query();
match query.get(key) {
@@ -56,7 +57,7 @@ fn get_query_usize(req: &HttpRequest, key: &'static str, default: usize) -> usiz
}
}

fn get_query_bool(req: &HttpRequest, key: &'static str, default: bool) -> bool
fn get_query_bool(req: &HttpRequest<AppState>, key: &'static str, default: bool) -> bool
{
let query = req.query();
match query.get(key) {
@@ -81,21 +82,13 @@ fn error(mut res : HttpResponseBuilder, message: &'static str) -> HttpResponse
.body(message)
}

impl<'a> Controller<'a>
impl Controller
{
pub fn new(
endpoints: Endpoints<'a>,
settings: AppParams)
-> Result<Self, Box<Error + 'static>>
{
Ok(Self { settings: settings, endpoints: endpoints })
}

pub fn index(&self) -> HttpResponse
pub fn index(req: &HttpRequest<AppState>) -> HttpResponse
{
let im = self.endpoints.get("shibes").unwrap();
let im = req.state().endpoints.get("shibes").unwrap();
let params = ApiParams { count: 1, https_urls: true, urls: true };
let dog_rand = self.get_images_for(&im, "shibes", &params);
let dog_rand = Controller::get_images_for(&req, &im, "shibes", &params);
let none = String::from("");
let index = IndexTemplate { dog: dog_rand.first().unwrap_or(&none) };
match index.render() {
@@ -104,19 +97,19 @@ impl<'a> Controller<'a>
}
}

pub fn get_endpoint(&self, req: &HttpRequest) -> HttpResponse
pub fn get_endpoint(req: &HttpRequest<AppState>) -> HttpResponse
{
let options = self.parse_api_params(req);
let options = Controller::parse_api_params(&req);
let endpoint = req.match_info().get("endpoint").unwrap_or("unknown");
debug!("request to endpoint {}", endpoint);

match self.endpoints.get(endpoint) {
Some(im) => self.serialize_images(&im, endpoint, &options),
match req.state().endpoints.get(endpoint) {
Some(im) => Controller::serialize_images(&req, &im, endpoint, &options),
None => error(HttpResponse::NotFound(), "Invalid endpoint.")
}
}

fn parse_api_params(&self, req: &HttpRequest) -> ApiParams
fn parse_api_params(req: &HttpRequest<AppState>) -> ApiParams
{
let count = num::clamp(get_query_usize(&req, "count", 1), 1, 100);
ApiParams {
@@ -126,7 +119,7 @@ impl<'a> Controller<'a>
}
}

fn handle_url(&self, options: &ApiParams, endpoint: &str, file: &str) -> String
fn handle_url(settings: &AppParams, options: &ApiParams, endpoint: &str, file: &str) -> String
{
if !options.urls
{
@@ -135,7 +128,7 @@ impl<'a> Controller<'a>
}
else if options.https_urls
{
let mut base = self.settings.https_url.clone();
let mut base = settings.https_url.clone();
base.push_str(endpoint);
base.push('/');
base.push_str(file);
@@ -143,7 +136,7 @@ impl<'a> Controller<'a>
}
else
{
let mut base = self.settings.http_url.clone();
let mut base = settings.http_url.clone();
base.push_str(endpoint);
base.push('/');
base.push_str(file);
@@ -151,20 +144,24 @@ impl<'a> Controller<'a>
}
}

fn get_images_for(&self, im: &ImageManager, endpoint: &str, options: &ApiParams) -> Vec<String>
fn get_images_for(
req: &HttpRequest<AppState>,
im: &ImageManager,
endpoint: &str,
options: &ApiParams) -> Vec<String>
{
return im.get_rand_iter(options.count)
.map(|f| self.handle_url(&options, &endpoint, &f))
.map(|f| Controller::handle_url(&req.state().settings, &options, &endpoint, &f))
.collect();
}

fn serialize_images(
&self,
req: &HttpRequest<AppState>,
im: &ImageManager,
endpoint: &str,
options: &ApiParams) -> HttpResponse
{
let rand = self.get_images_for(&im, &endpoint, &options);
let rand = Controller::get_images_for(&req, &im, &endpoint, &options);
match serde_json::to_string(&rand) {
Ok(json) => ok(json),
Err(_e) => error(HttpResponse::InternalServerError(), "Couldn't serialize images.")

+ 7
- 7
src/images.rs View File

@@ -43,26 +43,26 @@ impl ImageManager
}
}

pub struct Endpoints<'a>
pub struct Endpoints
{
endpoints: HashMap<&'a str, ImageManager>
endpoints: HashMap<String, ImageManager>
}

impl<'a> Endpoints<'a>
impl Endpoints
{
pub fn new() -> Self
{
Self { endpoints: HashMap::new() }
}

pub fn add(&mut self, key: &'static str, glob: &'static str) -> Result<(), Box<Error>>
pub fn add(&mut self, key: &str, glob: String) -> Result<(), Box<Error>>
{
let im = try!(ImageManager::new(glob));
self.endpoints.insert(key, im);
let im = try!(ImageManager::new(&glob));
self.endpoints.insert(String::from(key), im);
Ok(())
}

pub fn get(&'a self, name: &str) -> Option<&'a ImageManager>
pub fn get(&self, name: &str) -> Option<&ImageManager>
{
match self.endpoints.get(name) {
Some(im) => Some(&im),

+ 30
- 10
src/main.rs View File

@@ -8,27 +8,47 @@ mod controller;
mod images;
mod rand_iter;

use actix_web::{server, App};
use actix_web::{server, App, HttpResponse, fs};
use actix_web::http::Method;
use actix_web::middleware::Logger;
use config::Config;
use controller::{AppParams, Controller};
use controller::{AppParams, Controller, AppState};
use images::Endpoints;
use std::net::SocketAddr;

fn create_app(settings : AppParams) -> App
fn create_app(
settings_file : &Config,
settings : AppParams) -> App<AppState>
{
let mut endpoints = Endpoints::new();
endpoints.add("shibes", "content/shibes/*").unwrap();
let controller = Controller::new(endpoints, settings).unwrap();
let table = settings_file.get_table("endpoints").unwrap();
for key in table.keys()
{
let v = table.get(key);
match v
{
None => (),
Some(s) => {
endpoints.add(key, s.clone().into_str().unwrap()).unwrap();
debug!("loaded endpoint {}", key);
}
}
}

App::new()
let state = AppState { endpoints: endpoints, settings: settings };

App::with_state(state)
.middleware(Logger::default())
.resource(
"/",
|r| r.method(Method::GET).f(Controller::index))
.resource(
"/api/{endpoint}",
move |r| {
r.method(Method::GET).f(move |req| controller.get_endpoint(&req))
})
|r| r.method(Method::GET).f(Controller::get_endpoint))
.handler("/assets", fs::StaticFiles::new("assets").unwrap())
.default_resource(|r| {
r.route().f(|_| HttpResponse::NotFound().body("Not found."))
})
}

fn main()
@@ -49,7 +69,7 @@ fn main()

let port : u16 = settings_file.get_int("port").unwrap_or(6767) as u16;
server::new(move || create_app(settings.clone()))
server::new(move || create_app(&settings_file, settings.clone()))
.bind(SocketAddr::from(([127, 0, 0, 1], port)))
.unwrap()
.run();

+ 8
- 8
templates/index.html View File

@@ -2,9 +2,9 @@
<html>
<head>
<title>shibe.online - the shiba inu api</title>
<link href="/css/bootstrap.min.css" rel="stylesheet" />
<link href="/css/style.css" rel="stylesheet" />
<link href="/favicon.ico?v=1.1" rel="icon" type="image/x-icon" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,800" rel="stylesheet">
<link href="/assets/css/style.css" rel="stylesheet" />
<link href="/assets/favicon.ico?v=1.1" rel="icon" type="image/x-icon" />
<!-- oh yeah, gonna get that SEO. gonna be famous. -->
<meta property="og:title" content="shibe.online - the shiba inu api" />
<meta property="og:site_name" content="shibe.online" />
@@ -20,7 +20,7 @@
<h1>shibe.online</h1>
<h2>shibes as a service</h2>
</div>
<div class="shibe__container container">
<div class="shibe__container">
<p>
In this day and age, everyone and their dog has an API. So why not have an API for dogs? Shibe.online is that API.
</p>
@@ -30,10 +30,10 @@
<p>
<pre>
http://shibe.online/api/shibes?count=[1-100]&urls=[true/false]&httpsUrls=[true/false]
</pre>
</pre>
</p>
<p>
And you'll get back a JSON response of random images of shibes that's something like this:
And you'll get back a JSON response of random images of shibes that looks something like this:
</p>
<p>
<pre>
@@ -48,7 +48,7 @@ http://shibe.online/api/shibes?count=[1-100]&urls=[true/false]&httpsUrls=[true/f
And if those options in the URL aren't self-explanatory enough, here's a simple guide:
</p>
<p>
<table class="table">
<table>
<thead>
<tr>
<th>Name</th>
@@ -93,7 +93,7 @@ http://shibe.online/api/shibes?count=[1-100]&urls=[true/false]&httpsUrls=[true/f
<img class="shibe__image" src="{{ dog }}" alt="A shibe." />
</p>
<p>
Service by <a href="https://cybre.space/@commie">@commie@cybre.space</a>.
Service by @commie@cybre.space.
</p>
<p>
Special thanks to <a href="https://ja.md/">Jammy</a> for the shibes, <a href="http://www.vision.caltech.edu/visipedia/CUB-200.html">CalTech</a> for the birds, and

Loading…
Cancel
Save