NO-ob / LoliSnatcher_Droid

A booru client with support for batch downloading
GNU Affero General Public License v3.0
372 stars 23 forks source link

[Feature request] Add/Remove tags to Hydrus database item #149

Open GreenLandisaLie opened 1 year ago

GreenLandisaLie commented 1 year ago

I managed to add this feature in my private cloned repo. This is the cleaned version of the main method I use:

Future AddOrRemoveTags(BooruItem item, List<String> tagsList, bool isTagsToRemove) async {
    String url = "${booru.baseURL}/add_tags/add_tags";
    var dio = Dio();
    // notes: "my tags" works
    // "all known tags" does not work -.-
    // 0 to add
    // 1 to delete
    String addOrRemove = isTagsToRemove ? "1" : "0";
    Response dioResponse = await dio.post(url,
        options: Options(headers: {
            HttpHeaders.contentTypeHeader: "application/json",
            "Hydrus-Client-API-Access-Key":booru.apiKey!
        }),
        data: jsonEncode({
            "hash": item.md5String,
            "service_names_to_actions_to_tags": {
                "my tags": {
                    "$addOrRemove": tagsList
                }
            }
        }),
    );
    return fetched;
}

(for reference) I've implemented this 2 ways: 1 - I copied the share toolbar button and added a bunch of options for the tags I most commonly edit. When I click the button it will ADD the (selected) tag and when I hold it REMOVES it. Just like the share button this setting is saveable and the default action can be set in the settings (however I'm using hard-coded tags - in a public release the user should be able to set which tags they want to show up in the options). The top option is not a defined tag and instead it will prompt the user for a text (tag) - I did that following this basic tutorial. 2 - I added 2 buttons that show up when the user holds on a tag in the TagView.

2 1

EDIT: maybe change the first arg to a list of BooruItem and create a List of the item's hashes to be sent in the POST for when the user might want to use this feature from within the main window (when multiple items are selected).