Skip to content

Commit

Permalink
chore: creation of website contribution guide (#323)
Browse files Browse the repository at this point in the history
- Additionally adds website creation script for quick starts
  • Loading branch information
mvdicarlo authored Jan 6, 2025
1 parent b27668c commit b15dc4b
Show file tree
Hide file tree
Showing 62 changed files with 2,196 additions and 220 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# dependencies
/node_modules
scripts/node_modules

# IDEs and editors
/.idea
Expand Down
3 changes: 2 additions & 1 deletion TRANSLATION.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Translation guide

## How to contribute to translation

Go to [PostyBirb site](https://hosted.weblate.org/projects/postybirb/postybirb/), create account and suggest translation!
Expand All @@ -8,4 +9,4 @@ Go to [PostyBirb site](https://hosted.weblate.org/projects/postybirb/postybirb/)
To add new language you need to add [language 2-letter code](https://www.loc.gov/standards/iso639-2/php/code_list.php) to these files:

- [lingui.config.ts](./lingui.config.ts)
- [languages.tsx](./apps/postybirb-ui/src/app/languages.tsx)
- [languages.tsx](./apps/postybirb-ui/src/app/languages.tsx)
2 changes: 1 addition & 1 deletion apps/client-server/src/app/account/account.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MikroORM } from '@mikro-orm/core';
import { Test, TestingModule } from '@nestjs/testing';
import { DatabaseModule } from '../database/database.module';
import { WebsiteImplProvider } from '../websites/implementations';
import { WebsiteImplProvider } from '../websites/implementations/provider';
import { WebsiteRegistryService } from '../websites/website-registry.service';
import { AccountService } from './account.service';
import { CreateAccountDto } from './dtos/create-account.dto';
Expand Down
2 changes: 1 addition & 1 deletion apps/client-server/src/app/file/file.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { TagConvertersService } from '../tag-converters/tag-converters.service';
import { UserSpecifiedWebsiteOptionsService } from '../user-specified-website-options/user-specified-website-options.service';
import { ValidationService } from '../validation/validation.service';
import { WebsiteOptionsService } from '../website-options/website-options.service';
import { WebsiteImplProvider } from '../websites/implementations';
import { WebsiteImplProvider } from '../websites/implementations/provider';
import { WebsiteRegistryService } from '../websites/website-registry.service';
import { FileService } from './file.service';
import { MulterFileInfo } from './models/multer-file-info';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class FormGeneratorService {
}

// Get data for inserting into form
const data = instance.getWebsiteData();
const data = instance.getFormProperties();

// Get form model
let formModel: IWebsiteFormFields = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DatabaseModule } from '../database/database.module';
import { FormGeneratorModule } from '../form-generator/form-generator.module';
import { SettingsModule } from '../settings/settings.module';
import { TagConvertersModule } from '../tag-converters/tag-converters.module';
import { WebsiteImplProvider } from '../websites/implementations';
import { WebsiteImplProvider } from '../websites/implementations/provider';
import { DescriptionParserService } from './parsers/description-parser.service';
import { TagParserService } from './parsers/tag-parser.service';
import { TitleParserService } from './parsers/title-parser.service';
Expand Down
41 changes: 36 additions & 5 deletions apps/client-server/src/app/post/models/posting-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ import {
FileMetadataFields,
FileType,
IFileBuffer,
IFileDimensions,
SubmissionFileId,
} from '@postybirb/types';
import { getFileType } from '@postybirb/utils/file-type';
import { parse } from 'path';

export type ThumbnailOptions = {
buffer: Buffer;
fileName: string;
} & Omit<IFileDimensions, 'size'>;
export type ThumbnailOptions = Pick<
IFileBuffer,
'buffer' | 'height' | 'width' | 'mimeType' | 'fileName'
>;

export type FormDataFileFormat = {
value: Buffer;
options: {
contentType: string;
filename: string;
};
};

export class PostingFile {
public readonly id: SubmissionFileId;
Expand Down Expand Up @@ -56,4 +63,28 @@ export class PostingFile {
this.metadata = metadata;
return this;
}

public toPostFormat(): FormDataFileFormat {
return {
value: this.buffer,
options: {
contentType: this.mimeType,
filename: this.fileName,
},
};
}

public thumbnailToPostFormat(): FormDataFileFormat | undefined {
if (!this.thumbnail) {
return undefined;
}

return {
value: this.thumbnail.buffer,
options: {
contentType: this.thumbnail.mimeType,
filename: this.thumbnail.fileName,
},
};
}
}
2 changes: 1 addition & 1 deletion apps/client-server/src/app/post/post.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PostParsersModule } from '../post-parsers/post-parsers.module';
import { SettingsModule } from '../settings/settings.module';
import { ValidationModule } from '../validation/validation.module';
import { WebsiteOptionsModule } from '../website-options/website-options.module';
import { WebsiteImplProvider } from '../websites/implementations';
import { WebsiteImplProvider } from '../websites/implementations/provider';
import { WebsitesModule } from '../websites/websites.module';
import { PostController } from './post.controller';
import { PostService } from './post.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ export class PostFileResizerService {
instance = instance.jpeg({ quality: 99 });
}

({ width, height } = await instance.metadata());
const { name } = parse(thumb.fileName);
return {
buffer: await instance.toBuffer(),
fileName: `${name}${extension}`,
width: metadata.width,
height: metadata.height,
mimeType: thumb.mimeType,
height,
width
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import { PostFileResizerService } from '../post-file-resizer/post-file-resizer.s

type LoadedPostRecord = Loaded<PostRecord, never>;

// TODO - HEAVILY TEST THIS WITH UNIT AND MANUAL TESTING, ESPECIALLY FILE SUBMISSIONS
// SCENARIOS - ALT FILES, RESIZE, CONVERT, CANCELLATION, BATCHING, SRC INSERTION
@Injectable()
export class PostManagerService {
private readonly logger = Logger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { BadRequestException, NotFoundException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { PostyBirbDirectories, writeSync } from '@postybirb/fs';
import {
DefaultDescriptionValue,
IWebsiteFormFields,
NULL_ACCOUNT_ID,
ScheduleType,
SubmissionRating,
SubmissionType,
WebsiteOptionsDto,
DefaultDescriptionValue,
IWebsiteFormFields,
NULL_ACCOUNT_ID,
ScheduleType,
SubmissionRating,
SubmissionType,
WebsiteOptionsDto,
} from '@postybirb/types';
import { readFileSync } from 'fs';
import { join } from 'path';
Expand All @@ -27,7 +27,7 @@ import { UserSpecifiedWebsiteOptionsModule } from '../../user-specified-website-
import { UserSpecifiedWebsiteOptionsService } from '../../user-specified-website-options/user-specified-website-options.service';
import { ValidationService } from '../../validation/validation.service';
import { WebsiteOptionsService } from '../../website-options/website-options.service';
import { WebsiteImplProvider } from '../../websites/implementations';
import { WebsiteImplProvider } from '../../websites/implementations/provider';
import { WebsiteRegistryService } from '../../websites/website-registry.service';
import { WebsitesModule } from '../../websites/websites.module';
import { CreateSubmissionDto } from '../dtos/create-submission.dto';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DatabaseUpdateSubscriber } from '../database/subscribers/database.subsc
import { FileConverterService } from '../file-converter/file-converter.service';
import { PostParsersModule } from '../post-parsers/post-parsers.module';
import { PostParsersService } from '../post-parsers/post-parsers.service';
import { WebsiteImplProvider } from '../websites/implementations';
import { WebsiteImplProvider } from '../websites/implementations/provider';
import { WebsiteRegistryService } from '../websites/website-registry.service';
import { WebsitesModule } from '../websites/websites.module';
import { ValidationService } from './validation.service';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MikroORM } from '@mikro-orm/core';
import { Test, TestingModule } from '@nestjs/testing';
import {
DefaultDescriptionValue,
DefaultTagValue,
IWebsiteFormFields,
SubmissionRating,
SubmissionType,
DefaultDescriptionValue,
DefaultTagValue,
IWebsiteFormFields,
SubmissionRating,
SubmissionType,
} from '@postybirb/types';
import { AccountModule } from '../account/account.module';
import { AccountService } from '../account/account.service';
Expand All @@ -24,7 +24,7 @@ import { SubmissionService } from '../submission/services/submission.service';
import { UserSpecifiedWebsiteOptionsModule } from '../user-specified-website-options/user-specified-website-options.module';
import { UserSpecifiedWebsiteOptionsService } from '../user-specified-website-options/user-specified-website-options.service';
import { ValidationService } from '../validation/validation.service';
import { WebsiteImplProvider } from '../websites/implementations';
import { WebsiteImplProvider } from '../websites/implementations/provider';
import { WebsiteRegistryService } from '../websites/website-registry.service';
import { WebsitesModule } from '../websites/websites.module';
import { CreateWebsiteOptionsDto } from './dtos/create-website-options.dto';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
PostResponse,
SimpleValidationResult
} from '@postybirb/types';
import { Class } from 'type-fest';
import { CancellableToken } from '../../../post/models/cancellable-token';
import { PostingFile } from '../../../post/models/posting-file';
import { CustomLoginFlow } from '../../decorators/login-flow.decorator';
Expand Down Expand Up @@ -39,10 +38,6 @@ export default class Discord
FileWebsite<DiscordFileSubmission>,
MessageWebsite<DiscordMessageSubmission>
{
FileModel: Class<DiscordFileSubmission> = DiscordFileSubmission;

MessageModel: Class<DiscordMessageSubmission> = DiscordMessageSubmission;

protected BASE_URL: string;

public externallyAccessibleWebsiteDataProperties: DataPropertyAccessibility<DiscordAccountData> =
Expand All @@ -60,11 +55,11 @@ export default class Discord
}

createMessageModel(): DiscordMessageSubmission {
return new this.MessageModel();
return new DiscordMessageSubmission();
}

createFileModel(): DiscordFileSubmission {
return new this.FileModel();
return new DiscordFileSubmission();
}

calculateImageResize(file: ISubmissionFile): ImageResizeProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
BooleanField,
DescriptionField,
RatingField,
TextField,
Expand All @@ -11,12 +10,6 @@ import {
} from '@postybirb/types';

export class DiscordFileSubmission implements IWebsiteFormFields {
@BooleanField({ label: 'useThumbnail', defaultValue: true })
useThumbnail = true;

@BooleanField({ label: 'allowResize', defaultValue: true })
allowResize = true;

@TextField({ label: 'title', defaultValue: '' })
title?: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SimpleValidationResult
} from '@postybirb/types';
import { load } from 'cheerio';
import { Class } from 'type-fest';
import { CancellableToken } from '../../../post/models/cancellable-token';
import { PostingFile } from '../../../post/models/posting-file';
import { UserLoginFlow } from '../../decorators/login-flow.decorator';
Expand Down Expand Up @@ -46,11 +45,6 @@ export default class FurAffinity
MessageWebsite<FurAffinityMessageSubmission>,
WithCustomDescriptionParser
{
FileModel: Class<FurAffinityFileSubmission> = FurAffinityFileSubmission;

MessageModel: Class<FurAffinityMessageSubmission> =
FurAffinityMessageSubmission;

protected BASE_URL = 'https://furaffinity.net';

public externallyAccessibleWebsiteDataProperties: DataPropertyAccessibility<FurAffinityAccountData> =
Expand All @@ -59,24 +53,29 @@ export default class FurAffinity
};

public async onLogin(): Promise<ILoginState> {
const res = await Http.get<string>(
`${this.BASE_URL}/controls/submissions`,
{ partition: this.accountId },
);

if (res.body.includes('logout-link')) {
const $ = load(res.body);
return this.loginState.setLogin(
true,
$('.loggedin_user_avatar').attr('alt'),
try {
const res = await Http.get<string>(
`${this.BASE_URL}/controls/submissions`,
{ partition: this.accountId },
);
}

return this.loginState.setLogin(false, null);
if (res.body.includes('logout-link')) {
const $ = load(res.body);
return this.loginState.setLogin(
true,
$('.loggedin_user_avatar').attr('alt'),
);
}

return this.loginState.setLogin(false, null);
} catch (e) {
this.logger.error('Failed to login', e);
return this.loginState.setLogin(false, null);
}
}

createFileModel(): FurAffinityFileSubmission {
return new this.FileModel();
return new FurAffinityFileSubmission();
}

calculateImageResize(file: ISubmissionFile): ImageResizeProps {
Expand All @@ -102,7 +101,7 @@ export default class FurAffinity
}

createMessageModel(): FurAffinityMessageSubmission {
return new this.MessageModel();
return new FurAffinityMessageSubmission();
}

onPostMessageSubmission(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {
BooleanField,
DescriptionField,
RatingField,
TagField,
TextField,
TextField
} from '@postybirb/form-builder';
import {
DescriptionValue,
Expand All @@ -13,12 +12,6 @@ import {
} from '@postybirb/types';

export class FurAffinityFileSubmission implements IWebsiteFormFields {
@BooleanField({ label: 'useThumbnail', defaultValue: true })
useThumbnail = true;

@BooleanField({ label: 'allowResize', defaultValue: true })
allowResize = true;

@TextField({ label: 'title', required: true, row: 0, col: 1 })
title: string;

Expand Down
20 changes: 2 additions & 18 deletions apps/client-server/src/app/websites/implementations/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
import { Provider } from '@nestjs/common';
import { Class } from 'type-fest';
import { WEBSITE_IMPLEMENTATIONS } from '../../constants';
import { UnknownWebsite } from '../website';
import Discord from './discord/discord.website';
import FurAffinity from './fur-affinity/fur-affinity.website';
import TestWebsite from './test/test.website';

const useValue: Class<UnknownWebsite>[] = [Discord, FurAffinity, TestWebsite];

// if (IsTestEnvironment()) {
useValue.push(TestWebsite);
// }

export const WebsiteImplProvider: Provider<Class<UnknownWebsite>[]> = {
provide: WEBSITE_IMPLEMENTATIONS,
useValue,
};
export { default as Discord } from './discord/discord.website';
export { default as FurAffinity } from './fur-affinity/fur-affinity.website';
Loading

0 comments on commit b15dc4b

Please sign in to comment.