Skip to content

Commit 1f2c9f9

Browse files
authored
Merge pull request #24 from Lurking987/Lurking987-improve-api-handling
Improve API Handling
2 parents 1fddc53 + 58a7576 commit 1f2c9f9

3 files changed

Lines changed: 16 additions & 22 deletions

File tree

plugins/Clear All Tag Covers/Clear All Tag Covers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Clear All Tag Covers
22
description: Clear the image cover for all tags
3-
version: 0.1
3+
version: 0.2
44
exec:
55
- python
66
- "{pluginDir}/clear_tag_covers.py"

plugins/Clear All Tag Covers/clear_tag_covers.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,42 @@
11
import sys
22
import json
3-
import requests
43
import stashapi.log as log
4+
from stashapi.stashapp import StashInterface
55

66
def main():
77
try:
8-
# Standard way for Stash plugins to receive server info
98
raw_input = sys.stdin.read()
109
if not raw_input:
1110
log.error("No input received from Stash.")
1211
return
13-
14-
input_data = json.loads(raw_input)
15-
server = input_data.get("server_connection", {})
16-
17-
# Use dynamic base_url to handle local vs remote connections
18-
base_url = f"{server.get('Scheme', 'http')}://{server.get('Host', 'localhost')}:{server.get('Port', 9999)}"
19-
headers = {'Content-Type': 'application/json'}
20-
if server.get('ApiKey'):
21-
headers['ApiKey'] = server.get('ApiKey')
12+
13+
json_input = json.loads(raw_input)
14+
stash = StashInterface(json_input["server_connection"])
15+
2216
except Exception as e:
2317
log.error(f"Initialization failed: {e}")
2418
return
2519

26-
# GraphQL query to find all tags
27-
query = "{ findTags(filter: {per_page: -1}) { tags { id image_path } } }"
2820
try:
29-
res = requests.post(f"{base_url}/graphql", json={'query': query}, headers=headers, timeout=10).json()
30-
tags = res.get("data", {}).get("findTags", {}).get("tags", [])
21+
result = stash.call_GQL("{ findTags(filter: {per_page: -1}) { tags { id image_path } } }")
22+
tags = result.get("findTags", {}).get("tags", [])
3123
except Exception as e:
3224
log.error(f"Failed to fetch tags: {e}")
3325
return
3426

35-
# Clear covers only for tags that have one
3627
tags_to_clear = [t for t in tags if t.get("image_path")]
3728
total = len(tags_to_clear)
38-
29+
3930
if total == 0:
4031
log.info("No tag covers found to clear.")
4132
return
4233

34+
mutation = "mutation($id: ID!) { tagUpdate(input: { id: $id, image: \"\" }) { id } }"
4335
for idx, tag in enumerate(tags_to_clear, 1):
44-
mutation = "mutation($id: ID!) { tagUpdate(input: { id: $id, image: \"\" }) { id } }"
45-
requests.post(f"{base_url}/graphql", json={'query': mutation, 'variables': {"id": tag['id']}}, headers=headers)
36+
try:
37+
stash.call_GQL(mutation, {"id": tag["id"]})
38+
except Exception as e:
39+
log.error(f"Failed to clear tag {tag['id']}: {e}")
4640
log.progress(idx / total)
4741

4842
log.info(f"Successfully cleared {total} tag cover images.")

plugins/Clear All Tag Covers/manifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ id: Clear All Tag Covers
22
name: Clear All Tag Covers
33
metadata:
44
description: Clear the image cover for all tags.
5-
version: 0.1
6-
date: "2026-02-26 21:14:00"
5+
version: 0.2
6+
date: "2026-04-12 09:34:00"
77
requires: []
88
source_repository: https://lurking987.github.io/stash-plugins/main/index.yml
99
files:

0 commit comments

Comments
 (0)