Skip to content

Commit

Permalink
chore: sync with main
Browse files Browse the repository at this point in the history
  • Loading branch information
leaftail1880 committed Oct 1, 2024
1 parent cddf646 commit 3fd7ede
Show file tree
Hide file tree
Showing 282 changed files with 13,931 additions and 12,685 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ Thumbs.db
# Public UI dependencies
eui_theme_light.min.css
eui_theme_dark.min.css
apps/postybirb-ui/public/uppy-i18n/*.js
apps/postybirb-ui/public/uppy-i18n/*.js
.nx/cache
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

/dist
/coverage
apps/postybirb-ui/src/icons/icons.ts
apps/postybirb-ui/src/icons/icons.ts
/.nx/cache
8 changes: 2 additions & 6 deletions apps/client-server/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@
}
},
"lint": {
"executor": "@nx/linter:eslint",
"options": {
"lintFilePatterns": ["apps/client-server/**/*.ts"]
},
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/apps/client-server"],
"options": {
"jestConfig": "apps/client-server/jest.config.ts",
"passWithNoTests": true
"jestConfig": "apps/client-server/jest.config.ts"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export class Account extends PostyBirbEntity implements IAccount {
supports: [],
};

constructor(account: Partial<IAccount> & Pick<IAccount, 'name' | 'website'>) {
super();
this.name = account.name;
this.website = account.website;
this.groups = account.groups;
}

toJSON(): IAccountDto {
return serialize(this) as IAccountDto;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export class DirectoryWatcher
})
template?: Rel<Submission>;

constructor(directoryWatcher: IDirectoryWatcher) {
super();
this.path = directoryWatcher.path;
this.importAction = directoryWatcher.importAction;
this.template = directoryWatcher.template as Submission;
}

toJSON(): DirectoryWatcherDto {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return serialize(this as any, {
Expand Down
13 changes: 13 additions & 0 deletions apps/client-server/src/app/database/entities/post-record.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ export class PostRecord extends PostyBirbEntity implements IPostRecord {
@Property({ type: 'string', nullable: false })
resumeMode: PostRecordResumeMode = PostRecordResumeMode.CONTINUE;

constructor(
postRecord: Pick<
IPostRecord,
'parent' | 'completedAt' | 'state' | 'resumeMode'
>
) {
super();
this.parent = postRecord.parent as unknown as Submission;
this.completedAt = postRecord.completedAt;
this.state = postRecord.state;
this.resumeMode = postRecord.resumeMode;
}

toJSON(): PostRecordDto {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return serialize(this as any, { populate: ['children'] }) as PostRecordDto;
Expand Down
11 changes: 11 additions & 0 deletions apps/client-server/src/app/database/entities/submission.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ export class Submission<T extends ISubmissionMetadata = ISubmissionMetadata>
})
posts: Collection<IPostRecord>;

@Property({ type: 'number', nullable: true })
order: number;

constructor(submission: Partial<ISubmission<T>>) {
super();
this.type = submission.type;
this.isScheduled = submission.isScheduled;
this.schedule = submission.schedule;
this.metadata = submission.metadata ?? ({} as T);
}

toJSON(): ISubmissionDto<T> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return serialize(this as any, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export class WebsiteOptions<T extends IWebsiteFormFields = IWebsiteFormFields>
return this?.account?.id === NULL_ACCOUNT_ID;
}

constructor(websiteOptions: Partial<IWebsiteOptions<T>>) {
super();
this.submission = websiteOptions.submission as Submission;
this.data = websiteOptions.data;
this.account = websiteOptions.account as Account;
}

toJSON(): WebsiteOptionsDto<T> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return serialize(this as any, {
Expand Down
30 changes: 22 additions & 8 deletions apps/client-server/src/app/file/file.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import { readFileSync } from 'fs';
import { join } from 'path';
import { AccountService } from '../account/account.service';
import { DatabaseModule } from '../database/database.module';
import { FormGeneratorService } from '../form-generator/form-generator.service';
import { DescriptionParserService } from '../post-parsers/parsers/description-parser.service';
import { TagParserService } from '../post-parsers/parsers/tag-parser.service';
import { TitleParserService } from '../post-parsers/parsers/title-parser.service';
import { PostParsersService } from '../post-parsers/post-parsers.service';
import { SettingsService } from '../settings/settings.service';
import { CreateSubmissionDto } from '../submission/dtos/create-submission.dto';
import { FileSubmissionService } from '../submission/services/file-submission.service';
import { MessageSubmissionService } from '../submission/services/message-submission.service';
import { SubmissionService } from '../submission/services/submission.service';
import { TagConvertersService } from '../tag-converters/tag-converters.service';
import { UserSpecifiedWebsiteOptionsService } from '../user-specified-website-options/user-specified-website-options.service';
import { WebsiteOptionsService } from '../website-options/website-options.service';
import { WebsiteImplProvider } from '../websites/implementations';
Expand Down Expand Up @@ -76,6 +83,13 @@ describe('FileService', () => {
WebsiteRegistryService,
WebsiteOptionsService,
WebsiteImplProvider,
PostParsersService,
TagParserService,
DescriptionParserService,
TitleParserService,
TagConvertersService,
SettingsService,
FormGeneratorService,
],
}).compile();

Expand Down Expand Up @@ -107,11 +121,11 @@ describe('FileService', () => {
expect(file.size).toBe(fileInfo.size);
expect(file.hasThumbnail).toBe(true);
expect(file.props.hasCustomThumbnail).toBe(false);
expect(file.height).toBe(100);
expect(file.width).toBe(100);
expect(file.height).toBe(202);
expect(file.width).toBe(138);
expect(file.file.size).toBe(fileInfo.size);
expect(file.file.height).toBe(100);
expect(file.file.width).toBe(100);
expect(file.file.height).toBe(202);
expect(file.file.width).toBe(138);
expect(file.file.parent.id).toEqual(file.id);
expect(file.file.mimeType).toEqual(fileInfo.mimetype);
expect(file.file.buffer).toEqual(testFile);
Expand Down Expand Up @@ -143,11 +157,11 @@ describe('FileService', () => {
expect(updatedFile.size).toBe(updateFileInfo.size);
expect(updatedFile.hasThumbnail).toBe(true);
expect(updatedFile.props.hasCustomThumbnail).toBe(false);
expect(updatedFile.height).toBe(100);
expect(updatedFile.width).toBe(100);
expect(updatedFile.height).toBe(202);
expect(updatedFile.width).toBe(138);
expect(updatedFile.file.size).toBe(updateFileInfo.size);
expect(updatedFile.file.height).toBe(100);
expect(updatedFile.file.width).toBe(100);
expect(updatedFile.file.height).toBe(202);
expect(updatedFile.file.width).toBe(138);
expect(updatedFile.file.parent.id).toEqual(file.id);
expect(updatedFile.file.mimeType).not.toEqual(updateFileInfo.mimetype);
expect(updatedFile.file.buffer).toEqual(testFile);
Expand Down
21 changes: 4 additions & 17 deletions apps/client-server/src/app/file/services/create-file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ import {
import { PostyBirbRepository } from '../../database/repositories/postybirb-repository';
import { MulterFileInfo } from '../models/multer-file-info';
import { ImageUtil } from '../utils/image.util';
import { IsTestEnvironment } from '../../utils/test.util';

/**
* A Service that defines operations for creating a SubmissionFile.
* TODO check unit tests now that update has happened
* !Sharp hangs when run in test environment. Not sure why, but for now, returning
* !dummy data is enough for testing.
* TODO figure out why multi-submission sometimes breaks entity population
* @class CreateFileService
*/
@Injectable()
Expand Down Expand Up @@ -122,14 +117,10 @@ export class CreateFileService {
const sharpInstance = ImageUtil.load(buf);
let height = 0;
let width = 0;
if (IsTestEnvironment()) {
height = 100;
width = 100;
} else {
const meta = await sharpInstance.metadata();
height = meta.height;
width = meta.width;
}

const meta = await sharpInstance.metadata();
height = meta.height;
width = meta.width;

entity.width = width;
entity.height = height;
Expand Down Expand Up @@ -206,10 +197,6 @@ export class CreateFileService {
width = Math.min(fileWidth, width);
}

if (IsTestEnvironment()) {
return { buffer: Buffer.from([]), height, width };
}

const buffer = await sharpInstance
.resize(width, height)
.png({ quality: 90, force: true })
Expand Down
11 changes: 0 additions & 11 deletions apps/client-server/src/app/file/services/update-file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { PostyBirbRepository } from '../../database/repositories/postybirb-repos
import { MulterFileInfo } from '../models/multer-file-info';
import { ImageUtil } from '../utils/image.util';
import { CreateFileService } from './create-file.service';
import { IsTestEnvironment } from '../../utils/test.util';

/**
* A Service for updating existing SubmissionFile entities.
Expand All @@ -31,7 +30,6 @@ export class UpdateFileService {

/**
* Creates file entity and stores it.
* @todo extra data (image resize per website)
* @todo figure out what to do about non-image
*
* @param {MulterFileInfo} file
Expand Down Expand Up @@ -157,15 +155,6 @@ export class UpdateFileService {
if (ImageUtil.isImage(file.mimetype, false)) {
const sharpInstance = ImageUtil.load(buf);

if (IsTestEnvironment()) {
return {
height: 100,
width: 100,
buffer: buf,
sharpInstance,
};
}

const { height, width } = await sharpInstance.metadata();
return { buffer: buf, width, height, sharpInstance };
}
Expand Down
Loading

0 comments on commit 3fd7ede

Please sign in to comment.