2018-09-23 22:10:01 +00:00
|
|
|
var api = {};
|
|
|
|
|
|
|
|
/**************************************************************************************************/
|
|
|
|
api.albums = {};
|
|
|
|
|
|
|
|
api.albums._add_remove_photos =
|
|
|
|
function _add_remove_photos(album_id, photo_ids, add_or_remove, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url;
|
2018-09-23 22:10:01 +00:00
|
|
|
if (add_or_remove === "add")
|
|
|
|
{ url = `/album/${album_id}/add_photo`; }
|
|
|
|
else if (add_or_remove === "remove")
|
|
|
|
{ url = `/album/${album_id}/remove_photo`; }
|
|
|
|
else
|
|
|
|
{ throw `should be 'add' or 'remove', not ${add_or_remove}.`; }
|
|
|
|
|
2020-09-03 22:02:37 +00:00
|
|
|
let data = new FormData();
|
2018-09-23 22:10:01 +00:00
|
|
|
|
|
|
|
if (Array.isArray(photo_ids))
|
|
|
|
{ photo_ids = photo_ids.join(","); }
|
|
|
|
data.append("photo_id", photo_ids);
|
|
|
|
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.albums.add_child =
|
|
|
|
function add_child(album_id, child_id, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/album/${album_id}/add_child`;
|
|
|
|
let data = new FormData();
|
2018-09-23 22:10:01 +00:00
|
|
|
data.append("child_id", child_id);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.albums.add_photos =
|
|
|
|
function add_photos(album_id, photo_ids, callback)
|
|
|
|
{
|
|
|
|
api.albums._add_remove_photos(album_id, photo_ids, "add", callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.albums.create =
|
|
|
|
function create(title, parent_id, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/albums/create_album";
|
|
|
|
let data = new FormData();
|
2018-09-23 22:10:01 +00:00
|
|
|
if (title !== undefined)
|
|
|
|
{
|
|
|
|
data.append("title", title);
|
|
|
|
}
|
|
|
|
if (parent_id !== undefined)
|
|
|
|
{
|
|
|
|
data.append("parent_id", parent_id);
|
|
|
|
}
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.albums.delete =
|
|
|
|
function _delete(album_id, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/album/${album_id}/delete`;
|
2018-09-23 22:10:01 +00:00
|
|
|
common.post(url, null, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.albums.edit =
|
|
|
|
function edit(album_id, title, description, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/album/${album_id}/edit`;
|
|
|
|
let data = new FormData();
|
2018-09-23 22:10:01 +00:00
|
|
|
data.append("title", title);
|
|
|
|
data.append("description", description);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
2019-06-15 09:44:46 +00:00
|
|
|
api.albums.refresh_directories =
|
|
|
|
function refresh_directories(album_id, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/album/${album_id}/refresh_directories`;
|
2019-06-15 09:44:46 +00:00
|
|
|
common.post(url, null, callback);
|
|
|
|
}
|
|
|
|
|
2018-09-23 22:10:01 +00:00
|
|
|
api.albums.remove_child =
|
|
|
|
function remove_child(album_id, child_id, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/album/${album_id}/remove_child`;
|
|
|
|
let data = new FormData();
|
2018-09-23 22:10:01 +00:00
|
|
|
data.append("child_id", child_id);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.albums.remove_photos =
|
|
|
|
function remove_photos(album_id, photo_ids, callback)
|
|
|
|
{
|
|
|
|
api.albums._add_remove_photos(album_id, photo_ids, "remove", callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.albums.callback_follow =
|
|
|
|
function callback_follow(response)
|
|
|
|
{
|
|
|
|
if (response["meta"]["status"] == 200 && response["data"]["id"])
|
|
|
|
{
|
|
|
|
window.location.href = "/album/" + response["data"]["id"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
api.albums.callback_go_to_albums =
|
|
|
|
function callback_go_to_albums(response)
|
|
|
|
{
|
|
|
|
if (response["meta"]["status"] == 200)
|
|
|
|
{
|
|
|
|
window.location.href = "/albums";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************************************/
|
|
|
|
api.bookmarks = {};
|
|
|
|
|
2018-09-23 22:43:42 +00:00
|
|
|
api.bookmarks.create =
|
|
|
|
function create(b_url, title, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/bookmarks/create_bookmark";
|
|
|
|
let data = new FormData();
|
2018-09-23 22:43:42 +00:00
|
|
|
data.append("url", b_url.trim());
|
|
|
|
title = title.trim();
|
|
|
|
if (title)
|
|
|
|
{
|
|
|
|
data.append("title", title);
|
|
|
|
}
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.bookmarks.delete =
|
|
|
|
function _delete(bookmark_id, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/bookmark/${bookmark_id}/delete`;
|
2018-09-23 22:43:42 +00:00
|
|
|
common.post(url, null, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.bookmarks.edit =
|
2019-01-13 22:58:23 +00:00
|
|
|
function edit(bookmark_id, title, b_url, callback)
|
2018-09-23 22:43:42 +00:00
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/bookmark/${bookmark_id}/edit`;
|
|
|
|
let data = new FormData();
|
2018-09-23 22:43:42 +00:00
|
|
|
data.append("title", title.trim());
|
2019-01-13 22:58:23 +00:00
|
|
|
data.append("url", b_url.trim());
|
2018-09-23 22:43:42 +00:00
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
2018-09-23 22:10:01 +00:00
|
|
|
/**************************************************************************************************/
|
|
|
|
api.photos = {};
|
|
|
|
|
2018-09-23 22:52:19 +00:00
|
|
|
api.photos.add_tag =
|
|
|
|
function add_tag(photo_id, tagname, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/photo/${photo_id}/add_tag`;
|
|
|
|
let data = new FormData();
|
2018-09-23 22:52:19 +00:00
|
|
|
data.append("tagname", tagname);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
2020-08-31 02:18:06 +00:00
|
|
|
api.photos.batch_add_tag =
|
|
|
|
function batch_add_tag(photo_ids, tagname, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/batch/photos/add_tag";
|
|
|
|
let data = new FormData();
|
2020-08-31 02:18:06 +00:00
|
|
|
data.append("photo_ids", photo_ids.join(","));
|
|
|
|
data.append("tagname", tagname);
|
|
|
|
common.post(url, data, add_remove_tag_callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.photos.batch_refresh_metadata =
|
|
|
|
function batch_refresh_metadata(photo_ids, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/batch/photos/refresh_metadata";
|
|
|
|
let data = new FormData();
|
2020-08-31 02:18:06 +00:00
|
|
|
data.append("photo_ids", photo_ids.join(","));
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.photos.batch_remove_tag =
|
|
|
|
function batch_remove_tag(photo_ids, tagname, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/batch/photos/remove_tag";
|
|
|
|
let data = new FormData();
|
2020-08-31 02:18:06 +00:00
|
|
|
data.append("photo_ids", photo_ids.join(","));
|
|
|
|
data.append("tagname", tagname);
|
|
|
|
common.post(url, data, add_remove_tag_callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.photos.batch_set_searchhidden =
|
|
|
|
function batch_set_searchhidden(photo_ids, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/batch/photos/set_searchhidden";
|
|
|
|
let data = new FormData();
|
2020-08-31 02:18:06 +00:00
|
|
|
data.append("photo_ids", photo_ids.join(","));
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.photos.batch_unset_searchhidden =
|
|
|
|
function batch_unset_searchhidden(photo_ids, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/batch/photos/unset_searchhidden";
|
|
|
|
let data = new FormData();
|
2020-08-31 02:18:06 +00:00
|
|
|
data.append("photo_ids", photo_ids.join(","));
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
2020-02-27 02:57:29 +00:00
|
|
|
api.photos.delete =
|
|
|
|
function _delete(photo_id, delete_file, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/photo/${photo_id}/delete`;
|
|
|
|
let data = new FormData();
|
2020-02-27 02:57:29 +00:00
|
|
|
data.append("delete_file", delete_file);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
2020-01-12 22:52:03 +00:00
|
|
|
api.photos.generate_thumbnail =
|
|
|
|
function generate_thumbnail(photo_id, special, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/photo/${photo_id}/generate_thumbnail`
|
|
|
|
let data = new FormData();
|
2020-01-12 22:52:03 +00:00
|
|
|
for (x in special)
|
|
|
|
{
|
|
|
|
data.append(x, special[x]);
|
|
|
|
}
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
2020-08-31 02:18:06 +00:00
|
|
|
api.photos.get_download_zip_token =
|
|
|
|
function get_download_zip_token(photo_ids, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/batch/photos/download_zip";
|
|
|
|
let data = new FormData();
|
2020-08-31 02:18:06 +00:00
|
|
|
data.append("photo_ids", photo_ids.join(","));
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.photos.download_zip =
|
|
|
|
function download_zip(zip_token)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/batch/photos/download_zip/${zip_token}.zip`;
|
2020-08-31 02:18:06 +00:00
|
|
|
window.location.href = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
api.photos.callback_download_zip =
|
|
|
|
function callback_download_zip(response)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let zip_token = response.data.zip_token;
|
2020-08-31 02:18:06 +00:00
|
|
|
api.photos.download_zip(zip_token);
|
|
|
|
}
|
|
|
|
|
2018-09-23 22:52:19 +00:00
|
|
|
api.photos.refresh_metadata =
|
|
|
|
function refresh_metadata(photo_id, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/photo/${photo_id}/refresh_metadata`;
|
2018-09-23 22:52:19 +00:00
|
|
|
common.post(url, null, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.photos.remove_tag =
|
|
|
|
function remove_tag(photo_id, tagname, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/photo/${photo_id}/remove_tag`;
|
|
|
|
let data = new FormData();
|
2018-09-23 22:52:19 +00:00
|
|
|
data.append("tagname", tagname);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
2020-02-27 02:57:29 +00:00
|
|
|
api.photos.callback_go_to_search =
|
|
|
|
function callback_go_to_albums(response)
|
|
|
|
{
|
|
|
|
if (response["meta"]["status"] == 200)
|
|
|
|
{
|
|
|
|
window.location.href = "/search";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 22:10:01 +00:00
|
|
|
/**************************************************************************************************/
|
|
|
|
api.tags = {};
|
|
|
|
|
2018-09-23 23:41:34 +00:00
|
|
|
api.tags.add_child =
|
|
|
|
function add_child(tag_name, child_name, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/tag/${tag_name}/add_child`;
|
|
|
|
let data = new FormData();
|
2018-09-23 23:41:34 +00:00
|
|
|
data.append("child_name", child_name);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.tags.create =
|
|
|
|
function create(name, description, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/tags/create_tag`;
|
|
|
|
let data = new FormData();
|
2018-09-23 23:41:34 +00:00
|
|
|
data.append("name", name);
|
|
|
|
data.append("description", description);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.tags.delete =
|
|
|
|
function _delete(tag_name, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/tag/${tag_name}/delete`;
|
2018-09-23 23:41:34 +00:00
|
|
|
common.post(url, null, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.tags.easybake =
|
|
|
|
function easybake(easybake_string, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/tags/easybake";
|
|
|
|
let data = new FormData();
|
2018-09-23 23:41:34 +00:00
|
|
|
data.append("easybake_string", easybake_string);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.tags.edit =
|
|
|
|
function edit(tag_name, name, description, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/tag/${tag_name}/edit`;
|
|
|
|
let data = new FormData();
|
2018-09-23 23:41:34 +00:00
|
|
|
data.append("name", name);
|
|
|
|
data.append("description", description);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.tags.remove_child =
|
|
|
|
function remove_child(tag_name, child_name, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/tag/${tag_name}/remove_child`;
|
|
|
|
let data = new FormData();
|
2018-09-23 23:41:34 +00:00
|
|
|
data.append("child_name", child_name);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.tags.remove_synonym =
|
|
|
|
function remove_synonym(tag_name, syn_name, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = `/tag/${tag_name}/remove_synonym`;
|
|
|
|
let data = new FormData();
|
2018-09-23 23:41:34 +00:00
|
|
|
data.append("syn_name", syn_name);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
2020-02-27 22:57:27 +00:00
|
|
|
api.tags.callback_go_to_tags =
|
|
|
|
function callback_go_to_tags(response)
|
|
|
|
{
|
|
|
|
if (response["meta"]["status"] == 200)
|
|
|
|
{
|
|
|
|
window.location.href = "/tags";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log(response);
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 23:41:34 +00:00
|
|
|
|
2018-09-23 22:10:01 +00:00
|
|
|
/**************************************************************************************************/
|
|
|
|
api.users = {};
|
2018-09-23 23:50:27 +00:00
|
|
|
|
|
|
|
api.users.login =
|
|
|
|
function login(username, password, callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/login";
|
|
|
|
let data = new FormData();
|
2018-09-23 23:50:27 +00:00
|
|
|
data.append("username", username);
|
|
|
|
data.append("password", password);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.users.logout =
|
|
|
|
function logout(callback)
|
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/logout";
|
2018-09-23 23:50:27 +00:00
|
|
|
common.post(url, null, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.users.register =
|
2019-08-26 21:32:51 +00:00
|
|
|
function register(username, display_name, password_1, password_2, callback)
|
2018-09-23 23:50:27 +00:00
|
|
|
{
|
2020-09-03 22:02:37 +00:00
|
|
|
let url = "/register";
|
|
|
|
let data = new FormData();
|
2018-09-23 23:50:27 +00:00
|
|
|
data.append("username", username);
|
2019-08-26 21:32:51 +00:00
|
|
|
data.append("display_name", display_name);
|
2018-09-23 23:50:27 +00:00
|
|
|
data.append("password_1", password_1);
|
|
|
|
data.append("password_2", password_2);
|
|
|
|
common.post(url, data, callback);
|
|
|
|
}
|