cleanup, preparing for cashu as input

This commit is contained in:
Believethehype
2023-11-27 00:02:56 +01:00
parent 17f46c6f13
commit 08137790d4
8 changed files with 210 additions and 84 deletions

View File

@@ -19,7 +19,7 @@ def get_task(event, client, dvmconfig):
# This looks a bit more complicated, but we do several tasks for text-extraction in the future
elif event.kind() == EventDefinitions.KIND_NIP90_EXTRACT_TEXT:
for tag in event.tags():
for tag in event.tags:
if tag.as_vec()[0] == "i":
if tag.as_vec()[2] == "url":
file_type = check_url_is_readable(tag.as_vec()[1])
@@ -50,7 +50,7 @@ def get_task(event, client, dvmconfig):
return "unknown type"
def check_task_is_supported(event, client, get_duration=False, config=None):
def check_task_is_supported(event, tags, client, get_duration=False, config=None):
try:
dvm_config = config
input_value = ""
@@ -59,32 +59,37 @@ def check_task_is_supported(event, client, get_duration=False, config=None):
task = get_task(event, client=client, dvmconfig=dvm_config)
for tag in event.tags:
if tag.as_vec()[0] == 'i':
if len(tag.as_vec()) < 3:
print("Job Event missing/malformed i tag, skipping..")
return False, "", 0
else:
input_value = tag.as_vec()[1]
input_type = tag.as_vec()[2]
if input_type == "event":
evt = get_event_by_id(input_value, client=client, config=dvm_config)
if evt is None:
print("Event not found")
return False, "", 0
elif input_type == 'url' and check_url_is_readable(input_value) is None:
print("Url not readable / supported")
return False, task, duration
try:
for tag in tags:
if tag.as_vec()[0] == 'i':
if len(tag.as_vec()) < 3:
print("Job Event missing/malformed i tag, skipping..")
return False, "", 0
else:
input_value = tag.as_vec()[1]
input_type = tag.as_vec()[2]
if input_type == "event":
evt = get_event_by_id(input_value, client=client, config=dvm_config)
if evt is None:
print("Event not found")
return False, "", 0
elif input_type == 'url' and check_url_is_readable(input_value) is None:
print("Url not readable / supported")
return False, task, duration#
elif tag.as_vec()[0] == 'output':
# TODO move this to individual modules
output = tag.as_vec()[1]
if not (output == "text/plain"
or output == "text/json" or output == "json"
or output == "image/png" or "image/jpg"
or output == "image/png;format=url" or output == "image/jpg;format=url"
or output == ""):
print("Output format not supported, skipping..")
return False, "", 0
except Exception as e:
print("Check task 2: " + str(e))
elif tag.as_vec()[0] == 'output':
output = tag.as_vec()[1]
if not (output == "text/plain"
or output == "text/json" or output == "json"
or output == "image/png" or "image/jpg"
or output == "image/png;format=url" or output == "image/jpg;format=url"
or output == ""):
print("Output format not supported, skipping..")
return False, "", 0
for dvm in dvm_config.SUPPORTED_DVMS:
if dvm.TASK == task:
@@ -96,6 +101,7 @@ def check_task_is_supported(event, client, get_duration=False, config=None):
return True, task, duration
except Exception as e:
print("Check task: " + str(e))