From ef68cae625eb31d90469e48dab640aeb068e3973 Mon Sep 17 00:00:00 2001 From: Mungai Geoffrey Date: Thu, 21 Apr 2022 03:29:42 +0300 Subject: [PATCH] Use gunicorn instead of Werkzeug and 32 more very minor changes (#35) --- package.json | 3 +- server/app/__init__.py | 6 +- server/app/api/album.py | 9 +- server/app/lib/playlistlib.py | 6 + server/app/serializer.py | 14 +- server/start.sh | 9 +- src/App.vue | 7 +- src/components/AlbumView/Header.vue | 13 +- src/components/FolderView/SongList.vue | 12 +- src/components/LeftSidebar/SongCard.vue | 8 +- src/components/LeftSidebar/nowPlaying.vue | 2 +- src/components/Notification.vue | 2 +- src/components/PlaylistView/Header.vue | 2 +- src/components/RightSideBar/Search.vue | 7 +- src/components/RightSideBar/SearchInput.vue | 21 +- .../RightSideBar/queue/playingFrom.vue | 33 +- src/components/Search/LoadMore.vue | 15 +- src/components/Search/TracksGrid.vue | 63 ++- src/components/nav/NavBar.vue | 24 +- src/components/playlists/PlaylistCard.vue | 1 + src/components/shared/Loader.vue | 12 +- src/components/shared/Option.vue | 4 +- src/components/shared/SongItem.vue | 19 - src/composables/enums.ts | 1 + src/composables/keyboard.ts | 78 +++ src/composables/perks.js | 75 --- src/interfaces.ts | 6 + src/stores/album.ts | 2 +- src/stores/loader.ts | 26 + src/stores/queue.ts | 16 +- src/stores/{tabs.js => tabs.ts} | 2 +- src/views/FolderView.vue | 6 +- yarn.lock | 474 +++++++++++++++++- 33 files changed, 751 insertions(+), 227 deletions(-) create mode 100644 src/composables/keyboard.ts create mode 100644 src/stores/loader.ts rename src/stores/{tabs.js => tabs.ts} (95%) diff --git a/package.json b/package.json index 5f276402..14d6259b 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,9 @@ "lint": "eslint --ext .js,.vue --ignore-path .gitignore --fix src" }, "dependencies": { - "axios": "^0.26.0", + "axios": "^0.26.1", "mitt": "^3.0.0", + "node-vibrant": "^3.2.1-alpha.1", "pinia": "^2.0.11", "register-service-worker": "^1.7.1", "sass": "^1.49.0", diff --git a/server/app/__init__.py b/server/app/__init__.py index a1331bc6..b74f967d 100644 --- a/server/app/__init__.py +++ b/server/app/__init__.py @@ -1,7 +1,6 @@ from flask import Flask -from flask_cors import CORS - from flask_caching import Cache +from flask_cors import CORS config = {"CACHE_TYPE": "SimpleCache", "CACHE_DEFAULT_TIMEOUT": 300} @@ -19,7 +18,7 @@ def create_app(): cache.init_app(app) with app.app_context(): - from app.api import artist, track, search, folder, album, playlist + from app.api import album, artist, folder, playlist, search, track app.register_blueprint(album.album_bp, url_prefix="/") app.register_blueprint(artist.artist_bp, url_prefix="/") @@ -28,5 +27,4 @@ def create_app(): app.register_blueprint(folder.folder_bp, url_prefix="/") app.register_blueprint(playlist.playlist_bp, url_prefix="/") - return app diff --git a/server/app/api/album.py b/server/app/api/album.py index abc4d063..67f60c4b 100644 --- a/server/app/api/album.py +++ b/server/app/api/album.py @@ -1,12 +1,13 @@ """ Contains all the album routes. """ - -from flask import Blueprint, request from app import api -from app import helpers, cache from app import functions -from app.lib import albumslib, trackslib +from app import helpers +from app.lib import albumslib +from app.lib import trackslib +from flask import Blueprint +from flask import request album_bp = Blueprint("album", __name__, url_prefix="") diff --git a/server/app/lib/playlistlib.py b/server/app/lib/playlistlib.py index bbc8b7b1..90fa81bf 100644 --- a/server/app/lib/playlistlib.py +++ b/server/app/lib/playlistlib.py @@ -4,6 +4,7 @@ This library contains all the functions related to playlists. import os import random import string +from datetime import datetime from app import api from app import exceptions @@ -55,6 +56,7 @@ def create_all_playlists(): playlists = instances.playlist_instance.get_all_playlists() _bar = Bar("Creating playlists", max=len(playlists)) + for playlist in playlists: api.PLAYLISTS.append(models.Playlist(playlist)) @@ -132,3 +134,7 @@ def validate_images(): for image in os.listdir(p_path): if image not in images: os.remove(os.path.join(p_path, image)) + + +def create_new_date(): + return datetime.now() diff --git a/server/app/serializer.py b/server/app/serializer.py index 2e3bf78e..b0e5d102 100644 --- a/server/app/serializer.py +++ b/server/app/serializer.py @@ -4,16 +4,17 @@ from datetime import datetime from app import models -def date_string_to_time_passed(dstring: str) -> str: +def date_string_to_time_passed(prev_date: str) -> str: """ Converts a date string to time passed. eg. 2 minutes ago, 1 hour ago, yesterday, 2 days ago, 2 weeks ago, etc. """ now = datetime.now() - then = datetime.strptime(dstring, "%Y-%m-%d %H:%M:%S") + then = datetime.strptime(prev_date, "%Y-%m-%d %H:%M:%S") diff = now - then days = diff.days + print(days) if days < 0: return "in the future" @@ -32,22 +33,19 @@ def date_string_to_time_passed(dstring: str) -> str: elif days == 1: return "yesterday" elif days < 7: - if days == 1: - return "1 day ago" - return str(days) + " days ago" elif days < 30: - if days == 7: + if days < 14: return "1 week ago" return str(days // 7) + " weeks ago" elif days < 365: - if days == 30: + if days < 60: return "1 month ago" return str(days // 30) + " months ago" elif days > 365: - if days == 365: + if days < 730: return "1 year ago" return str(days // 365) + " years ago" diff --git a/server/start.sh b/server/start.sh index a509bcc8..5cceeae4 100755 --- a/server/start.sh +++ b/server/start.sh @@ -1,9 +1,8 @@ +# ppath=$(poetry run which python) -ppath=$(poetry run which python) - -$ppath manage.py - +# $ppath manage.py #python manage.py +gpath=$(poetry run which gunicorn) -# gunicorn -b 0.0.0.0:9876 --workers=4 "wsgi:create_app()" --log-level=debug +"$gpath" -b 0.0.0.0:9876 -w 1 --threads=4 "manage:create_app()" #--log-level=debug diff --git a/src/App.vue b/src/App.vue index aa01e0f6..2ab5990a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,9 +9,9 @@ > - +
- +
@@ -40,6 +40,7 @@ import ContextMenu from "./components/contextMenu.vue"; import Modal from "./components/modal.vue"; import Notification from "./components/Notification.vue"; import useQStore from "./stores/queue"; +import shortcuts from "./composables/keyboard"; const context_store = useContextStore(); const queue = useQStore(); @@ -48,7 +49,7 @@ queue.readQueueFromLocalStorage(); const RightSideBar = Main; -const collapsed = ref(false); +shortcuts(queue); const app_dom = document.getElementById("app"); diff --git a/src/components/AlbumView/Header.vue b/src/components/AlbumView/Header.vue index a9ba96a3..50b0d90c 100644 --- a/src/components/AlbumView/Header.vue +++ b/src/components/AlbumView/Header.vue @@ -32,9 +32,16 @@ import perks from "../../composables/perks.js"; import { AlbumInfo } from "../../interfaces.js"; import PlayBtnRect from "../shared/PlayBtnRect.vue"; import { playSources } from "../../composables/enums"; + const props = defineProps<{ album: AlbumInfo; }>(); + +function extrackColors() { + +} + +extrackColors(); diff --git a/src/components/nav/NavBar.vue b/src/components/nav/NavBar.vue index 05b92149..706fce08 100644 --- a/src/components/nav/NavBar.vue +++ b/src/components/nav/NavBar.vue @@ -11,6 +11,8 @@
+