!GsmxjHfeAYLsTEQmjS:nixos.org

Matrix Meta (Nix)

657 Members
Discuss your proposals for the Matrix space here, before suggesting them in #matrix-suggestions:nixos.org187 Servers

Load older messages


SenderMessageTime
23 Jul 2021
@schnecfk:ruhr-uni-bochum.deCRTifiedThat's significantly cleaner15:37:52
@sumner:sumnerevans.comsumner *

Alternative is:

mimetype=$(file --mime-type $FILEPATH | sed 's/.*: //g')
15:38:14
@schnecfk:ruhr-uni-bochum.deCRTified *
#!/usr/bin/env nix-shell
#!nix-shell -i sh -p jq curl

# Configure this:
HOMESERVER="" # Without trailing slash
TOKEN="" # Access token here


# Pass this as argv:
ROOMID="${1}"
FILEPATH="${2}"

# Thanks to sumner
MIMETYPE=$(file --mime-type $FILEPATH | sed 's/.*: //g')

echo MIME is $MIMETYPE
# Upload image to image.png
mxc=$(curl --silent -H "Content-Type: ${MIMETYPE}" -H "Authorization: Bearer ${TOKEN}" -X POST --data-binary "@${FILEPATH}" "${HOMESERVER}/_matrix/media/r0/upload?filename=image.png")
echo $mxc
# Build m.room.avatar event
EVENT_SET_AVATAR="{ \"url\": $(echo $mxc | jq '.content_uri') }"
# Push event
curl --silent -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}" -X PUT --data "${EVENT_SET_AVATAR}" "${HOMESERVER}/_matrix/client/r0/rooms/${ROOMID}/state/m.room.avatar"


15:40:31
@schnecfk:ruhr-uni-bochum.deCRTifiedAdded it :)15:40:45
@schnecfk:ruhr-uni-bochum.deCRTifiedJust the filename that's wrong now :D15:41:15
@leons:is.currently.onlineLeon You should add file as a build input ;) 15:41:21
@schnecfk:ruhr-uni-bochum.deCRTified *
#!/usr/bin/env nix-shell
#!nix-shell -i sh -p jq curl file

# Configure this:
HOMESERVER="" # Without trailing slash
TOKEN="" # Access token here


# Pass this as argv:
ROOMID="${1}"
FILEPATH="${2}"

# Thanks to sumner
MIMETYPE=$(file --mime-type $FILEPATH | sed 's/.*: //g')

echo MIME is $MIMETYPE
# Upload image to image.png
mxc=$(curl --silent -H "Content-Type: ${MIMETYPE}" -H "Authorization: Bearer ${TOKEN}" -X POST --data-binary "@${FILEPATH}" "${HOMESERVER}/_matrix/media/r0/upload?filename=image.png")
echo $mxc
# Build m.room.avatar event
EVENT_SET_AVATAR="{ \"url\": $(echo $mxc | jq '.content_uri') }"
# Push event
curl --silent -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}" -X PUT --data "${EVENT_SET_AVATAR}" "${HOMESERVER}/_matrix/client/r0/rooms/${ROOMID}/state/m.room.avatar"


15:41:29
@schnecfk:ruhr-uni-bochum.deCRTified
In reply to @leons:is.currently.online
You should add file as a build input ;)
you're right. Didn't copy the whole file again as my token is in the local version 🙈
15:41:50
@sumner:sumnerevans.comsumner
In reply to @schnecfk:ruhr-uni-bochum.de
Just the filename that's wrong now :D
filename is optional
15:42:06
@schnecfk:ruhr-uni-bochum.deCRTified *
#!/usr/bin/env nix-shell
#!nix-shell -i sh -p jq curl file

# Configure this:
HOMESERVER="" # Without trailing slash
TOKEN="" # Access token here


# Pass this as argv:
ROOMID="${1}"
FILEPATH="${2}"

# Thanks to sumner
MIMETYPE=$(file --mime-type $FILEPATH | sed 's/.*: //g')

echo MIME is $MIMETYPE
# Upload image to image.png
mxc=$(curl --silent -H "Content-Type: ${MIMETYPE}" -H "Authorization: Bearer ${TOKEN}" -X POST --data-binary "@${FILEPATH}" "${HOMESERVER}/_matrix/media/r0/upload")
echo $mxc
# Build m.room.avatar event
EVENT_SET_AVATAR="{ \"url\": $(echo $mxc | jq '.content_uri') }"
# Push event
curl --silent -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}" -X PUT --data "${EVENT_SET_AVATAR}" "${HOMESERVER}/_matrix/client/r0/rooms/${ROOMID}/state/m.room.avatar"


15:42:18
@schnecfk:ruhr-uni-bochum.deCRTified In that case, poof :D 15:42:25
@sumner:sumnerevans.comsumner
In reply to @schnecfk:ruhr-uni-bochum.de
Just the filename that's wrong now :D
* filename is optional. Required fields are marked as such.
15:42:37
@sumner:sumnerevans.comsumnerMay be worth uploading that as a file so that it's easy to find in the sidebar.15:43:59
@schnecfk:ruhr-uni-bochum.deCRTifiedIn that case I'll run shellcheck on it15:44:36
@grahamc:nixos.org@grahamc:nixos.orghttps://matrix.org/_matrix/media/r0/download/nixos.org/ab7db8fb43cc002b48b03de4cf04f0ec7c75558515:48:02
@grahamc:nixos.org@grahamc:nixos.orgnice!15:48:25
@grahamc:nixos.org@grahamc:nixos.org

here is what I've put together:


make_avatar() (
  room_id=$1
  roomhash=$(md5sum <<<"$room_id" | cut -d' ' -f1)
  filename="$scratch/$roomhash.avatar"

  curl "https://www.gravatar.com/avatar/${roomhash}?d=identicon&f=y&s=2048" > "$filename"
  echo "$filename"
)

upload_media() (
  FILEPATH="${1}"

  mime=$(file --brief --mime "$FILEPATH")

  # Upload image to image.png
  curl \
    --silent \
    -H "Content-Type: $mime" \
    -H "Authorization: Bearer ${AUTH_TOKEN}" \
    -X POST \
    --data-binary "@${FILEPATH}" \
    "${HOMESERVER}/_matrix/media/r0/upload?filename=image.png" \
    | jq '.content_uri'
)

set_room_avatar() (
  ROOMID=$1
  MXC=$2

  # Build m.room.avatar event
  EVENT_SET_AVATAR=$(jq -n '{ url: $mxc }' --arg mxc "$MXC")

  # Push event
  curl \
    --silent \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ${AUTH_TOKEN}" \
    -X PUT \
    --data "${EVENT_SET_AVATAR}" \
    "${HOMESERVER}/_matrix/client/r0/rooms/${ROOMID}/state/m.room.avatar"
)

15:48:52
@jez:petrichor.meJez (he/him) left the room.15:49:04
@schnecfk:ruhr-uni-bochum.deCRTifiedThat's a clean style for a shell script 👀15:50:20
@schnecfk:ruhr-uni-bochum.deCRTifiedlooks good to go15:50:39
@schnecfk:ruhr-uni-bochum.deCRTified grahamc (he/him): maybe keep a list of the rooms that you'll assign a generated image for. That way, we could replace them easier with something prettier (autogenerated) afterwards. I was thinking about doing something with the nix logo, e.g. assigning colors from the hash of the room name or something like this 15:57:24
@grahamc:nixos.org@grahamc:nixos.orgthat is a cool idea15:58:25
@schnecfk:ruhr-uni-bochum.deCRTifiedI'll try something this evening (so in 2-3 hours probably)15:59:12
@schnecfk:ruhr-uni-bochum.deCRTified * I'll try something this evening (so in 2-3 hours probably), but that might help to keep the nix "branding" present in the room avatars 😁15:59:39
@grahamc:nixos.org@grahamc:nixos.orgthat would be cool16:03:18
@grahamc:nixos.org@grahamc:nixos.orgI'm not going to roll it out widely yet anyway, I want to give some people time to think about it16:03:29
@grahamc:nixos.org@grahamc:nixos.orgapplied to !gKfPYWNBcIabzMfEvn:nixos.org !pbdtvoHxUGLhcEvnlu:nixos.org 16:04:32
@grahamc:nixos.org@grahamc:nixos.org hrm I tried to add a URL parameter to the community room's avatar but it breaks the rendering: "avatar": "mxc://nixos.org/721c442bc81f9fedaeada3ad89af693666619889?autogenerated=1" 16:11:43
@schnecfk:ruhr-uni-bochum.deCRTified
In reply to @grahamc:nixos.org
hrm I tried to add a URL parameter to the community room's avatar but it breaks the rendering: "avatar": "mxc://nixos.org/721c442bc81f9fedaeada3ad89af693666619889?autogenerated=1"
I wonder if the mimetype is preserved - in that case you could use a parameter there? 🤔
16:29:12
@schnecfk:ruhr-uni-bochum.deCRTified Looks like it is preserved - both in the event (where you can supply it under the info->mimetype key), and when uploading the image (in that case it's the Content-Type header) 16:36:09

Show newer messages


Back to Room ListRoom Version: 6