From 0238bc793d13fb788c62ebbfcc706d1ab79fb995 Mon Sep 17 00:00:00 2001 From: Fairpost Date: Fri, 1 May 2026 15:52:34 +0200 Subject: [PATCH 1/3] feat: Add Textsize plugin for BlueSky --- src/platforms/Bluesky/Bluesky.ts | 7 +++- src/plugins/TextSize.ts | 62 ++++++++++++++++++++++++++++++++ src/plugins/index.ts | 1 + 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/plugins/TextSize.ts diff --git a/src/platforms/Bluesky/Bluesky.ts b/src/platforms/Bluesky/Bluesky.ts index d7ee572..86a4906 100644 --- a/src/platforms/Bluesky/Bluesky.ts +++ b/src/platforms/Bluesky/Bluesky.ts @@ -18,12 +18,17 @@ export default class Bluesky extends Platform { assetsFolder = "_bluesky"; postFileName = "post.json"; pluginSettings = { + textsize: { + max_length: 300, + }, limitfiles: { video_max: 1, image_max: 4, }, imagesize: { - max_size: 1000, + max_size: 2000, + max_width: 4000, + max_height: 4000, }, }; settings: FieldMapping = { diff --git a/src/plugins/TextSize.ts b/src/plugins/TextSize.ts new file mode 100644 index 0000000..fbe221b --- /dev/null +++ b/src/plugins/TextSize.ts @@ -0,0 +1,62 @@ +import Plugin from "../models/Plugin.ts"; +import Post from "../models/Post.ts"; + +interface TextSizeSettings { + min_length?: number; + max_length?: number; +} + +/** + * Plugin ImageSize. + * + * Resize images from Post based on Platform limits. + * + */ +export default class TextSize extends Plugin { + static defaults: TextSizeSettings = { + min_length: 0, + max_length: 0, + }; + settings: TextSizeSettings; + + constructor(settings?: object) { + super(); + this.settings = { + ...TextSize.defaults, + ...(settings ?? {}), + }; + } + + /** + * Process the post + */ + + async process(post: Post): Promise { + post.platform.user.log.trace(this.id, post.id, "process"); + if ( + this.settings.max_length && + post.body && + post.body.length >= this.settings.max_length + ) { + const splitBody = post.body.match(/[^.\n]+[.\n]*|[.\n]+/g); + if (splitBody) { + let newBody = ""; + let nextLine = splitBody.shift(); + while ( + nextLine && + newBody.length + nextLine.length < this.settings.max_length + ) { + newBody += nextLine; + nextLine = splitBody.shift(); + } + if (newBody !== "") { + post.body = newBody; + } + } + if (post.body.length >= this.settings.max_length) { + post.body = + post.body.substring(0, this.settings.max_length - 4) + "..."; + } + } + } +} diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 3d39c44..76028e5 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -1,3 +1,4 @@ +export { default as TextSize } from "./TextSize.ts"; export { default as LimitFiles } from "./LimitFiles.ts"; export { default as ImageSize } from "./ImageSize.ts"; export { default as ImageFrame } from "./ImageFrame.ts"; From e58acb2f3a5bfea28b6333b33956824e3ec10842 Mon Sep 17 00:00:00 2001 From: Fairpost Date: Fri, 1 May 2026 16:14:00 +0200 Subject: [PATCH 2/3] feat: Add min_length and throw/catch error --- src/platforms/Bluesky/Bluesky.ts | 6 +++++- src/plugins/TextSize.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/platforms/Bluesky/Bluesky.ts b/src/platforms/Bluesky/Bluesky.ts index 86a4906..2096adb 100644 --- a/src/platforms/Bluesky/Bluesky.ts +++ b/src/platforms/Bluesky/Bluesky.ts @@ -108,7 +108,11 @@ export default class Bluesky extends Platform { }; const plugins = this.loadPlugins(pluginSettings); for (const plugin of plugins) { - await plugin.process(post); + try { + await plugin.process(post); + } catch { + post.valid = false; + } } // Annimated GIF will be sent as a video. Only one animated GIF can be sent per post. diff --git a/src/plugins/TextSize.ts b/src/plugins/TextSize.ts index fbe221b..452e06b 100644 --- a/src/plugins/TextSize.ts +++ b/src/plugins/TextSize.ts @@ -33,6 +33,16 @@ export default class TextSize extends Plugin { async process(post: Post): Promise { post.platform.user.log.trace(this.id, post.id, "process"); + if ( + this.settings.min_length && + (!post.body || post.body.length >= this.settings.min_length) + ) { + throw post.platform.user.log.error( + "TextSize.process", + "Post body is required, min length " + this.settings.min_length, + post.id, + ); + } if ( this.settings.max_length && post.body && From 17a0a6bf4c74b250cee556755bb064d88a719d8c Mon Sep 17 00:00:00 2001 From: Fairpost Date: Fri, 1 May 2026 16:17:06 +0200 Subject: [PATCH 3/3] fix: < --- src/plugins/TextSize.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/TextSize.ts b/src/plugins/TextSize.ts index 452e06b..43577da 100644 --- a/src/plugins/TextSize.ts +++ b/src/plugins/TextSize.ts @@ -35,7 +35,7 @@ export default class TextSize extends Plugin { post.platform.user.log.trace(this.id, post.id, "process"); if ( this.settings.min_length && - (!post.body || post.body.length >= this.settings.min_length) + (!post.body || post.body.length < this.settings.min_length) ) { throw post.platform.user.log.error( "TextSize.process",