Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tag handling to base website, update parser #286

Merged
merged 7 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions commons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ export * from './models/default-file-options.entity';
// Website Option Entities
import * as WebsiteOptions from './websites/websites';
export { WebsiteOptions };

// Doesn't really fit :P
export * from './websites/megalodon/megalodon.instancesettings';
5 changes: 5 additions & 0 deletions commons/src/websites/megalodon/megalodon.instancesettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class MegalodonInstanceSettings {
maxChars?: number = undefined;
maxImages?: number = undefined;
}

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ParserService {
private readonly fileManipulator: FileManipulationService,
websitesService: WebsitesService,
) {
this.descriptionParser = new DescriptionParser(customShortcuts, websitesService, settings);
this.descriptionParser = new DescriptionParser(customShortcuts, websitesService, settings, this);
}

public async parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import FormContent from 'src/server/utils/form-content.util';
import { Website } from 'src/server/websites/website.base';
import { WebsitesService } from 'src/server/websites/websites.service';
import SubmissionPartEntity from '../../submission-part/models/submission-part.entity';
import { ParserService } from '../parser.service';

interface ShortcutData {
originalText: string;
Expand All @@ -26,6 +27,7 @@ export class DescriptionParser {
private customShortcuts: CustomShortcutService,
private websitesService: WebsitesService,
private settings: SettingsService,
private readonly parserService: ParserService,
) {
this.websiteDescriptionShortcuts = websitesService.getUsernameShortcuts();
this.websiteDescriptionShortcuts = {
Expand All @@ -52,6 +54,7 @@ export class DescriptionParser {

if (description.length) {
// Insert {default}, {title}, {tags} shortcuts
let tags = await this.parserService.parseTags(website, defaultPart, websitePart);
description = this.insertDefaultShortcuts(description, [
{
name: 'default',
Expand All @@ -63,10 +66,7 @@ export class DescriptionParser {
},
{
name: 'tags',
content:
defaultPart.data.tags.value.map(t => '#' + t).join(' ') ??
websitePart.data.tags.value.map(t => '#' + t).join(' ') ??
'',
content: website.generateTagsString(tags, description, websitePart),
},
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import FormContent from "../../utils/form-content.util";
@Injectable()
export class Artconomy extends Website {
readonly BASE_URL: string = 'https://artconomy.com';
readonly MAX_CHARS: number = 2000;
readonly acceptsFiles: string[] = [
'png',
'jpeg',
Expand Down Expand Up @@ -255,7 +256,7 @@ export class Artconomy extends Website {
FormContent.getDescription(defaultPart.data.description, submissionPart.data.description),
)

if (description.length > 2000) {
if (description.length > this.MAX_CHARS) {
problems.push('Description must be 2000 characters or fewer.')
}

Expand Down
1 change: 1 addition & 0 deletions electron-app/src/server/websites/aryion/aryion.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Website } from '../website.base';
@Injectable()
export class Aryion extends Website {
readonly BASE_URL = 'https://aryion.com';
readonly MAX_CHARS: number = undefined; // No limit
readonly defaultDescriptionParser = BBCodeParser.parse;
readonly usernameShortcuts = [
{
Expand Down
27 changes: 11 additions & 16 deletions electron-app/src/server/websites/bluesky/bluesky.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ export class Bluesky extends Website {
).map(tag => `#${tag}`);
}

private appendRichTextTags(tags: string[], description: string): string {
return this.appendTags(this.formatTags(tags), description, this.MAX_CHARS, getRichTextLength);
}

private async uploadMedia(
agent: BskyAgent,
data: BlueskyAccountData,
Expand Down Expand Up @@ -229,8 +225,6 @@ export class Bluesky extends Website {
$type: 'app.bsky.embed.images',
};

const status = this.appendRichTextTags(data.tags, data.description);

let labelsRecord: ComAtprotoLabelDefs.SelfLabels | undefined;
if (data.options.label_rating) {
labelsRecord = {
Expand All @@ -239,7 +233,7 @@ export class Bluesky extends Website {
};
}

const rt = new RichText({ text: status });
const rt = new RichText({ text: data.description });
await rt.detectFacets(agent);

let postResult = await agent
Expand Down Expand Up @@ -286,7 +280,6 @@ export class Bluesky extends Website {
let profile = await agent.getProfile({actor: agent.session.did });

const reply = await this.getReplyRef(agent, data.options.replyToUrl);
const status = this.appendRichTextTags(data.tags, data.description);

let labelsRecord: ComAtprotoLabelDefs.SelfLabels | undefined;
if (data.options.label_rating) {
Expand All @@ -296,7 +289,7 @@ export class Bluesky extends Website {
};
}

const rt = new RichText({ text: status });
const rt = new RichText({ text: data.description });
await rt.detectFacets(agent);

let postResult = await agent.post({
Expand Down Expand Up @@ -423,13 +416,15 @@ export class Bluesky extends Website {
`Max description length allowed is ${this.MAX_CHARS} characters.`,
);
} else {
this.validateAppendTags(
warnings,
this.formatTags(FormContent.getTags(defaultPart.data.tags, submissionPart.data.tags)),
description,
this.MAX_CHARS,
getRichTextLength,
);
if (description.toLowerCase().indexOf('{tags}') > -1) {
this.validateInsertTags(
warnings,
this.formatTags(FormContent.getTags(defaultPart.data.tags, submissionPart.data.tags)),
description,
this.MAX_CHARS,
getRichTextLength,
);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions electron-app/src/server/websites/custom/custom.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Website } from '../website.base';
@Injectable()
export class Custom extends Website {
readonly BASE_URL: string = '';
readonly MAX_CHARS: number = undefined; // No limit
readonly acceptsFiles: string[] = []; // accepts all
readonly acceptsAdditionalFiles: boolean = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Website } from '../website.base';
@Injectable()
export class Derpibooru extends Website {
BASE_URL: string = 'https://derpibooru.org';
MAX_CHARS: number = -1; // No limit
acceptsFiles: string[] = ['jpeg', 'jpg', 'png', 'svg', 'gif', 'webm'];
acceptsSourceUrls: boolean = true;
enableAdvertisement: boolean = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface DeviantArtFolder {
@Injectable()
export class DeviantArt extends Website {
readonly BASE_URL = 'https://www.deviantart.com';
readonly MAX_CHARS: number = undefined; // No Limit
readonly acceptsFiles = [
'jpeg',
'jpg',
Expand Down
5 changes: 3 additions & 2 deletions electron-app/src/server/websites/discord/discord.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { DiscordAccountData } from './discord.account.interface';
@Injectable()
export class Discord extends Website {
readonly BASE_URL: string = '';
readonly MAX_CHARS: number = 2000;
readonly acceptsFiles: string[] = []; // accepts all
readonly acceptsAdditionalFiles: boolean = true;
readonly enableAdvertisement: boolean = false;
Expand Down Expand Up @@ -163,7 +164,7 @@ export class Discord extends Website {
FormContent.getDescription(defaultPart.data.description, submissionPart.data.description),
);

if (description.length > 2000) {
if (description.length > this.MAX_CHARS) {
warnings.push('Max description length allowed is 2,000 characters.');
}

Expand All @@ -182,7 +183,7 @@ export class Discord extends Website {
FormContent.getDescription(defaultPart.data.description, submissionPart.data.description),
);

if (description.length > 2000) {
if (description.length > this.MAX_CHARS) {
warnings.push('Max description length allowed is 2,000 characters.');
}

Expand Down
1 change: 1 addition & 0 deletions electron-app/src/server/websites/e621/e621.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Website } from '../website.base';
@Injectable()
export class e621 extends Website {
readonly BASE_URL: string = 'https://e621.net';
readonly MAX_CHARS: number = undefined; // No limit
readonly acceptsFiles: string[] = ['jpeg', 'jpg', 'png', 'gif', 'webm'];
readonly acceptsSourceUrls: boolean = true;
readonly defaultDescriptionParser = PlaintextParser.parse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import _ from 'lodash';
export class FurAffinity extends Website {
readonly BASE_URL = 'https://www.furaffinity.net';
readonly waitBetweenPostsInterval = 70000;
readonly MAX_CHARS: number = undefined; // No limit
readonly defaultDescriptionParser = BBCodeParser.parse;
readonly usernameShortcuts = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Website } from '../website.base';
@Injectable()
export class Furbooru extends Website {
BASE_URL: string = 'https://furbooru.org';
readonly MAX_CHARS: number = undefined; // No Limit
acceptsFiles: string[] = ['jpeg', 'jpg', 'png', 'svg', 'gif', 'webm'];
acceptsSourceUrls: boolean = true;
enableAdvertisement: boolean = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import _ from 'lodash';
@Injectable()
export class FurryNetwork extends Website {
readonly BASE_URL: string = 'https://furrynetwork.com';
readonly MAX_CHARS: number = undefined; // No Limit
readonly refreshBeforePost: boolean = true;
readonly acceptsFiles: string[] = [
'png',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { MarkdownParser } from 'src/server/description-parsing/markdown/markdown
@Injectable()
export class Furtastic extends Website {
readonly BASE_URL: string = 'https://api.furtastic.art';
readonly MAX_CHARS: number = undefined; // No Limit
readonly acceptsFiles: string[] = ['jpeg', 'jpg', 'png', 'gif', 'webm', 'pdf'];
readonly defaultDescriptionParser = MarkdownParser.parse;
readonly enableAdvertisement: boolean = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import _ from 'lodash';
@Injectable()
export class HentaiFoundry extends Website {
readonly BASE_URL = 'https://www.hentai-foundry.com';
readonly MAX_CHARS: number = undefined; // No Limit
readonly acceptsFiles = ['jpeg', 'jpg', 'png', 'svg', 'gif'];
readonly defaultDescriptionParser = BBCodeParser.parse;
readonly usernameShortcuts = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { InkbunnyAccountData } from './inkbunny-account.interface';
@Injectable()
export class Inkbunny extends Website {
readonly BASE_URL: string = 'https://inkbunny.net';
readonly MAX_CHARS: number = undefined; // No Limit
readonly acceptsFiles: string[] = [
'png',
'jpeg',
Expand Down
5 changes: 3 additions & 2 deletions electron-app/src/server/websites/itaku/itaku.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import _ from 'lodash';
@Injectable()
export class Itaku extends Website {
BASE_URL: string = 'https://itaku.ee';
readonly MAX_CHARS: number = 5000;
acceptsFiles: string[] = ['jpeg', 'jpg', 'png', 'gif', 'webp', 'mp4', 'mov', 'webm'];
acceptsAdditionalFiles: boolean = false;
readonly defaultDescriptionParser = PlaintextParser.parse;
Expand Down Expand Up @@ -236,7 +237,7 @@ export class Itaku extends Website {
FormContent.getDescription(defaultPart.data.description, submissionPart.data.description),
);

if (description.length > 5000) {
if (description.length > this.MAX_CHARS) {
problems.push(
`Max description length allowed is 5000 characters.`,
);
Expand Down Expand Up @@ -278,7 +279,7 @@ export class Itaku extends Website {
problems.push('Description required');
}

if (description.length > 5000) {
if (description.length > this.MAX_CHARS) {
problems.push(
`Max description length allowed is 5000 characters.`,
);
Expand Down
1 change: 1 addition & 0 deletions electron-app/src/server/websites/ko-fi/ko-fi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import _ from 'lodash';
@Injectable()
export class KoFi extends Website {
readonly BASE_URL: string = 'https://ko-fi.com';
readonly MAX_CHARS: number = undefined; // No Limit
readonly acceptsFiles: string[] = ['jpeg', 'jpg', 'png', 'gif'];
readonly acceptsAdditionalFiles: boolean = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Website } from '../website.base';
@Injectable()
export class Manebooru extends Website {
BASE_URL: string = 'https://manebooru.art';
readonly MAX_CHARS: number = undefined; // No Limit
acceptsFiles: string[] = ['jpeg', 'jpg', 'png', 'svg', 'gif', 'webm'];
acceptsSourceUrls: boolean = true;
enableAdvertisement: boolean = false;
Expand Down
9 changes: 7 additions & 2 deletions electron-app/src/server/websites/mastodon/mastodon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { Injectable } from '@nestjs/common';
import {
FileRecord,
FileSubmissionType,
MegalodonInstanceSettings,
} from 'postybirb-commons';
import { ScalingOptions } from '../interfaces/scaling-options.interface';
import _ from 'lodash';
import { Megalodon } from '../megalodon/megalodon.service';
import { } from 'postybirb-commons';

const INFO_KEY = 'INSTANCE INFO';

Expand Down Expand Up @@ -60,8 +62,11 @@ export class Mastodon extends Megalodon {
getInstanceSettings(accountId: string) {
const instanceInfo: MastodonInstanceInfo = this.getAccountInfo(accountId, INFO_KEY);

this.maxCharLength = instanceInfo?.configuration?.statuses?.max_characters ?? 500;
this.maxMediaCount = instanceInfo ? instanceInfo?.configuration?.statuses?.max_media_attachments : 4;
let result = new MegalodonInstanceSettings();
result.maxChars = instanceInfo?.configuration?.statuses?.max_characters ?? 500;
result.maxImages = instanceInfo ? instanceInfo?.configuration?.statuses?.max_media_attachments : 4;

return result;
}

getScalingOptions(file: FileRecord, accountId: string): ScalingOptions {
Expand Down
Loading