mirror of
https://github.com/krateng/maloja.git
synced 2025-07-09 03:04:07 -04:00
Implemented server logic for association, fix GH-227
This commit is contained in:
parent
d645707ff1
commit
0032d0b70a
@ -767,6 +767,40 @@ def merge_artists(target_id,source_ids):
|
|||||||
"status":"success"
|
"status":"success"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@api.post("associate_albums_to_artist")
|
||||||
|
@authenticated_function(api=True)
|
||||||
|
@catch_exceptions
|
||||||
|
def associate_albums_to_artist(target_id,source_ids):
|
||||||
|
result = database.associate_albums_to_artist(target_id,source_ids)
|
||||||
|
if result:
|
||||||
|
return {
|
||||||
|
"status":"success",
|
||||||
|
"desc":f"{result['target']} was added as album artist of {', '.join(src['albumtitle'] for src in result['sources'])}"
|
||||||
|
}
|
||||||
|
|
||||||
|
@api.post("associate_tracks_to_artist")
|
||||||
|
@authenticated_function(api=True)
|
||||||
|
@catch_exceptions
|
||||||
|
def associate_tracks_to_artist(target_id,source_ids):
|
||||||
|
result = database.associate_tracks_to_artist(target_id,source_ids)
|
||||||
|
if result:
|
||||||
|
return {
|
||||||
|
"status":"success",
|
||||||
|
"desc":f"{result['target']} was added as artist for {', '.join(src['title'] for src in result['sources'])}"
|
||||||
|
}
|
||||||
|
|
||||||
|
@api.post("associate_tracks_to_album")
|
||||||
|
@authenticated_function(api=True)
|
||||||
|
@catch_exceptions
|
||||||
|
def associate_tracks_to_album(target_id,source_ids):
|
||||||
|
result = database.associate_tracks_to_album(target_id,source_ids)
|
||||||
|
if result:
|
||||||
|
return {
|
||||||
|
"status":"success",
|
||||||
|
"desc":f"{', '.join(src['title'] for src in result['sources'])} were added to {result['target']['albumtitle']}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@api.post("reparse_scrobble")
|
@api.post("reparse_scrobble")
|
||||||
@authenticated_function(api=True)
|
@authenticated_function(api=True)
|
||||||
@catch_exceptions
|
@catch_exceptions
|
||||||
|
@ -265,6 +265,43 @@ def merge_albums(target_id,source_ids):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@waitfordb
|
||||||
|
def associate_albums_to_artist(target_id,source_ids):
|
||||||
|
sources = [sqldb.get_album(id) for id in source_ids]
|
||||||
|
target = sqldb.get_artist(target_id)
|
||||||
|
log(f"Adding {sources} into {target}")
|
||||||
|
sqldb.add_artists_to_albums(artist_ids=[target_id],album_ids=source_ids)
|
||||||
|
result = {'sources':sources,'target':target}
|
||||||
|
dbcache.invalidate_entity_cache()
|
||||||
|
dbcache.invalidate_caches()
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
@waitfordb
|
||||||
|
def associate_tracks_to_artist(target_id,source_ids):
|
||||||
|
sources = [sqldb.get_track(id) for id in source_ids]
|
||||||
|
target = sqldb.get_artist(target_id)
|
||||||
|
log(f"Adding {sources} into {target}")
|
||||||
|
sqldb.add_artists_to_tracks(artist_ids=[target_id],track_ids=source_ids)
|
||||||
|
result = {'sources':sources,'target':target}
|
||||||
|
dbcache.invalidate_entity_cache()
|
||||||
|
dbcache.invalidate_caches()
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
@waitfordb
|
||||||
|
def associate_tracks_to_album(target_id,source_ids):
|
||||||
|
sources = [sqldb.get_track(id) for id in source_ids]
|
||||||
|
target = sqldb.get_album(target_id)
|
||||||
|
log(f"Adding {sources} into {target}")
|
||||||
|
sqldb.add_tracks_to_albums({src:target_id for src in source_ids})
|
||||||
|
result = {'sources':sources,'target':target}
|
||||||
|
dbcache.invalidate_entity_cache()
|
||||||
|
dbcache.invalidate_caches()
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@waitfordb
|
@waitfordb
|
||||||
def get_scrobbles(dbconn=None,**keys):
|
def get_scrobbles(dbconn=None,**keys):
|
||||||
|
@ -555,7 +555,7 @@ def edit_scrobble(scrobble_id,scrobbleupdatedict,dbconn=None):
|
|||||||
|
|
||||||
dbconn.execute(op)
|
dbconn.execute(op)
|
||||||
|
|
||||||
|
# edit function only for primary db information (not linked fields)
|
||||||
@connection_provider
|
@connection_provider
|
||||||
def edit_artist(id,artistupdatedict,dbconn=None):
|
def edit_artist(id,artistupdatedict,dbconn=None):
|
||||||
|
|
||||||
@ -578,6 +578,7 @@ def edit_artist(id,artistupdatedict,dbconn=None):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# edit function only for primary db information (not linked fields)
|
||||||
@connection_provider
|
@connection_provider
|
||||||
def edit_track(id,trackupdatedict,dbconn=None):
|
def edit_track(id,trackupdatedict,dbconn=None):
|
||||||
|
|
||||||
@ -600,6 +601,7 @@ def edit_track(id,trackupdatedict,dbconn=None):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# edit function only for primary db information (not linked fields)
|
||||||
@connection_provider
|
@connection_provider
|
||||||
def edit_album(id,albumupdatedict,dbconn=None):
|
def edit_album(id,albumupdatedict,dbconn=None):
|
||||||
|
|
||||||
@ -623,6 +625,37 @@ def edit_album(id,albumupdatedict,dbconn=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
### Edit associations
|
||||||
|
|
||||||
|
@connection_provider
|
||||||
|
def add_artists_to_tracks(track_ids,artist_ids,dbconn=None):
|
||||||
|
|
||||||
|
op = DB['trackartists'].insert().values([
|
||||||
|
{'track_id':track_id,'artist_id':artist_id}
|
||||||
|
for track_id in track_ids for artist_id in artist_ids
|
||||||
|
])
|
||||||
|
|
||||||
|
result = dbconn.execute(op)
|
||||||
|
clean_db(dbconn=dbconn)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@connection_provider
|
||||||
|
def add_artists_to_albums(album_ids,artist_ids,dbconn=None):
|
||||||
|
|
||||||
|
op = DB['albumartists'].insert().values([
|
||||||
|
{'album_id':album_id,'artist_id':artist_id}
|
||||||
|
for album_id in album_ids for artist_id in artist_ids
|
||||||
|
])
|
||||||
|
|
||||||
|
result = dbconn.execute(op)
|
||||||
|
clean_db(dbconn=dbconn)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Merge
|
### Merge
|
||||||
|
|
||||||
@connection_provider
|
@connection_provider
|
||||||
|
@ -209,7 +209,7 @@ div#notification_area {
|
|||||||
div#notification_area div.notification {
|
div#notification_area div.notification {
|
||||||
background-color:white;
|
background-color:white;
|
||||||
width:400px;
|
width:400px;
|
||||||
height:50px;
|
min-height:50px;
|
||||||
margin-bottom:7px;
|
margin-bottom:7px;
|
||||||
padding:9px;
|
padding:9px;
|
||||||
opacity:0.4;
|
opacity:0.4;
|
||||||
|
@ -247,6 +247,13 @@ function showValidMergeIcons() {
|
|||||||
associationmarkicon.classList.remove('hide');
|
associationmarkicon.classList.remove('hide');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entity_type == 'track') {
|
||||||
|
associationmarkicon.title = "Mark this track to add to album or add artist";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
associationmarkicon.title = "Mark this album to add artist";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -356,29 +363,32 @@ function associate() {
|
|||||||
var current_stored = (lcst.getItem(key) || '').split(",");
|
var current_stored = (lcst.getItem(key) || '').split(",");
|
||||||
current_stored = current_stored.filter((x)=>x).map((x)=>parseInt(x));
|
current_stored = current_stored.filter((x)=>x).map((x)=>parseInt(x));
|
||||||
|
|
||||||
callback_func = function(req){
|
if (current_stored.length != 0) {
|
||||||
if (req.status == 200) {
|
callback_func = function(req){
|
||||||
//window.location.reload();
|
if (req.status == 200) {
|
||||||
showValidMergeIcons();
|
//window.location.reload();
|
||||||
notifyCallback(req);
|
showValidMergeIcons();
|
||||||
}
|
notifyCallback(req);
|
||||||
else {
|
}
|
||||||
notifyCallback(req);
|
else {
|
||||||
}
|
notifyCallback(req);
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
neo.xhttpreq(
|
neo.xhttpreq(
|
||||||
"/apis/mlj_1/associate_" + target_entity_type + "s_to_" + entity_type,
|
"/apis/mlj_1/associate_" + target_entity_type + "s_to_" + entity_type,
|
||||||
data={
|
data={
|
||||||
'source_ids':current_stored,
|
'source_ids':current_stored,
|
||||||
'target_id':entity_id
|
'target_id':entity_id
|
||||||
},
|
},
|
||||||
method="POST",
|
method="POST",
|
||||||
callback=callback_func,
|
callback=callback_func,
|
||||||
json=true
|
json=true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
lcst.removeItem(key);
|
||||||
|
}
|
||||||
|
|
||||||
lcst.removeItem(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user