Commit 7592fd36 authored by jan.koester's avatar jan.koester
Browse files

public media methods

parent f1812495
Loading
Loading
Loading
Loading
+45 −1
Changes for plugins/media/media.cpp: 45 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ namespace blogi {
            std::string _lang = getLang(*Args->database[tid]);
            std::string albumname;
            std::string selectedStore;
            bool makePublic = false;

            libhttppp::HttpForm form;
            form.parse(req);
@@ -180,13 +181,18 @@ namespace blogi {
                    albumname=curdat.value;
                else if(curdat.key=="store_name")
                    selectedStore=curdat.value;
                else if(curdat.key=="album_public")
                    makePublic = (curdat.value=="on" || curdat.value=="1" || curdat.value=="true");
            }

            if(!albumname.empty() && !selectedStore.empty()){
                std::string token = _getSessionToken(tid, sessionid);
                _ensureMdbReady(tid, token);
                std::string storeId = _getStoreId(tid, selectedStore);
                _mdb[tid]->create_album(storeId, albumname);
                auto album = _mdb[tid]->create_album(storeId, albumname);
                if(makePublic){
                    _mdb[tid]->set_album_public(album.id, true);
                }
            }

            // Return a form JSON for creating new album
@@ -219,6 +225,12 @@ namespace blogi {
            json_object_object_add(jfAlbum, "value", json_object_new_string(""));
            json_object_array_add(jfields, jfAlbum);

            json_object *jfPublic = json_object_new_object();
            json_object_object_add(jfPublic, "name", json_object_new_string("album_public"));
            json_object_object_add(jfPublic, "label", json_object_new_string(tr(_lang,"Public").c_str()));
            json_object_object_add(jfPublic, "type", json_object_new_string("checkbox"));
            json_object_array_add(jfields, jfPublic);

            json_object_object_add(jform, "fields", jfields);
            json_object_object_add(jform, "submit", json_object_new_string(tr(_lang,"create").c_str()));
            json_object_object_add(jroot, "form", jform);
@@ -660,6 +672,28 @@ namespace blogi {
                }
            }

            if(suburl=="togglepublic"){
                std::string albumId;
                libhttppp::HttpForm form;
                form.parse(req);
                for(const auto &curdat : form.urlData()){
                    if(curdat.key=="albumid")
                        albumId=curdat.value;
                }
                if(!albumId.empty()){
                    try {
                        std::string _sessionToken = _getSessionToken(tid, sessionid);
                        _ensureMdbReady(tid, _sessionToken);
                        auto album = _mdb[tid]->get_album(albumId);
                        _mdb[tid]->set_album_public(albumId, !album.is_public);
                    } catch(std::exception &e) {
                        std::cerr << "media: togglepublic failed: " << e.what() << std::endl;
                    } catch(...) {
                        std::cerr << "media: togglepublic failed" << std::endl;
                    }
                }
            }

            if(suburl=="config"){
                return settingsConfig(tid,req);
            }
@@ -736,6 +770,7 @@ namespace blogi {
            json_object_array_add(jheaders, json_object_new_string(tr(_lang,"Store").c_str()));
            json_object_array_add(jheaders, json_object_new_string(tr(_lang,"Album name").c_str()));
            json_object_array_add(jheaders, json_object_new_string(tr(_lang,"Media count").c_str()));
            json_object_array_add(jheaders, json_object_new_string(tr(_lang,"Visibility").c_str()));
            json_object_array_add(jheaders, json_object_new_string(tr(_lang,"Created").c_str()));
            json_object_array_add(jheaders, json_object_new_string(tr(_lang,"Actions").c_str()));
            json_object_object_add(jtable, "headers", jheaders);
@@ -761,6 +796,8 @@ namespace blogi {
                    json_object_array_add(jcells, json_object_new_string(storeName.c_str()));
                    json_object_array_add(jcells, json_object_new_string(album.name.c_str()));
                    json_object_array_add(jcells, json_object_new_string(std::to_string(album.media_count).c_str()));
                    json_object_array_add(jcells, json_object_new_string(
                        album.is_public ? tr(_lang,"Public").c_str() : tr(_lang,"Private").c_str()));
                    json_object_array_add(jcells, json_object_new_string(album.created_at.c_str()));
                    json_object_object_add(jrow, "cells", jcells);

@@ -772,6 +809,13 @@ namespace blogi {
                    json_object_object_add(jview, "url", json_object_new_string(viewUrl.c_str()));
                    json_object_array_add(jactions, jview);

                    json_object *jtoggle = json_object_new_object();
                    json_object_object_add(jtoggle, "label", json_object_new_string(
                        album.is_public ? tr(_lang,"Make Private").c_str() : tr(_lang,"Make Public").c_str()));
                    std::string toggleUrl = Args->config->buildurl("settings/media/togglepublic?") + "albumid=" + album.id;
                    json_object_object_add(jtoggle, "url", json_object_new_string(toggleUrl.c_str()));
                    json_object_array_add(jactions, jtoggle);

                    json_object *jremove = json_object_new_object();
                    json_object_object_add(jremove, "label", json_object_new_string(tr(_lang,"Remove").c_str()));
                    std::string removeUrl = Args->config->buildurl("settings/media/delalbum?") + "albumid=" + album.id;