From 326cfa543c6263818aad7dec4a869bc8139ec14c Mon Sep 17 00:00:00 2001 From: Jokler Date: Sat, 22 Feb 2020 18:53:13 +0100 Subject: Move web server related files into a folder --- askama.toml | 3 + src/web_server.rs | 2 +- static/.gitkeep | 0 static/fonts/.gitkeep | 0 static/style.css | 63 ---------------- templates/base.htm | 15 ---- templates/docs/api.htm | 126 ------------------------------- templates/index.htm | 36 --------- templates/song.htm | 7 -- templates/tmtu/index.htm | 145 ------------------------------------ web_server/static/fonts/.gitkeep | 0 web_server/static/style.css | 63 ++++++++++++++++ web_server/templates/base.htm | 15 ++++ web_server/templates/docs/api.htm | 126 +++++++++++++++++++++++++++++++ web_server/templates/index.htm | 36 +++++++++ web_server/templates/song.htm | 7 ++ web_server/templates/tmtu/index.htm | 145 ++++++++++++++++++++++++++++++++++++ 17 files changed, 396 insertions(+), 393 deletions(-) create mode 100644 askama.toml delete mode 100644 static/.gitkeep delete mode 100644 static/fonts/.gitkeep delete mode 100644 static/style.css delete mode 100644 templates/base.htm delete mode 100644 templates/docs/api.htm delete mode 100644 templates/index.htm delete mode 100644 templates/song.htm delete mode 100644 templates/tmtu/index.htm create mode 100644 web_server/static/fonts/.gitkeep create mode 100644 web_server/static/style.css create mode 100644 web_server/templates/base.htm create mode 100644 web_server/templates/docs/api.htm create mode 100644 web_server/templates/index.htm create mode 100644 web_server/templates/song.htm create mode 100644 web_server/templates/tmtu/index.htm diff --git a/askama.toml b/askama.toml new file mode 100644 index 0000000..fceb790 --- /dev/null +++ b/askama.toml @@ -0,0 +1,3 @@ +[general] +# Directories to search for templates, relative to the crate root. +dirs = ["web_server/templates"] diff --git a/src/web_server.rs b/src/web_server.rs index 0097fb1..01233f2 100644 --- a/src/web_server.rs +++ b/src/web_server.rs @@ -44,7 +44,7 @@ pub async fn start(args: WebServerArgs) -> std::io::Result<()> { .service(api::get_bot), ) .service(web::scope("/docs").service(get_api_docs)) - .service(actix_files::Files::new("/static", "static/")) + .service(actix_files::Files::new("/static", "web_server/static/")) }) .bind(args.bind_address)? .run() diff --git a/static/.gitkeep b/static/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/static/fonts/.gitkeep b/static/fonts/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/static/style.css b/static/style.css deleted file mode 100644 index 09a985c..0000000 --- a/static/style.css +++ /dev/null @@ -1,63 +0,0 @@ -@font-face { - font-family: 'roboto-regular'; - src: url('fonts/Roboto-Regular.ttf') format('truetype'); -} - -@font-face { - font-family: 'roboto-light'; - src: url('fonts/Roboto-Light.ttf') format('truetype'); -} - -@font-face { - font-family: 'roboto-bold'; - src: url('fonts/Roboto-Bold.ttf') format('truetype'); -} - -body { - background-color: #151515; -} - -main { - margin: auto; - max-width: 800px; - padding: 1em; - background-color: #202020; - color: #eee; - font-family: 'roboto-regular', Arial; -} - -nav > a { - font-size: 1.4rem; -} - -a, a:visited { - color: #eee; -} - -a:hover { - color: #ccc; -} - -pre { - font-size: 0.9rem; - font-family: monospace; - background-color: #151515; - overflow: auto; - padding: 1em; -} - -.code-background { - background-color: #151515; -} - -.code-normal { - color: #c0c5ce; -} - -.code-string { - color:#a3be8c; -} - -.code-number { - color: #d08770; -} diff --git a/templates/base.htm b/templates/base.htm deleted file mode 100644 index b8b2f49..0000000 --- a/templates/base.htm +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - {% block title %}{{ title }} - PokeBot{% endblock %} - - -
- {% block content %}{% endblock %} -
- - diff --git a/templates/docs/api.htm b/templates/docs/api.htm deleted file mode 100644 index a973272..0000000 --- a/templates/docs/api.htm +++ /dev/null @@ -1,126 +0,0 @@ -{% extends "base.htm" %} - -{% block title %}API Documentation{% endblock %} - -{% block content %} -

API Documentation

- - -

Bot list

-

Show a list of all bots.

- -

URL: /api/bots

-

Method: GET

-

Auth required: NO

- -

Success Response

- -

Code: 200 OK

- -

Content example

- - -
-[
-  {
-    "name": "MusicBot",
-    "state": "Playing",
-    "volume": 0.5,
-    "position": {
-      "secs": 10,
-      "nanos": 63573687
-    },
-    "currently_playing": {
-      "url": "<temp_url>",
-      "webpage_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
-      "title": "Rick Astley - Never Gonna Give You Up (Video)",
-      "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
-      "duration": {
-        "secs": 212,
-        "nanos": 0
-      }
-    },
-    "playlist": [
-      {
-        "url": "<temp_url>",
-        "webpage_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
-        "title": "Rick Astley - Never Gonna Give You Up (Video)",
-        "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
-        "duration": {
-          "secs": 212,
-          "nanos": 0
-        }
-      }
-    ]
-  }
-]
-
- - -

Show Bot

-

Show a specific bot.

- -

URL: /api/bots/:botname

-

Method: GET

-

Auth required: NO

- -

Success Response

-

Code: 200 OK

- -

Content example

- - -
-{
-  "name": "MusicBot",
-  "state": "Playing",
-  "volume": 0.5,
-  "position": {
-    "secs": 142,
-    "nanos": 690911766
-  },
-  "currently_playing": {
-    "url": "<temp_url>",
-    "webpage_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
-    "title": "Rick Astley - Never Gonna Give You Up (Video)",
-    "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
-    "duration": {
-      "secs": 212,
-      "nanos": 0
-    }
-  },
-  "playlist": [
-    {
-      "url": "<temp_url>",
-      "webpage_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
-      "title": "Rick Astley - Never Gonna Give You Up (Video)",
-      "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
-      "duration": {
-        "secs": 212,
-        "nanos": 0
-      }
-    }
-  ]
-}
-
- -

Error Response

- -

Condition: If ':botname' is not connected to TeamSpeak.

- -

Code: 404 NOT FOUND

- -Content: - - -
-{
-  "error": "Not Found",
-  "description": "The requested resource was not found"
-}
-
- -{% endblock %} diff --git a/templates/index.htm b/templates/index.htm deleted file mode 100644 index eed31f3..0000000 --- a/templates/index.htm +++ /dev/null @@ -1,36 +0,0 @@ -{% extends "base.htm" %} - -{% block title %}Overview{% endblock %} - -{% block content %} -

Bots

-
- - -
- - - -{% endblock %} diff --git a/templates/song.htm b/templates/song.htm deleted file mode 100644 index 072567a..0000000 --- a/templates/song.htm +++ /dev/null @@ -1,7 +0,0 @@ -{{ item.title }} -({{ item.duration|fmt_duration }}) -{% match item.thumbnail %} - {% when Some with (thumbnail) %} - - {% when None %} -{% endmatch %} diff --git a/templates/tmtu/index.htm b/templates/tmtu/index.htm deleted file mode 100644 index 785e653..0000000 --- a/templates/tmtu/index.htm +++ /dev/null @@ -1,145 +0,0 @@ - - - - tmtu mode - - - - - - - - {% match bot %} - {% when Some with (bot) %} - - - - - - - {% when None %} - {% endmatch %} -
-

PokeBot

-

A web interface for inspecting currently playing audio in PokeBot. Select an instance of the bot to view it's playlist and history.

- -
-

Status

-
- {% match bot.currently_playing %} - {% when Some with (current) %} -

Currently playing: {{ current.title }}

-

{{ bot.position|fmt_duration }} / {{ current.duration|fmt_duration }} - {% match current.duration %} - {% when Some with (duration) %} - {% let position %} - {% match bot.position %} - {% when Some with (pos) %} - {% let position = pos.as_secs_f64() %} - {% when None %} - {% let position = 0.0 %} - {% endmatch %} - {% let progress = position / duration.as_secs_f64() %} - {% let percent = progress * 100.0 %} -

- {% when None %} -

- {% endmatch %} - {% when None %} - {% endmatch %} -
-
-

Playlist

- - - - - - - - {% for item in bot.playlist %} - - - - - - - {% endfor %} -
#tracklengthadded by
{{ loop.index }}{{ item.title }} - {% let duration = item.duration %} - {{ duration|fmt_duration }} - {{ item.added_by }}
-
- - diff --git a/web_server/static/fonts/.gitkeep b/web_server/static/fonts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/web_server/static/style.css b/web_server/static/style.css new file mode 100644 index 0000000..09a985c --- /dev/null +++ b/web_server/static/style.css @@ -0,0 +1,63 @@ +@font-face { + font-family: 'roboto-regular'; + src: url('fonts/Roboto-Regular.ttf') format('truetype'); +} + +@font-face { + font-family: 'roboto-light'; + src: url('fonts/Roboto-Light.ttf') format('truetype'); +} + +@font-face { + font-family: 'roboto-bold'; + src: url('fonts/Roboto-Bold.ttf') format('truetype'); +} + +body { + background-color: #151515; +} + +main { + margin: auto; + max-width: 800px; + padding: 1em; + background-color: #202020; + color: #eee; + font-family: 'roboto-regular', Arial; +} + +nav > a { + font-size: 1.4rem; +} + +a, a:visited { + color: #eee; +} + +a:hover { + color: #ccc; +} + +pre { + font-size: 0.9rem; + font-family: monospace; + background-color: #151515; + overflow: auto; + padding: 1em; +} + +.code-background { + background-color: #151515; +} + +.code-normal { + color: #c0c5ce; +} + +.code-string { + color:#a3be8c; +} + +.code-number { + color: #d08770; +} diff --git a/web_server/templates/base.htm b/web_server/templates/base.htm new file mode 100644 index 0000000..b8b2f49 --- /dev/null +++ b/web_server/templates/base.htm @@ -0,0 +1,15 @@ + + + + + + + + {% block title %}{{ title }} - PokeBot{% endblock %} + + +
+ {% block content %}{% endblock %} +
+ + diff --git a/web_server/templates/docs/api.htm b/web_server/templates/docs/api.htm new file mode 100644 index 0000000..a973272 --- /dev/null +++ b/web_server/templates/docs/api.htm @@ -0,0 +1,126 @@ +{% extends "base.htm" %} + +{% block title %}API Documentation{% endblock %} + +{% block content %} +

API Documentation

+ + +

Bot list

+

Show a list of all bots.

+ +

URL: /api/bots

+

Method: GET

+

Auth required: NO

+ +

Success Response

+ +

Code: 200 OK

+ +

Content example

+ + +
+[
+  {
+    "name": "MusicBot",
+    "state": "Playing",
+    "volume": 0.5,
+    "position": {
+      "secs": 10,
+      "nanos": 63573687
+    },
+    "currently_playing": {
+      "url": "<temp_url>",
+      "webpage_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
+      "title": "Rick Astley - Never Gonna Give You Up (Video)",
+      "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
+      "duration": {
+        "secs": 212,
+        "nanos": 0
+      }
+    },
+    "playlist": [
+      {
+        "url": "<temp_url>",
+        "webpage_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
+        "title": "Rick Astley - Never Gonna Give You Up (Video)",
+        "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
+        "duration": {
+          "secs": 212,
+          "nanos": 0
+        }
+      }
+    ]
+  }
+]
+
+ + +

Show Bot

+

Show a specific bot.

+ +

URL: /api/bots/:botname

+

Method: GET

+

Auth required: NO

+ +

Success Response

+

Code: 200 OK

+ +

Content example

+ + +
+{
+  "name": "MusicBot",
+  "state": "Playing",
+  "volume": 0.5,
+  "position": {
+    "secs": 142,
+    "nanos": 690911766
+  },
+  "currently_playing": {
+    "url": "<temp_url>",
+    "webpage_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
+    "title": "Rick Astley - Never Gonna Give You Up (Video)",
+    "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
+    "duration": {
+      "secs": 212,
+      "nanos": 0
+    }
+  },
+  "playlist": [
+    {
+      "url": "<temp_url>",
+      "webpage_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
+      "title": "Rick Astley - Never Gonna Give You Up (Video)",
+      "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
+      "duration": {
+        "secs": 212,
+        "nanos": 0
+      }
+    }
+  ]
+}
+
+ +

Error Response

+ +

Condition: If ':botname' is not connected to TeamSpeak.

+ +

Code: 404 NOT FOUND

+ +Content: + + +
+{
+  "error": "Not Found",
+  "description": "The requested resource was not found"
+}
+
+ +{% endblock %} diff --git a/web_server/templates/index.htm b/web_server/templates/index.htm new file mode 100644 index 0000000..eed31f3 --- /dev/null +++ b/web_server/templates/index.htm @@ -0,0 +1,36 @@ +{% extends "base.htm" %} + +{% block title %}Overview{% endblock %} + +{% block content %} +

Bots

+
+ + +
+ + + +{% endblock %} diff --git a/web_server/templates/song.htm b/web_server/templates/song.htm new file mode 100644 index 0000000..072567a --- /dev/null +++ b/web_server/templates/song.htm @@ -0,0 +1,7 @@ +{{ item.title }} +({{ item.duration|fmt_duration }}) +{% match item.thumbnail %} + {% when Some with (thumbnail) %} + + {% when None %} +{% endmatch %} diff --git a/web_server/templates/tmtu/index.htm b/web_server/templates/tmtu/index.htm new file mode 100644 index 0000000..785e653 --- /dev/null +++ b/web_server/templates/tmtu/index.htm @@ -0,0 +1,145 @@ + + + + tmtu mode + + + + + + + + {% match bot %} + {% when Some with (bot) %} + + + + + + + {% when None %} + {% endmatch %} +
+

PokeBot

+

A web interface for inspecting currently playing audio in PokeBot. Select an instance of the bot to view it's playlist and history.

+ +
+

Status

+
+ {% match bot.currently_playing %} + {% when Some with (current) %} +

Currently playing: {{ current.title }}

+

{{ bot.position|fmt_duration }} / {{ current.duration|fmt_duration }} + {% match current.duration %} + {% when Some with (duration) %} + {% let position %} + {% match bot.position %} + {% when Some with (pos) %} + {% let position = pos.as_secs_f64() %} + {% when None %} + {% let position = 0.0 %} + {% endmatch %} + {% let progress = position / duration.as_secs_f64() %} + {% let percent = progress * 100.0 %} +

+ {% when None %} +

+ {% endmatch %} + {% when None %} + {% endmatch %} +
+
+

Playlist

+ + + + + + + + {% for item in bot.playlist %} + + + + + + + {% endfor %} +
#tracklengthadded by
{{ loop.index }}{{ item.title }} + {% let duration = item.duration %} + {{ duration|fmt_duration }} + {{ item.added_by }}
+
+ + -- cgit v1.2.3-70-g09d2