(request)
| 61 | |
| 62 | @PromptServer.instance.routes.get("/pysssss/metadata/{name}") |
| 63 | async def load_metadata(request): |
| 64 | name = request.match_info["name"] |
| 65 | pos = name.index("/") |
| 66 | type = name[0:pos] |
| 67 | name = name[pos+1:] |
| 68 | |
| 69 | file_path = None |
| 70 | if type == "embeddings" or type == "loras": |
| 71 | name = name.lower() |
| 72 | files = folder_paths.get_filename_list(type) |
| 73 | for f in files: |
| 74 | lower_f = f.lower() |
| 75 | if lower_f == name: |
| 76 | file_path = folder_paths.get_full_path(type, f) |
| 77 | else: |
| 78 | n = os.path.splitext(f)[0].lower() |
| 79 | if n == name: |
| 80 | file_path = folder_paths.get_full_path(type, f) |
| 81 | |
| 82 | if file_path is not None: |
| 83 | break |
| 84 | else: |
| 85 | file_path = folder_paths.get_full_path( |
| 86 | type, name) |
| 87 | if not file_path: |
| 88 | return web.Response(status=404) |
| 89 | |
| 90 | try: |
| 91 | meta = get_metadata(file_path) |
| 92 | except: |
| 93 | meta = None |
| 94 | |
| 95 | if meta is None: |
| 96 | meta = {} |
| 97 | |
| 98 | file_no_ext = os.path.splitext(file_path)[0] |
| 99 | |
| 100 | info_file = file_no_ext + ".txt" |
| 101 | if os.path.isfile(info_file): |
| 102 | with open(info_file, "r") as f: |
| 103 | meta["pysssss.notes"] = f.read() |
| 104 | |
| 105 | hash_file = file_no_ext + ".sha256" |
| 106 | if os.path.isfile(hash_file): |
| 107 | with open(hash_file, "rt") as f: |
| 108 | meta["pysssss.sha256"] = f.read() |
| 109 | else: |
| 110 | with open(file_path, "rb") as f: |
| 111 | meta["pysssss.sha256"] = hashlib.sha256(f.read()).hexdigest() |
| 112 | with open(hash_file, "wt") as f: |
| 113 | f.write(meta["pysssss.sha256"]) |
| 114 | |
| 115 | return web.json_response(meta) |
nothing calls this directly
no test coverage detected