diff --git a/src/platforms/Bluesky/Bluesky.ts b/src/platforms/Bluesky/Bluesky.ts index d7ee572..2096adb 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 = { @@ -103,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 new file mode 100644 index 0000000..43577da --- /dev/null +++ b/src/plugins/TextSize.ts @@ -0,0 +1,72 @@ +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.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 && + 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";