Skylar-Tech / node-red-contrib-matrix-chat

Matrix chat server support for Node-RED
GNU General Public License v3.0
31 stars 10 forks source link

Send images missing info #80

Open blaxer opened 1 year ago

blaxer commented 1 year ago

Very minor issue but when sending an image, there does not appear to be any data in content --> info. This causes an issue with most of the matrix bridges I use (mautrix) as they don't recognize the message as containing an image and just show it as a binary attachement. It seems that content --> info should contain at least mimetype.

Example message that does not work correctly via bridges, sent from node-red-contrib-matrix-chat (with sensative data removed)

{ "type": "m.room.message", "sender": "@xxxx.com", "content": { "body": "Camera Snapshot", "msgtype": "m.image", "url": "mxc://xxx/xxxx", "info": {} }, "origin_server_ts": xxxxx, "unsigned": { "age": 75 }, "event_id": "xxxx", "room_id": "xxxx" }

Example message sent by the element client that works properly through (mautrix) bridges

{ "type": "m.room.message", "sender": "@xxxx.com", "content": { "body": "1.jpg", "info": { "size": 316949, "mimetype": "image/jpeg", "thumbnail_info": { "w": 635, "h": 600, "mimetype": "image/jpeg", "size": 166629 }, "w": 959, "h": 906, "xyz.amorgan.blurhash": "xxxxx", "thumbnail_url": "mxc://xxxx/xxxx" }, "msgtype": "m.image", "url": "mxc://xxxx/xxxx" }, "origin_server_ts": xxxx, "unsigned": { "age": 87, "transaction_id": "xxxx" }, "event_id": "xxxx", "room_id": "xxxx" }

Again from my testing the only thing that seems to be required to make an image display correctly is :

"info": {
  "mimetype": "image/jpeg",
            }

but perhaps it's a good idea to send the rest of the info as well to more closely match the "stock" client message?

TIA!

genjudev commented 1 year ago

Yeah its a good idea, to match the way matrix do it.

// from matrix-js-sdk
export interface IEncryptedFile {
    url: string;
    mimetype?: string;
    key: {
        alg: string;
        key_ops: string[]; // eslint-disable-line camelcase
        kty: string;
        k: string;
        ext: boolean;
    };
    iv: string;
    hashes: { [alg: string]: string };
    v: string;
}

type TMediaFile = {
    msgtype: string;
    body: string //filename, when encrypted randomized. Do not use real name.
    info: {
        mimetype: string;
        size: number;
        h: number;
        w: number;
    },
    url: string;
    file: IEncryptedFile
}
unknown1818 commented 8 months ago

any way to implement this i node-red function node?

msg.payload = { 
    "url": msg.image_url, 
    "info": { 
        "mimetype": "image/jpg"
    } 
}
return msg;

but i got blank message

skylord123 commented 8 months ago

Again from my testing the only thing that seems to be required to make an image display correctly is :

"info": {
  "mimetype": "image/jpeg",
            }

but perhaps it's a good idea to send the rest of the info as well to more closely match the "stock" client message?

Yes you are right. My testing when I created it showed that mimtype was required but the other things not so much. I'll look into automatically detecting the info. I just really don't want to add too many third party packages so I have been avoiding it.

I'm hoping in a future release to deprecate the send image and file nodes for a single upload file node. If you want to update the room or profile image you need an uploaded file to the matrix server so one of the options will be to upload a file without posting it to a room to accomplish that. I'll look into parsing extra info at that time.

At least you can send the data manually for now though if you know the information of the image.