-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8fa3a7
commit b559813
Showing
5 changed files
with
611 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { login } from 'masto/fetch'; | ||
import Client from "./Client.mjs"; | ||
|
||
export default class MastodonClient extends Client | ||
{ | ||
key = 'mastodon'; | ||
name = 'Mastodon'; | ||
|
||
#url; | ||
#accessToken; | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.#url = process.env.MASTODON_URL; | ||
this.#accessToken = process.env.MASTODON_ACCESS_TOKEN; | ||
} | ||
|
||
async send(status, generator) { | ||
// Mastodon API | ||
const masto = await login({ | ||
url: this.#url, | ||
accessToken: this.#accessToken, | ||
disableVersionCheck: true, | ||
disableExperimentalWarning: true, | ||
}); | ||
|
||
// Upload images | ||
let mediaIds = await Promise.all( | ||
status.media.map(async m => { | ||
let request = { file: new Blob([m.file]) }; | ||
if (m.altText) { | ||
request.description = m.altText; | ||
} | ||
|
||
let attachment = await masto.mediaAttachments.create(request); | ||
|
||
return attachment.id; | ||
}), | ||
); | ||
|
||
// Send status | ||
await masto.statuses.create({ | ||
status: status.status, | ||
mediaIds, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.