mirror of
https://git.datalinker.icu/ltdrdata/ComfyUI-Manager
synced 2025-12-09 06:04:31 +08:00
Revert "Migrate matrix-client to matrix-nio (#2025)"
This reverts commit d4715aebefb71567d7684f710f8653fdff1e18e4.
This commit is contained in:
parent
621de1ab99
commit
d82e1f5d67
@ -335,8 +335,8 @@ async def share_art(request):
|
|||||||
content_type = assetFileType
|
content_type = assetFileType
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from nio import AsyncClient, LoginResponse, RoomSendResponse, UploadResponse, RoomMessageText, RoomMessageMedia
|
from matrix_client.api import MatrixHttpApi
|
||||||
import asyncio
|
from matrix_client.client import MatrixClient
|
||||||
|
|
||||||
homeserver = 'matrix.org'
|
homeserver = 'matrix.org'
|
||||||
if matrix_auth:
|
if matrix_auth:
|
||||||
@ -345,35 +345,20 @@ async def share_art(request):
|
|||||||
if not homeserver.startswith("https://"):
|
if not homeserver.startswith("https://"):
|
||||||
homeserver = "https://" + homeserver
|
homeserver = "https://" + homeserver
|
||||||
|
|
||||||
client = AsyncClient(homeserver, matrix_auth['username'])
|
client = MatrixClient(homeserver)
|
||||||
|
try:
|
||||||
# Login
|
token = client.login(username=matrix_auth['username'], password=matrix_auth['password'])
|
||||||
login_resp = await client.login(matrix_auth['password'])
|
if not token:
|
||||||
if not isinstance(login_resp, LoginResponse) or not login_resp.access_token:
|
return web.json_response({"error": "Invalid Matrix credentials."}, content_type='application/json', status=400)
|
||||||
await client.close()
|
except:
|
||||||
return web.json_response({"error": "Invalid Matrix credentials."}, content_type='application/json', status=400)
|
return web.json_response({"error": "Invalid Matrix credentials."}, content_type='application/json', status=400)
|
||||||
|
|
||||||
# Upload asset
|
matrix = MatrixHttpApi(homeserver, token=token)
|
||||||
with open(asset_filepath, 'rb') as f:
|
with open(asset_filepath, 'rb') as f:
|
||||||
upload_resp, _maybe_keys = await client.upload(f, content_type=content_type, filename=filename)
|
mxc_url = matrix.media_upload(f.read(), content_type, filename=filename)['content_uri']
|
||||||
asset_data = f.seek(0) or f.read() # get size for info below
|
|
||||||
if not isinstance(upload_resp, UploadResponse) or not upload_resp.content_uri:
|
|
||||||
await client.close()
|
|
||||||
return web.json_response({"error": "Failed to upload asset to Matrix."}, content_type='application/json', status=500)
|
|
||||||
mxc_url = upload_resp.content_uri
|
|
||||||
|
|
||||||
# Upload workflow JSON
|
workflow_json_mxc_url = matrix.media_upload(prompt['workflow'], 'application/json', filename='workflow.json')['content_uri']
|
||||||
import io
|
|
||||||
workflow_json_bytes = json.dumps(prompt['workflow']).encode('utf-8')
|
|
||||||
workflow_io = io.BytesIO(workflow_json_bytes)
|
|
||||||
upload_workflow_resp, _maybe_keys = await client.upload(workflow_io, content_type='application/json', filename='workflow.json')
|
|
||||||
workflow_io.seek(0)
|
|
||||||
if not isinstance(upload_workflow_resp, UploadResponse) or not upload_workflow_resp.content_uri:
|
|
||||||
await client.close()
|
|
||||||
return web.json_response({"error": "Failed to upload workflow to Matrix."}, content_type='application/json', status=500)
|
|
||||||
workflow_json_mxc_url = upload_workflow_resp.content_uri
|
|
||||||
|
|
||||||
# Send text message
|
|
||||||
text_content = ""
|
text_content = ""
|
||||||
if title:
|
if title:
|
||||||
text_content += f"{title}\n"
|
text_content += f"{title}\n"
|
||||||
@ -381,44 +366,9 @@ async def share_art(request):
|
|||||||
text_content += f"{description}\n"
|
text_content += f"{description}\n"
|
||||||
if credits:
|
if credits:
|
||||||
text_content += f"\ncredits: {credits}\n"
|
text_content += f"\ncredits: {credits}\n"
|
||||||
await client.room_send(
|
matrix.send_message(comfyui_share_room_id, text_content)
|
||||||
room_id=comfyui_share_room_id,
|
matrix.send_content(comfyui_share_room_id, mxc_url, filename, 'm.image')
|
||||||
message_type="m.room.message",
|
matrix.send_content(comfyui_share_room_id, workflow_json_mxc_url, 'workflow.json', 'm.file')
|
||||||
content={"msgtype": "m.text", "body": text_content}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Send image
|
|
||||||
await client.room_send(
|
|
||||||
room_id=comfyui_share_room_id,
|
|
||||||
message_type="m.room.message",
|
|
||||||
content={
|
|
||||||
"msgtype": "m.image",
|
|
||||||
"body": filename,
|
|
||||||
"url": mxc_url,
|
|
||||||
"info": {
|
|
||||||
"mimetype": content_type,
|
|
||||||
"size": len(asset_data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Send workflow JSON file
|
|
||||||
await client.room_send(
|
|
||||||
room_id=comfyui_share_room_id,
|
|
||||||
message_type="m.room.message",
|
|
||||||
content={
|
|
||||||
"msgtype": "m.file",
|
|
||||||
"body": "workflow.json",
|
|
||||||
"url": workflow_json_mxc_url,
|
|
||||||
"info": {
|
|
||||||
"mimetype": "application/json",
|
|
||||||
"size": len(workflow_json_bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
await client.close()
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|||||||
@ -3,7 +3,7 @@ name = "comfyui-manager"
|
|||||||
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
|
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
|
||||||
version = "3.36"
|
version = "3.36"
|
||||||
license = { file = "LICENSE.txt" }
|
license = { file = "LICENSE.txt" }
|
||||||
dependencies = ["GitPython", "PyGithub", "matrix-nio", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions", "toml", "uv", "chardet"]
|
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions", "toml", "uv", "chardet"]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Repository = "https://github.com/ltdrdata/ComfyUI-Manager"
|
Repository = "https://github.com/ltdrdata/ComfyUI-Manager"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
GitPython
|
GitPython
|
||||||
PyGithub
|
PyGithub
|
||||||
matrix-nio
|
matrix-client==0.4.0
|
||||||
transformers
|
transformers
|
||||||
huggingface-hub>0.20
|
huggingface-hub>0.20
|
||||||
typer
|
typer
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user