From 925164e21db86e9a8b7732e1ae2ba82ff0acfeec Mon Sep 17 00:00:00 2001 From: "Simon V. Lejel" Date: Fri, 11 Mar 2022 18:09:49 +0100 Subject: [PATCH 1/4] Add database structure --- db/connector.py | 17 +++++++++++++++++ db/model/image_table.py | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 db/connector.py create mode 100644 db/model/image_table.py diff --git a/db/connector.py b/db/connector.py new file mode 100644 index 0000000..e262970 --- /dev/null +++ b/db/connector.py @@ -0,0 +1,17 @@ +import os + +from sqlalchemy import create_engine + +user = os.environ['DB_USER'] +password = os.environ['DB_PASSWORD'] +host = os.environ['DB_HOST'] +port = os.environ['DB_PORT'] +database = os.environ['DB_DATABASE'] + + +def get_connection(): + return create_engine( + url="mysql+pymysql://{0}:{1}@{2}:{3}/{4}".format( + user, password, host, port, database + ) + ) diff --git a/db/model/image_table.py b/db/model/image_table.py new file mode 100644 index 0000000..a6af713 --- /dev/null +++ b/db/model/image_table.py @@ -0,0 +1,18 @@ +import sqlalchemy as db + +from db import connector + +engine = connector.create_engine + +metadata_obj = db.MetaData() + +profile = db.Table( + 'images', + metadata_obj, + db.Column('id', db.Integer, primary_key=True), + db.Column('location', db.String), + db.Column('copyright', db.String), + db.Column('date_added', db.TIMESTAMP), +) + +metadata_obj.create_all(engine) From f5fe17fa5c8ef04329f1ac329af912959e3b082a Mon Sep 17 00:00:00 2001 From: "Simon V. Lejel" Date: Fri, 11 Mar 2022 18:11:38 +0100 Subject: [PATCH 2/4] Add styling --- static/css/styles.css | 26 ++++++++++++++++++++++++++ static/css/styles.css.map | 1 + static/css/styles.scss | 31 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 static/css/styles.css create mode 100644 static/css/styles.css.map diff --git a/static/css/styles.css b/static/css/styles.css new file mode 100644 index 0000000..9923b26 --- /dev/null +++ b/static/css/styles.css @@ -0,0 +1,26 @@ +body { + background-image: url("/random"); + height: 100vh; + width: 100vw; +} +body nav { + display: flex; + flex-direction: row; + justify-content: center; + background: rgba(0, 0, 0, 0.4); + width: 100vw; + padding: 0 20px; +} +body nav ul > li { + color: white; +} +body nav ul > li :hover { + color: #13678A; + animation: ease-in; +} +body h1 { + margin: auto; + text-align: center; +} + +/*# sourceMappingURL=styles.css.map */ diff --git a/static/css/styles.css.map b/static/css/styles.css.map new file mode 100644 index 0000000..c3ba649 --- /dev/null +++ b/static/css/styles.css.map @@ -0,0 +1 @@ +{"version":3,"sourceRoot":"","sources":["styles.scss"],"names":[],"mappings":"AAGA;EACE;EACA;EACA;;AAEA;EACE;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;;AAEA;EACE,OAnBD;EAoBC;;AAKN;EACE;EACA","file":"styles.css"} \ No newline at end of file diff --git a/static/css/styles.scss b/static/css/styles.scss index e69de29..e08a537 100644 --- a/static/css/styles.scss +++ b/static/css/styles.scss @@ -0,0 +1,31 @@ +// Variables +$blue: #13678A; + +body { + background-image: url("/random"); + height: 100vh; + width: 100vw; + + nav { + display: flex; + flex-direction: row; + justify-content: center; + background: rgba(0, 0, 0, 0.4); + width: 100vw; + padding: 0 20px; + + ul > li { + color: white; + + :hover { + color: $blue; + animation: ease-in; + } + } + } + + h1 { + margin: auto; + text-align: center; + } +} \ No newline at end of file From 8238e9555af7f8bfcbe0bdaa68651e54330dacde Mon Sep 17 00:00:00 2001 From: "Simon V. Lejel" Date: Fri, 11 Mar 2022 18:11:54 +0100 Subject: [PATCH 3/4] Add HTML --- templates/home.html | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/templates/home.html b/templates/home.html index 001d90f..7a52053 100644 --- a/templates/home.html +++ b/templates/home.html @@ -3,8 +3,17 @@ DCSL Image Hosting Server + - + +

Welcome to the DCSL Image Hosting Server!

+

- Serving images since year 2022

\ No newline at end of file From 9f4e06d7f9240b437a4eff403a78ee984c0bb9d9 Mon Sep 17 00:00:00 2001 From: "Simon V. Lejel" Date: Fri, 11 Mar 2022 18:12:19 +0100 Subject: [PATCH 4/4] Add missing endpoints --- app.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index de3ce5f..9118387 100644 --- a/app.py +++ b/app.py @@ -4,8 +4,26 @@ app = Flask(__name__) @app.route('/') -def hello_world(): # put application's code here +def home(): # put application's code here return render_template('home.html') + +@app.route('/random') +def random_image(): + # TODO Implement + return NotImplementedError + + +@app.route('/daily') +def daily_image(): + # TODO Implement + return NotImplementedError + + +@app.route('/all') +def all_images(): + # TODO Implement + return NotImplementedError + if __name__ == '__main__': app.run(host='0.0.0.0')