Skip to content

Commit

Permalink
Merge pull request #349 from mvdicarlo/develop
Browse files Browse the repository at this point in the history
v3.1.45
  • Loading branch information
mvdicarlo authored Jul 26, 2024
2 parents 5c01d14 + baee24d commit 299dc10
Show file tree
Hide file tree
Showing 42 changed files with 327 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface DefaultOptions {
tags: TagData;
description: DescriptionData;
rating?: SubmissionRating | string;
spoilerText?: string;
sources: string[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface ItakuFileOptions extends DefaultFileOptions {
visibility: string;
shareOnFeed: boolean;
spoilerText?: string;
spoilerTextOverwrite?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface ItakuNotificationOptions extends DefaultOptions {
folders: string[];
visibility: string;
spoilerText?: string;
spoilerTextOverwrite?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DefaultFileOptions } from '../../submission/default-options.interface';
export interface MastodonFileOptions extends DefaultFileOptions {
useTitle: boolean;
spoilerText?: string;
spoilerTextOverwrite?: boolean;
visibility: string;
altText?: string;
replyToUrl?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DefaultOptions } from '../../submission/default-options.interface';
export interface MastodonNotificationOptions extends DefaultOptions {
useTitle: boolean;
spoilerText?: string;
spoilerTextOverwrite?: boolean;
visibility: string;
replyToUrl?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DefaultFileOptions } from '../../submission/default-options.interface';
export interface MissKeyFileOptions extends DefaultFileOptions {
useTitle: boolean;
spoilerText?: string;
spoilerTextOverwrite?: boolean;
visibility: string;
altText?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { DefaultOptions } from '../../submission/default-options.interface';
export interface MissKeyNotificationOptions extends DefaultOptions {
useTitle: boolean;
spoilerText?: string;
spoilerTextOverwrite?: boolean;
visibility: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DefaultFileOptions } from '../../submission/default-options.interface';
export interface PixelfedFileOptions extends DefaultFileOptions {
useTitle: boolean;
spoilerText?: string;
spoilerTextOverwrite?: boolean;
visibility: string;
altText?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DefaultFileOptions } from '../../submission/default-options.interface';
export interface PleromaFileOptions extends DefaultFileOptions {
useTitle: boolean;
spoilerText?: string;
spoilerTextOverwrite?: boolean;
visibility: string;
altText?: string;
replyToUrl?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DefaultOptions } from '../../submission/default-options.interface';
export interface PleromaNotificationOptions extends DefaultOptions {
useTitle: boolean;
spoilerText?: string;
spoilerTextOverwrite?: boolean;
visibility: string;
replyToUrl?: string;
}
4 changes: 4 additions & 0 deletions commons/src/models/default-options.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export class DefaultOptionsEntity implements DefaultOptions {
@IsOptional()
rating?: SubmissionRating | string;

@Expose()
@IsOptional()
spoilerText?: string;

@IsArray()
sources: string[];

Expand Down
5 changes: 5 additions & 0 deletions commons/src/websites/itaku/itaku.file.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export class ItakuFileOptionsEntity extends DefaultFileOptionsEntity implements
@IsOptional()
spoilerText?: string;

@Expose()
@IsBoolean()
@IsOptional()
spoilerTextOverwrite?: boolean;

constructor(entity?: Partial<ItakuFileOptions>) {
super(entity as DefaultFileOptions);
}
Expand Down
7 changes: 6 additions & 1 deletion commons/src/websites/itaku/itaku.notification.options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Expose } from 'class-transformer';
import { IsArray, IsString, IsOptional } from 'class-validator';
import { IsArray, IsString, IsOptional, IsBoolean } from 'class-validator';
import { DefaultOptions } from '../../interfaces/submission/default-options.interface';
import { ItakuNotificationOptions } from '../../interfaces/websites/itaku/itaku.notification.options.interface';
import { DefaultValue } from '../../models/decorators/default-value.decorator';
Expand All @@ -24,6 +24,11 @@ export class ItakuNotificationOptionsEntity
@IsOptional()
spoilerText?: string;

@Expose()
@IsBoolean()
@IsOptional()
spoilerTextOverwrite?: boolean;

constructor(entity?: Partial<ItakuNotificationOptions>) {
super(entity as DefaultOptions);
}
Expand Down
5 changes: 5 additions & 0 deletions commons/src/websites/mastodon/mastodon.file.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class MastodonFileOptionsEntity
@IsString()
spoilerText?: string;

@Expose()
@IsBoolean()
@IsOptional()
spoilerTextOverwrite?: boolean;

@Expose()
@IsString()
@DefaultValue('public')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class MastodonNotificationOptionsEntity
@IsString()
spoilerText?: string;

@Expose()
@IsBoolean()
@IsOptional()
spoilerTextOverwrite?: boolean;

@Expose()
@IsString()
@DefaultValue('public')
Expand Down
5 changes: 5 additions & 0 deletions commons/src/websites/misskey/misskey.file.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class MissKeyFileOptionsEntity
@IsString()
spoilerText?: string;

@Expose()
@IsBoolean()
@IsOptional()
spoilerTextOverwrite?: boolean;

@Expose()
@IsString()
@DefaultValue('public')
Expand Down
5 changes: 5 additions & 0 deletions commons/src/websites/misskey/misskey.notification.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class MissKeyNotificationOptionsEntity
@IsString()
spoilerText?: string;

@Expose()
@IsBoolean()
@IsOptional()
spoilerTextOverwrite?: boolean;

@Expose()
@IsString()
@DefaultValue('public')
Expand Down
5 changes: 5 additions & 0 deletions commons/src/websites/pixelfed/pixelfed.file.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class PixelfedFileOptionsEntity
@IsString()
spoilerText?: string;

@Expose()
@IsBoolean()
@IsOptional()
spoilerTextOverwrite?: boolean;

@Expose()
@IsString()
@DefaultValue('public')
Expand Down
7 changes: 6 additions & 1 deletion commons/src/websites/pleroma/pleroma.file.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export class PleromaFileOptionsEntity extends DefaultFileOptionsEntity
@IsOptional()
@IsString()
spoilerText?: string;


@Expose()
@IsBoolean()
@IsOptional()
spoilerTextOverwrite?: boolean;

@Expose()
@IsString()
@DefaultValue('public')
Expand Down
5 changes: 5 additions & 0 deletions commons/src/websites/pleroma/pleroma.notification.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export class PleromaNotificationOptionsEntity extends DefaultOptionsEntity
@IsString()
spoilerText?: string;

@Expose()
@IsBoolean()
@IsOptional()
spoilerTextOverwrite?: boolean;

@Expose()
@IsString()
@DefaultValue('public')
Expand Down
21 changes: 19 additions & 2 deletions electron-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion electron-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postybirb-plus",
"version": "3.1.44",
"version": "3.1.45",
"description": "(ClientServer) PostyBirb is an application that helps artists post art and other multimedia to multiple websites more quickly.",
"main": "dist/main.js",
"author": "Michael DiCarlo",
Expand Down Expand Up @@ -47,6 +47,7 @@
"@nestjs/schedule": "^0.4.2",
"@nestjs/websockets": "^7.6.18",
"@types/node": "^16.10.2",
"async-mutex": "^0.5.0",
"chardet": "^0.8.0",
"cheerio": "^1.0.0-rc.10",
"class-transformer": "^0.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class FileManipulationService {
buffer,
mimeType,
);
this.logger.debug('Acquired Image Manipulator');

try {
let skipRescale = false;
Expand All @@ -48,8 +49,6 @@ export class FileManipulationService {
if (maxSize < im.getHeight() || maxSize < im.getWidth()) {
const scaled = await im.resize(maxSize).getData();
newBuffer = scaled.buffer;
const newIm = await this.imageManipulationPool.getImageManipulator(newBuffer, mimeType);
newIm.destroy();

if (newBuffer.length > targetSize) {
this.logger.debug(
Expand Down Expand Up @@ -91,6 +90,7 @@ export class FileManipulationService {
}
} finally {
im.destroy();
this.logger.debug('Released Image Manipulator');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import os from 'os';
import ImageManipulator from '../manipulators/image.manipulator';
import { UiNotificationService } from 'src/server/notification/ui-notification/ui-notification.service';
import { NotificationType } from 'src/server/notification/enums/notification-type.enum';
import { Mutex } from 'async-mutex';

interface QueuedWaiter {
resolve: (im: ImageManipulator) => void;
Expand All @@ -20,38 +21,45 @@ export class ImageManipulationPoolService {
private inUse: ImageManipulator[] = [];
private readonly MAX_COUNT: number = Math.min(os.cpus().length, 4);
private hasAlerted: boolean = false;
private readonly mutex = new Mutex();

constructor(private readonly uiNotificationService: UiNotificationService) {}

getImageManipulator(data: Buffer, type: string): Promise<ImageManipulator> {
return new Promise(async resolve => {
if (data.length > ImageManipulator.DEFERRED_LIMIT) {
if (this.inUse.length < this.MAX_COUNT) {
const im = await ImageManipulator.build(data, type as any);
this.inUse.push(im);
resolve(im.onDestroy(this.onDestroyCallback.bind(this)));
this.logger.debug(`Pool Size = ${this.inUse.length} of ${this.MAX_COUNT}`);
} else {
this.logger.debug('Queueing Image Manipulator');
this.queue.push({
resolve,
arguments: {
data,
type,
},
});
// mutex is used to ensure that the pool size is not exceeded when rapidly called
const release = await this.mutex.acquire();
try {
if (data.length > ImageManipulator.DEFERRED_LIMIT) {
if (this.inUse.length < this.MAX_COUNT) {
const im = await ImageManipulator.build(data, type as any);
this.inUse.push(im);
resolve(im.onDestroy(this.onDestroyCallback.bind(this)));
this.logger.debug(`Pool Size = ${this.inUse.length} of ${this.MAX_COUNT}`);
} else {
this.logger.debug('Queueing Image Manipulator');
this.queue.push({
resolve,
arguments: {
data,
type,
},
});

if (!this.hasAlerted) {
this.hasAlerted = true;
this.uiNotificationService.createUINotification(
NotificationType.INFO,
0,
'PostyBirb is currently processing many image files. This may affect the time it takes to create or post image based submissions.',
);
if (!this.hasAlerted) {
this.hasAlerted = true;
this.uiNotificationService.createUINotification(
NotificationType.INFO,
0,
'PostyBirb is currently processing many image files. This may affect the time it takes to create or post image based submissions.',
);
}
}
} else {
resolve(await ImageManipulator.build(data, type as any));
}
} else {
resolve(await ImageManipulator.build(data, type as any));
} finally {
release();
}
});
}
Expand Down
Loading

0 comments on commit 299dc10

Please sign in to comment.