mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
move "determining last updated date" to the server
This commit is contained in:
@@ -12,6 +12,8 @@ from app.lib import playlistlib
|
|||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
from flask import request
|
from flask import request
|
||||||
|
|
||||||
|
from app.helpers import create_new_date
|
||||||
|
|
||||||
playlist_bp = Blueprint("playlist", __name__, url_prefix="/")
|
playlist_bp = Blueprint("playlist", __name__, url_prefix="/")
|
||||||
|
|
||||||
PlaylistExists = exceptions.PlaylistExists
|
PlaylistExists = exceptions.PlaylistExists
|
||||||
@@ -38,7 +40,7 @@ def create_playlist():
|
|||||||
"name": data["name"],
|
"name": data["name"],
|
||||||
"description": "",
|
"description": "",
|
||||||
"pre_tracks": [],
|
"pre_tracks": [],
|
||||||
"lastUpdated": data["lastUpdated"],
|
"lastUpdated": create_new_date(),
|
||||||
"image": "",
|
"image": "",
|
||||||
"thumb": "",
|
"thumb": "",
|
||||||
}
|
}
|
||||||
@@ -99,7 +101,7 @@ def update_playlist(playlistid: str):
|
|||||||
playlist = {
|
playlist = {
|
||||||
"name": str(data.get("name")).strip(),
|
"name": str(data.get("name")).strip(),
|
||||||
"description": str(data.get("description").strip()),
|
"description": str(data.get("description").strip()),
|
||||||
"lastUpdated": str(data.get("lastUpdated")),
|
"lastUpdated": create_new_date(),
|
||||||
"image": None,
|
"image": None,
|
||||||
"thumb": None,
|
"thumb": None,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ from app import db
|
|||||||
from app import models
|
from app import models
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
|
||||||
|
from app.helpers import create_new_date
|
||||||
|
|
||||||
convert_many = db.convert_many
|
convert_many = db.convert_many
|
||||||
convert_one = db.convert_one
|
convert_one = db.convert_one
|
||||||
|
|
||||||
@@ -23,12 +25,8 @@ class Playlists(db.Mongo):
|
|||||||
Inserts a new playlist object into the database.
|
Inserts a new playlist object into the database.
|
||||||
"""
|
"""
|
||||||
return self.collection.update_one(
|
return self.collection.update_one(
|
||||||
{
|
{"name": playlist["name"]},
|
||||||
"name": playlist["name"]
|
{"$set": playlist},
|
||||||
},
|
|
||||||
{
|
|
||||||
"$set": playlist
|
|
||||||
},
|
|
||||||
upsert=True,
|
upsert=True,
|
||||||
).upserted_id
|
).upserted_id
|
||||||
|
|
||||||
@@ -50,12 +48,13 @@ class Playlists(db.Mongo):
|
|||||||
"""
|
"""
|
||||||
Adds a track to a playlist.
|
Adds a track to a playlist.
|
||||||
"""
|
"""
|
||||||
|
date = create_new_date()
|
||||||
|
|
||||||
return self.collection.update_one(
|
return self.collection.update_one(
|
||||||
{"_id": ObjectId(playlistid)},
|
{
|
||||||
{"$push": {
|
"_id": ObjectId(playlistid),
|
||||||
"pre_tracks": track
|
},
|
||||||
}},
|
{"$push": {"pre_tracks": track}, "$set": {"lastUpdated": date}},
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_playlist_by_name(self, name: str) -> dict:
|
def get_playlist_by_name(self, name: str) -> dict:
|
||||||
|
|||||||
+5
-13
@@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
This module contains mini functions for the server.
|
This module contains mini functions for the server.
|
||||||
"""
|
"""
|
||||||
import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import threading
|
import threading
|
||||||
@@ -114,21 +114,13 @@ def check_artist_image(image: str) -> str:
|
|||||||
return img_name
|
return img_name
|
||||||
|
|
||||||
|
|
||||||
class Timer:
|
|
||||||
begin: int = 0
|
|
||||||
end: int = 0
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
self.begin = time.time()
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
self.end = time.time()
|
|
||||||
print(str(datetime.timedelta(seconds=round(self.end - self.begin))))
|
|
||||||
|
|
||||||
|
|
||||||
def create_album_hash(title: str, artist: str) -> str:
|
def create_album_hash(title: str, artist: str) -> str:
|
||||||
"""
|
"""
|
||||||
Creates a simple hash for an album
|
Creates a simple hash for an album
|
||||||
"""
|
"""
|
||||||
return (title + artist).replace(" ", "").lower()
|
return (title + artist).replace(" ", "").lower()
|
||||||
|
|
||||||
|
def create_new_date():
|
||||||
|
now = datetime.now()
|
||||||
|
str = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
return str
|
||||||
@@ -145,6 +145,7 @@ class Playlist:
|
|||||||
if track not in self._pre_tracks:
|
if track not in self._pre_tracks:
|
||||||
self._pre_tracks.append(track)
|
self._pre_tracks.append(track)
|
||||||
self.update_count()
|
self.update_count()
|
||||||
|
self.lastUpdated = helpers.create_new_date()
|
||||||
else:
|
else:
|
||||||
raise TrackExistsInPlaylist("Track already exists in playlist")
|
raise TrackExistsInPlaylist("Track already exists in playlist")
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import { onMounted, ref } from "vue";
|
|||||||
import { Playlist } from "../../interfaces";
|
import { Playlist } from "../../interfaces";
|
||||||
import { updatePlaylist } from "../../composables/playlists";
|
import { updatePlaylist } from "../../composables/playlists";
|
||||||
import usePStore from "../../stores/p.ptracks";
|
import usePStore from "../../stores/p.ptracks";
|
||||||
import { getCurrentDate } from "../../composables/perks";
|
|
||||||
|
|
||||||
const pStore = usePStore();
|
const pStore = usePStore();
|
||||||
|
|
||||||
@@ -103,7 +102,6 @@ function update_playlist(e: Event) {
|
|||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
|
|
||||||
formData.append("image", image);
|
formData.append("image", image);
|
||||||
formData.append("lastUpdated", getCurrentDate());
|
|
||||||
|
|
||||||
if (formData.get("name").toString().trim() !== "") {
|
if (formData.get("name").toString().trim() !== "") {
|
||||||
updatePlaylist(props.playlist.playlistid, formData, pStore).then(() => {
|
updatePlaylist(props.playlist.playlistid, formData, pStore).then(() => {
|
||||||
|
|||||||
@@ -75,24 +75,10 @@ function formatSeconds(seconds) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCurrentDate() {
|
|
||||||
const date = new Date();
|
|
||||||
|
|
||||||
const yyyy = date.getFullYear();
|
|
||||||
const mm = date.getMonth() + 1;
|
|
||||||
const dd = date.getDate();
|
|
||||||
|
|
||||||
const hh = date.getHours();
|
|
||||||
const min = date.getMinutes();
|
|
||||||
const sec = date.getSeconds();
|
|
||||||
|
|
||||||
return `${yyyy}-${mm}-${dd} ${hh}:${min}:${sec}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
putCommas,
|
putCommas,
|
||||||
focusCurrent,
|
focusCurrent,
|
||||||
formatSeconds,
|
formatSeconds,
|
||||||
getElem,
|
getElem,
|
||||||
getCurrentDate,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import axios from "axios";
|
|||||||
import { Playlist, Track } from "../interfaces";
|
import { Playlist, Track } from "../interfaces";
|
||||||
import { Notification, NotifType } from "../stores/notification";
|
import { Notification, NotifType } from "../stores/notification";
|
||||||
import state from "./state";
|
import state from "./state";
|
||||||
import { getCurrentDate } from "../composables/perks";
|
|
||||||
/**
|
/**
|
||||||
* Creates a new playlist on the server.
|
* Creates a new playlist on the server.
|
||||||
* @param playlist_name The name of the playlist to create.
|
* @param playlist_name The name of the playlist to create.
|
||||||
@@ -13,7 +12,6 @@ async function createNewPlaylist(playlist_name: string, track?: Track) {
|
|||||||
await axios
|
await axios
|
||||||
.post(state.settings.uri + "/playlist/new", {
|
.post(state.settings.uri + "/playlist/new", {
|
||||||
name: playlist_name,
|
name: playlist_name,
|
||||||
lastUpdated: getCurrentDate(),
|
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
new Notification("✅ Playlist created successfullly!");
|
new Notification("✅ Playlist created successfullly!");
|
||||||
@@ -29,7 +27,7 @@ async function createNewPlaylist(playlist_name: string, track?: Track) {
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err.response.status == 409) {
|
if (err.response.status == 409) {
|
||||||
new Notification(
|
new Notification(
|
||||||
"That playlist already exists ... you might want to try another name!",
|
"That playlist already exists",
|
||||||
NotifType.Error
|
NotifType.Error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user