From f2b332795fbaf6c8f1b31e698eee3388cfb3568b Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Sun, 17 Mar 2024 09:55:39 -0700 Subject: [PATCH] Update Mastodon client --- app/social/clients/MastodonClient.mjs | 11 +++-- package-lock.json | 63 ++++++++------------------- package.json | 2 +- 3 files changed, 27 insertions(+), 49 deletions(-) diff --git a/app/social/clients/MastodonClient.mjs b/app/social/clients/MastodonClient.mjs index 4d8378c..4e6295b 100644 --- a/app/social/clients/MastodonClient.mjs +++ b/app/social/clients/MastodonClient.mjs @@ -1,4 +1,4 @@ -import { login } from 'masto/fetch'; +import { createRestAPIClient } from 'masto'; import Client from "./Client.mjs"; export default class MastodonClient extends Client @@ -8,12 +8,14 @@ export default class MastodonClient extends Client #url; #accessToken; + #visibility; constructor() { super(); this.#url = process.env.MASTODON_URL; this.#accessToken = process.env.MASTODON_ACCESS_TOKEN; + this.#visibility = process.env.MASTODON_VISIBILITY || 'public'; } async canSend() { @@ -22,7 +24,7 @@ export default class MastodonClient extends Client async send(status, generator) { // Mastodon API - const masto = await login({ + const masto = await createRestAPIClient({ url: this.#url, accessToken: this.#accessToken, disableVersionCheck: true, @@ -37,18 +39,19 @@ export default class MastodonClient extends Client request.description = m.altText; } - let attachment = await masto.mediaAttachments.create(request); + let attachment = await masto.v2.media.create(request); return attachment.id; }), ); // Send status - await masto.statuses.create({ + await masto.v1.statuses.create({ status: status.status, spoilerText: status.contentWrapper, sensitive: !!status.contentWrapper, // Without the sensitive property the image is still visible mediaIds, + visibility: this.#visibility, }); } } diff --git a/package-lock.json b/package-lock.json index ed3a0eb..3fe3a4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "ical-generator": "^3.6.0", "jsonpath": "^1.1.1", "lodash": "^4.17.21", - "masto": "^4.9.1", + "masto": "^6.7.0", "mkdirp": "^1.0.4", "nxapi": "^1.4.0", "pinia": "^2.0.22", @@ -2658,16 +2658,6 @@ "node": ">=4" } }, - "node_modules/axios": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.1.3.tgz", - "integrity": "sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==", - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/axobject-query": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz", @@ -4825,10 +4815,10 @@ "node": ">= 0.6" } }, - "node_modules/eventemitter3": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", - "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==" + "node_modules/events-to-async": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/events-to-async/-/events-to-async-2.0.1.tgz", + "integrity": "sha512-RtnLYrMbXp4JkZIoZu+3VTqV21bNVBlJBZ4NmtwvMNqSE3qouhxv2gvLE4JJDaQc54ioPkrX74V6x+hp/hqjkQ==" }, "node_modules/eventsource": { "version": "2.0.2", @@ -6121,27 +6111,6 @@ "resolved": "https://registry.npmjs.org/iso-datestring-validator/-/iso-datestring-validator-2.2.2.tgz", "integrity": "sha512-yLEMkBbLZTlVQqOnQ4FiMujR6T4DEcCb1xizmvXS+OxuhwcbtynoosRzdMA69zZCShCNAbi+gJ71FxZBBXx1SA==" }, - "node_modules/isomorphic-form-data": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isomorphic-form-data/-/isomorphic-form-data-2.0.0.tgz", - "integrity": "sha512-TYgVnXWeESVmQSg4GLVbalmQ+B4NPi/H4eWxqALKj63KsUrcu301YDjBqaOw3h+cbak7Na4Xyps3BiptHtxTfg==", - "dependencies": { - "form-data": "^2.3.2" - } - }, - "node_modules/isomorphic-form-data/node_modules/form-data": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", - "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 0.12" - } - }, "node_modules/isomorphic-ws": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/isomorphic-ws/-/isomorphic-ws-5.0.0.tgz", @@ -6459,17 +6428,15 @@ } }, "node_modules/masto": { - "version": "4.11.1", - "resolved": "https://registry.npmjs.org/masto/-/masto-4.11.1.tgz", - "integrity": "sha512-siTQNhfLV1JjOERCGgjagMvD6q0K0hLuhOXrbXNcYzHAwpbPeSeAM6CSpIRrZ8zFDepOR62Djs/GtJdTR21Rfw==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/masto/-/masto-6.7.0.tgz", + "integrity": "sha512-R1UyuCdiyBuA9xuIEVIYa2187oIoHhpL1T0glIY+RICAo7JYOAEPdi4aAmROyPcWOYwMlaVDmRRb1zmNbvTnVg==", "dependencies": { - "axios": "1.1.3", "change-case": "^4.1.2", - "eventemitter3": "^5.0.0", - "isomorphic-form-data": "^2.0.0", + "events-to-async": "^2.0.1", "isomorphic-ws": "^5.0.0", - "semver": "^7.3.7", - "ws": "^8.8.0" + "ts-custom-error": "^3.3.1", + "ws": "^8.16.0" } }, "node_modules/media-typer": { @@ -8642,6 +8609,14 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, + "node_modules/ts-custom-error": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/ts-custom-error/-/ts-custom-error-3.3.1.tgz", + "integrity": "sha512-5OX1tzOjxWEgsr/YEUWSuPrQ00deKLh6D7OTWcvNHm12/7QPyRh8SYpyWvA4IZv8H/+GQWQEh/kwo95Q9OVW1A==", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/ts-interface-checker": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", diff --git a/package.json b/package.json index 2f9908c..d3c3e22 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "ical-generator": "^3.6.0", "jsonpath": "^1.1.1", "lodash": "^4.17.21", - "masto": "^4.9.1", + "masto": "^6.7.0", "mkdirp": "^1.0.4", "nxapi": "^1.4.0", "pinia": "^2.0.22",