Skip to content

Commit

Permalink
Merge pull request #40 from mvdicarlo/develop
Browse files Browse the repository at this point in the history
v3.0.28
  • Loading branch information
mvdicarlo authored Mar 25, 2021
2 parents dfe4645 + 4f3a899 commit 5bea508
Show file tree
Hide file tree
Showing 24 changed files with 2,062 additions and 1,557 deletions.
2 changes: 1 addition & 1 deletion commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "lib/index",
"types": "lib/index",
"scripts": {
"build": "npm run prebuild && tsc",
"build": "tsc",
"prebuild": "rimraf lib",
"lint": "tslint -p tsconfig.json -c tslint.json",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DefaultFileOptions } from '../../submission/default-options.interface';

export interface SubscribeStarFileOptions extends DefaultFileOptions {
tier?: string;
tiers: string[];
useTitle: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DefaultOptions } from '../../submission/default-options.interface';

export interface SubscribeStarNotificationOptions extends DefaultOptions {
tier?: string;
tiers: string[];
useTitle: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class SubscribeStarFileOptionsEntity extends DefaultFileOptionsEntity
@Expose()
@IsOptional()
@IsString()
tier?: string;
@DefaultValue([])
tiers!: string[];

@Expose()
@IsBoolean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class SubscribeStarNotificationOptionsEntity extends DefaultOptionsEntity
@Expose()
@IsOptional()
@IsString()
tier?: string;
@DefaultValue([])
tiers!: string[];

@Expose()
@IsBoolean()
Expand Down
3,300 changes: 1,852 additions & 1,448 deletions electron-app/package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions electron-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postybirb-plus",
"version": "3.0.27",
"version": "3.0.28",
"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 @@ -52,7 +52,6 @@
"electron-updater": "^4.3.5",
"electron-window-state": "^5.0.3",
"fs-extra": "^8.1.0",
"gif-frames": "^1.0.1",
"iconv-lite": "^0.5.1",
"image-decode": "^1.2.2",
"jimp": "^0.9.3",
Expand Down
32 changes: 18 additions & 14 deletions electron-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ app.commandLine.appendSwitch('disable-background-timer-throttling');

process.env.PORT = process.env.PORT || '9247';
global.AUTH_SERVER_URL = 'https://postybirb-api.cleverapps.io';
global.DEBUG_MODE = !!process.argv.find(arg => arg === '-d' || arg === '--develop');
global.SERVER_ONLY_MODE = !!process.argv.find(arg => arg === '-s' || arg === '--server');
global.DEBUG_MODE = !!process.argv.find((arg) => arg === '-d' || arg === '--develop');
global.SERVER_ONLY_MODE = !!process.argv.find((arg) => arg === '-s' || arg === '--server');
global.BASE_DIRECTORY = path.join(app.getPath('documents'), 'PostyBirb');
global.CHILD_PROCESS_IDS = [];

Expand All @@ -40,6 +40,7 @@ let initializedOnce: boolean = false;
let mainWindowState: WindowStateKeeper.State = null;
let mainWindow: BrowserWindow = null;
let backgroundAlertTimeout = null;
let hasNotifiedAboutBackground = false;
const icon: string = path.join(__dirname, '../build/assets/icons/minnowicon.png');

// Enable windows 10 notifications
Expand Down Expand Up @@ -82,9 +83,9 @@ app.on(
},
);
app.on('quit', () => {
enableSleep()
enableSleep();
clearTimeout(backgroundAlertTimeout);
global.CHILD_PROCESS_IDS.forEach(id => process.kill(id));
global.CHILD_PROCESS_IDS.forEach((id) => process.kill(id));
});

async function initialize() {
Expand Down Expand Up @@ -153,20 +154,23 @@ function createWindow() {
mainWindowState.manage(mainWindow);
}

mainWindow.webContents.on('new-window', event => event.preventDefault());
mainWindow.webContents.on('new-window', (event) => event.preventDefault());
mainWindow.on('closed', () => {
mainWindow = null;
if (global.tray && util.isWindows()) {
clearTimeout(backgroundAlertTimeout);
backgroundAlertTimeout = setTimeout(() => {
const notification = new Notification({
title: 'PostyBirb',
icon,
body: 'PostyBirb will continue in the background.',
silent: true,
});
notification.show();
}, 750);
if (!hasNotifiedAboutBackground) {
backgroundAlertTimeout = setTimeout(() => {
hasNotifiedAboutBackground = true;
const notification = new Notification({
title: 'PostyBirb',
icon,
body: 'PostyBirb will continue in the background.',
silent: true,
});
notification.show();
}, 750);
}
}
});

Expand Down
33 changes: 12 additions & 21 deletions electron-app/src/server/file-manager/file-manager.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Injectable, Logger } from '@nestjs/common';
import { detect } from 'chardet';
import { app, nativeImage } from 'electron';
import * as fs from 'fs-extra';
import * as shortid from 'shortid';
import { decode } from 'iconv-lite';
import * as _ from 'lodash';
import * as path from 'path';
import { FileRecord, FileSubmission, UploadedFile } from 'postybirb-commons';

import { Injectable, Logger } from '@nestjs/common';
import * as shortid from 'shortid';
import { SUBMISSION_FILE_DIRECTORY, THUMBNAIL_FILE_DIRECTORY } from 'src/server/directories';

import { app, nativeImage } from 'electron';
import * as gifFrames from 'gif-frames';
import ImageManipulator from 'src/server/file-manipulation/manipulators/image.manipulator';
import { decode } from 'iconv-lite';
import { detect } from 'chardet';
import { ImageManipulationPoolService } from 'src/server/file-manipulation/pools/image-manipulation-pool.service';
import { GifManipulator } from '../file-manipulation/manipulators/gif.manipulator';

@Injectable()
export class FileManagerService {
Expand Down Expand Up @@ -44,17 +42,13 @@ export class FileManagerService {
if (file.mimetype.includes('image')) {
if (file.mimetype === 'image/gif') {
await fs.outputFile(submissionFilePath, file.buffer);
const [frame0] = await gifFrames({ url: file.buffer, frames: 0 });

const frame0 = await GifManipulator.getFrame(file.buffer);
const im: ImageManipulator = await this.imageManipulationPool.getImageManipulator(
frame0.getImage().read(),
frame0,
'image/jpeg',
);
thumbnail = (
await im
.resize(300)
.setQuality(99)
.getData()
).buffer;
thumbnail = (await im.resize(300).setQuality(99).getData()).buffer;
} else if (ImageManipulator.isMimeType(file.mimetype)) {
const im: ImageManipulator = await this.imageManipulationPool.getImageManipulator(
file.buffer,
Expand All @@ -75,10 +69,7 @@ export class FileManagerService {
ext: `.${ImageManipulator.getExtension(data.type)}`,
});

const thumbnailData = await im
.resize(300)
.setQuality(99)
.getData();
const thumbnailData = await im.resize(300).setQuality(99).getData();
thumbnail = thumbnailData.buffer;
thumbnailFilePath = `${THUMBNAIL_FILE_DIRECTORY}/${fileId}.${ImageManipulator.getExtension(
thumbnailData.type,
Expand Down Expand Up @@ -129,7 +120,7 @@ export class FileManagerService {
submission.fallback,
...(submission.additional || []),
];
await Promise.all(files.filter(f => !!f).map(f => this.removeSubmissionFile(f)));
await Promise.all(files.filter((f) => !!f).map((f) => this.removeSubmissionFile(f)));
}

scaleImage(file: UploadedFile, scalePx: number): UploadedFile {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Jimp = require('jimp');

export class GifManipulator {
static async getFrame(fileBuffer: Buffer): Promise<Buffer> {
const gif = await Jimp.read(fileBuffer);
return await gif.getBufferAsync(Jimp.MIME_PNG);
}
}
5 changes: 5 additions & 0 deletions electron-app/src/server/remote/remote.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ export class RemoteController {
}
res.sendFile(query.uri);
}

@Get('ping')
ping() {
return 'pong';
}
}
8 changes: 4 additions & 4 deletions electron-app/src/server/submission/parser/parser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ export class ParserService {
if (tags.length) {
const conversionMap = {};
(await this.tagConverter.getTagConvertersForWebsite(website.constructor.name)).forEach(
converter => {
(converter) => {
conversionMap[converter.tag] = converter.getTagForWebsite(website.constructor.name);
},
);

tags = tags.map(tag => conversionMap[tag] || tag);
tags = tags.map((tag) => conversionMap[tag] || tag).filter((tag) => !!tag.trim().length);
}

return tags;
Expand Down Expand Up @@ -157,11 +157,11 @@ export class ParserService {

if (website.acceptsAdditionalFiles) {
const additionalFiles = (submission.additional || []).filter(
record => !record.ignoredAccounts!.includes(websitePart.accountId),
(record) => !record.ignoredAccounts!.includes(websitePart.accountId),
);

data.additional = await Promise.all(
additionalFiles.map(file => this.attemptFileScale(website, file, canScale)),
additionalFiles.map((file) => this.attemptFileScale(website, file, canScale)),
);
} else {
data.additional = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@nestjs/common';
import * as cheerio from 'cheerio';
import { nativeImage } from 'electron';
import * as gifFrames from 'gif-frames';
import {
DefaultOptions,
FileRecord,
Expand All @@ -13,6 +12,7 @@ import {
SubmissionPart,
} from 'postybirb-commons';
import UserAccountEntity from 'src/server//account/models/user-account.entity';
import { GifManipulator } from 'src/server/file-manipulation/manipulators/gif.manipulator';
import ImageManipulator from 'src/server/file-manipulation/manipulators/image.manipulator';
import Http from 'src/server/http/http.util';
import { CancellationToken } from 'src/server/submission/post/cancellation/cancellation-token';
Expand Down Expand Up @@ -158,12 +158,12 @@ export class Newgrounds extends Website {

let thumbfile = data.thumbnail ? data.thumbnail : data.primary.file;
if (!data.thumbnail && data.primary.file.options.contentType === 'image/gif') {
const [frame0] = await gifFrames({ url: data.primary.file.value, frames: 0 });
const frame0 = await GifManipulator.getFrame(data.primary.file.value);
thumbfile = {
value: frame0.getImage().read(),
value: frame0,
options: {
filename: 'thumbnail.jpg',
contentType: 'image/jpg',
filename: 'thumbnail.png',
contentType: 'image/png',
},
};
}
Expand Down
4 changes: 2 additions & 2 deletions electron-app/src/server/websites/patreon/patreon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export class Patreon extends Website {
post_type: createData.data.type,
is_paid: options.charge ? 'true' : 'false',
title: data.title,
teaser_text: options.teaser || '',
teaser_text: (options.teaser || '').slice(0, 140),
post_metadata: {},
tags: { publish: true },
};
Expand Down Expand Up @@ -456,7 +456,7 @@ export class Patreon extends Website {
post_type: createData.data.type,
is_paid: options.charge ? 'true' : 'false',
title: data.title,
teaser_text: options.teaser || '',
teaser_text: (options.teaser || '').slice(0, 140),
post_metadata: {},
tags: { publish: true },
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class SubscribeStar extends Website {
}</div>`,
pinned_uploads: '[]',
new_editor: 'true',
'tier_ids[]': data.options.tier === 'free' ? undefined : data.options.tier,
'tier_ids[]': data.options.tiers.includes('free') ? undefined : data.options.tiers,
'tags[]': data.tags,
};

Expand Down Expand Up @@ -158,7 +158,7 @@ export class SubscribeStar extends Website {
page.body = page.body.replace(/\&quot;/g, '"');
const csrf = page.body.match(/<meta name="csrf-token" content="(.*?)"/)[1];

const files = [data.primary, ...data.additional].map(f => f.file);
const files = [data.primary, ...data.additional].map((f) => f.file);
const postKey = page.body.match(/data-s3-upload-path=\\"(.*?)\\"/)[1];
const uploadURL = page.body.match(/data-s3-url="(.*?)"/)[1];
this.checkCancelled(cancellationToken);
Expand Down Expand Up @@ -217,7 +217,7 @@ export class SubscribeStar extends Website {
if (files.length > 1) {
const order = processData.imgs_and_videos
.sort((a, b) => a.id - b.id)
.map(record => record.id);
.map((record) => record.id);

const reorder = await Http.post<{ error: any; html: string }>(
`${this.BASE_URL}/post_uploads/reorder`,
Expand Down Expand Up @@ -245,7 +245,7 @@ export class SubscribeStar extends Website {
}</div>`,
pinned_uploads: '[]',
new_editor: 'true',
'tier_ids[]': data.options.tier === 'free' ? undefined : data.options.tier,
'tier_ids[]': data.options.tiers.includes('free') ? undefined : data.options.tiers,
'tags[]': data.tags,
};

Expand Down Expand Up @@ -287,29 +287,31 @@ export class SubscribeStar extends Website {
const warnings: string[] = [];
const isAutoscaling: boolean = submissionPart.data.autoScale;

if (!submissionPart.data.tier) {
problems.push('No access tier selected.');
if (!submissionPart.data.tiers) {
problems.push('No access tiers selected.');
}

if (submissionPart.data.tier) {
if (submissionPart.data.tiers && submissionPart.data.tiers.length) {
const folders: Folder[] = _.get(
this.accountInformation.get(submissionPart.accountId),
GenericAccountProp.FOLDERS,
[],
);
if (!folders.find(f => f.value === submissionPart.data.tier)) {
warnings.push(`Access Tier (${submissionPart.data.tier}) not found.`);
}
submissionPart.data.tiers.forEach((tier) => {
if (!folders.find((f) => f.value === tier)) {
warnings.push(`Access Tier (${tier}) not found.`);
}
});
}

const files = [
submission.primary,
...(submission.additional || []).filter(
f => !f.ignoredAccounts!.includes(submissionPart.accountId),
(f) => !f.ignoredAccounts!.includes(submissionPart.accountId),
),
];

files.forEach(file => {
files.forEach((file) => {
const { type, size, name, mimetype } = file;
let maxMB = 5;
if (type === FileSubmissionType.AUDIO) {
Expand Down Expand Up @@ -344,20 +346,23 @@ export class SubscribeStar extends Website {
const problems: string[] = [];
const warnings: string[] = [];

if (!submissionPart.data.tier) {
problems.push('No access tier selected.');
if (!submissionPart.data.tiers) {
problems.push('No access tiers selected.');
}

if (submissionPart.data.tier) {
if (submissionPart.data.tiers && submissionPart.data.tiers.length) {
const folders: Folder[] = _.get(
this.accountInformation.get(submissionPart.accountId),
GenericAccountProp.FOLDERS,
[],
);
if (!folders.find(f => f.value === submissionPart.data.tier)) {
warnings.push(`Access Tier (${submissionPart.data.tier}) not found.`);
}
submissionPart.data.tiers.forEach((tier) => {
if (!folders.find((f) => f.value === tier)) {
warnings.push(`Access Tier (${tier}) not found.`);
}
});
}

return { problems, warnings };
}
}
Loading

0 comments on commit 5bea508

Please sign in to comment.