diff options
author | Matthew Hodgson <matthew@matrix.org> | 2015-02-07 12:59:09 +0000 |
---|---|---|
committer | Matthew Hodgson <matthew@matrix.org> | 2015-02-07 12:59:09 +0000 |
commit | f02bf64d0e25cc3264c7f6767e9fbc008d7cc3d3 (patch) | |
tree | 16ec5d13ab31710e99a634c3c7250f82e84268d0 /scripts | |
parent | thou shalt specify a content-length (diff) | |
download | synapse-f02bf64d0e25cc3264c7f6767e9fbc008d7cc3d3.tar.xz |
create identicons for new users by default as default avatars, and provide script to update existing avatarless users
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/make_identicons.pl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/scripts/make_identicons.pl b/scripts/make_identicons.pl new file mode 100755 index 0000000000..172f63eba0 --- /dev/null +++ b/scripts/make_identicons.pl @@ -0,0 +1,24 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use DBI; +use DBD::SQLite; +use JSON; + +my $dbh = DBI->connect("dbi:SQLite:dbname=homeserver.db","","") || die DBI->error; + +my $res = $dbh->selectall_arrayref("select token, name from access_tokens, users where access_tokens.user_id = users.id group by user_id") || die DBI->error; + +foreach (@$res) { + my ($token, $mxid) = ($_->[0], $_->[1]); + my ($user_id) = ($mxid =~ m/@(.*):/); + my ($url) = $dbh->selectrow_array("select avatar_url from profiles where user_id=?", undef, $user_id); + if (!$url || $url =~ /#auto$/) { + `curl -o tmp.png "http://localhost:8008/_matrix/media/v1/identicon?name=${mxid}&width=320&height=320"`; + my $json = `curl -X POST -H "Content-Type: image/png" -T "tmp.png" http://localhost:8008/_matrix/media/v1/upload?access_token=$token`; + my $content_uri = from_json($json)->{content_uri}; + `curl -X PUT -H "Content-Type: application/json" --data '{ "avatar_url": "${content_uri}#auto"}' http://localhost:8008/_matrix/client/api/v1/profile/${mxid}/avatar_url?access_token=$token`; + } +} |