Skip to content

Commit

Permalink
Merge pull request #41 from mvdicarlo/develop
Browse files Browse the repository at this point in the history
v3.0.29
  • Loading branch information
mvdicarlo authored Apr 10, 2021
2 parents 5bea508 + 8c2045a commit ce6e57a
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export interface PatreonFileOptions extends DefaultFileOptions {
schedule?: string; // as date string
teaser?: string;
allAsAttachment: boolean;
earlyAccess?: Date;
}
7 changes: 6 additions & 1 deletion commons/src/websites/patreon/patreon.file.options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Expose } from 'class-transformer';
import { IsArray, IsBoolean, IsDateString, IsOptional, IsString } from 'class-validator';
import { IsArray, IsBoolean, IsDate, IsDateString, IsOptional, IsString } from 'class-validator';
import { DefaultFileOptions } from '../../interfaces/submission/default-options.interface';
import { PatreonFileOptions } from '../../interfaces/websites/patreon/patreon.file.options.interface';
import { DefaultValue } from '../../models/decorators/default-value.decorator';
Expand Down Expand Up @@ -32,6 +32,11 @@ export class PatreonFileOptionsEntity extends DefaultFileOptionsEntity
@DefaultValue(false)
allAsAttachment!: boolean;

@Expose()
@IsOptional()
@IsDate()
earlyAccess?: Date;

constructor(entity?: Partial<PatreonFileOptions>) {
super(entity as DefaultFileOptions);
}
Expand Down
5 changes: 3 additions & 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.28",
"version": "3.0.29",
"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 All @@ -16,11 +16,12 @@
"postinstall": "electron-builder install-app-deps",
"build": "nest build",
"build:linux": "electron-builder -l",
"build:mac": "electron-builder -m",
"build:osx": "electron-builder -m",
"build:windows": "electron-builder -w",
"build:release": "export $(cat .env | xargs) && electron-builder -mwl -p always",
"release:windows": "electron-builder -w -p always",
"release:linux": "electron-builder -l -p always",
"release:osx": "export $(cat .env | xargs) && electron-builder -m -p always",
"clean": "rimraf release",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "npm run prebuild && nest build && electron dist/main --develop",
Expand Down
57 changes: 38 additions & 19 deletions electron-app/src/server/websites/mastodon/mastodon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import WebsiteValidator from 'src/server/utils/website-validator.util';
import { LoginResponse } from '../interfaces/login-response.interface';
import { ScalingOptions } from '../interfaces/scaling-options.interface';
import { Website } from '../website.base';
import * as _ from 'lodash';

@Injectable()
export class Mastodon extends Website {
Expand Down Expand Up @@ -81,7 +82,7 @@ export class Mastodon extends Website {
return { maxSize: FileSize.MBtoBytes(300) };
}

private async uploadMedia(data: MastodonAccountData, file: PostFile): Promise<string> {
private async uploadMedia(data: MastodonAccountData, file: PostFile): Promise<{ id: string }> {
const upload = await Http.post<{ id: string; errors: any }>(
`${data.website}/api/v1/media`,
undefined,
Expand All @@ -106,7 +107,7 @@ export class Mastodon extends Website {
);
}

return upload.body.id;
return { id: upload.body.id };
}

async postFileSubmission(
Expand All @@ -116,29 +117,47 @@ export class Mastodon extends Website {
): Promise<PostResponse> {
const M = this.getMastodonInstance(accountData);

const files = [data.primary, ...data.additional].slice(0, 4);
const files = [data.primary, ...data.additional];
this.checkCancelled(cancellationToken);
const uploadIds = await Promise.all(
files.map(file => this.uploadMedia(accountData, file.file)),
);
const uploadedMedias: {
id: string;
}[] = [];
for (const file of files) {
uploadedMedias.push(await this.uploadMedia(accountData, file.file));
}

const isSensitive = data.rating !== SubmissionRating.GENERAL;

const { options } = data;
const form: any = {
status: `${options.useTitle && data.title ? `${data.title}\n` : ''}${
data.description
}`.substring(0, 500),
sensitive: isSensitive,
media_ids: uploadIds,
};
const chunks = _.chunk(uploadedMedias, 4);
let lastId = undefined;
for (let i = 0; i < chunks.length; i++) {
let form = undefined;
if (i === 0) {
form = {
status: `${options.useTitle && data.title ? `${data.title}\n` : ''}${
data.description
}`.substring(0, 500),
sensitive: isSensitive,
media_ids: chunks[i].map((media) => media.id),
};
} else {
form = {
sensitive: isSensitive,
media_ids: chunks[i].map((media) => media.id),
in_reply_to_id: lastId,
};
}

if (options.spoilerText) {
form.spoiler_text = options.spoilerText;
if (options.spoilerText) {
form.spoiler_text = options.spoilerText;
}

const post = await M.post('statuses', form);
lastId = post.data.id;
}

this.checkCancelled(cancellationToken);
const post = await M.post('statuses', form);

return this.createPostResponse({});
}

Expand Down Expand Up @@ -188,12 +207,12 @@ export class Mastodon extends Website {
const files = [
submission.primary,
...(submission.additional || []).filter(
f => !f.ignoredAccounts!.includes(submissionPart.accountId),
(f) => !f.ignoredAccounts!.includes(submissionPart.accountId),
),
];

const maxMB: number = 300;
files.forEach(file => {
files.forEach((file) => {
const { type, size, name, mimetype } = file;
if (!WebsiteValidator.supportsFileType(file, this.acceptsFiles)) {
problems.push(`Does not support file format: (${name}) ${mimetype}.`);
Expand Down
17 changes: 11 additions & 6 deletions electron-app/src/server/websites/newgrounds/newgrounds.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class Newgrounds extends Website {
}

const newCookies: any = {};
parkFile.response.headers['set-cookie'].forEach(cookie => {
parkFile.response.headers['set-cookie'].forEach((cookie) => {
const cookieParts = cookie.split(';')[0].split('=');
return (newCookies[cookieParts[0]] = cookieParts[1]);
});
Expand Down Expand Up @@ -240,7 +240,14 @@ export class Newgrounds extends Website {
} else {
let message = '';
try {
message = post.body.errors.join(' ');
message = post.body.errors
.map((err) => {
if (err.includes('You must agree to the terms of the submissions agreement.')) {
return 'You must first manually post to Newgrounds to accept the terms of the submissions agreement.';
}
return err;
})
.join(' ');
} catch (err) {
message = (cheerio.load(post.body.error) as any).text();
}
Expand All @@ -256,7 +263,7 @@ export class Newgrounds extends Website {
formatTags(tags: string[]): any {
return super
.formatTags(tags, { spaceReplacer: '-' })
.map(tag => {
.map((tag) => {
return tag.replace(/(\(|\)|:|#|;|\]|\[|')/g, '').replace(/_/g, '-');
})
.slice(0, 12);
Expand Down Expand Up @@ -288,9 +295,7 @@ export class Newgrounds extends Website {
}

if (!WebsiteValidator.supportsFileType(submission.primary, this.acceptsFiles)) {
problems.push(
`Currently supported file formats: ${this.acceptsFiles.join(', ')}`,
);
problems.push(`Currently supported file formats: ${this.acceptsFiles.join(', ')}`);
}

const { type, size, name } = submission.primary;
Expand Down
4 changes: 4 additions & 0 deletions electron-app/src/server/websites/patreon/patreon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ export class Patreon extends Website {
attributes.tags.publish = false;
}

if (options.earlyAccess) {
attributes.change_visibility_at = this.toUTCISO(options.earlyAccess);
}

const relationships = {
post_tag: {
data: relationshipTags.length > 0 ? relationshipTags[0] : {},
Expand Down
58 changes: 53 additions & 5 deletions electron-app/src/server/websites/telegram/telegram.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ScalingOptions } from '../interfaces/scaling-options.interface';
import { Website } from '../website.base';
import { TelegramStorage } from './telegram.storage';
import _ = require('lodash');
import FormContent from 'src/server/utils/form-content.util';

@Injectable()
export class Telegram extends Website {
Expand Down Expand Up @@ -89,10 +90,12 @@ export class Telegram extends Website {
phone_code: data.code,
phone_code_hash: this.authData[data.appId].phone_code_hash,
})
.then(() => true)
.then(() => {
result: true;
})
.catch((err) => {
this.logger.error(err);
return false;
return { result: false, message: err.error_message };
});
}

Expand Down Expand Up @@ -269,6 +272,8 @@ export class Telegram extends Website {
fileData.push(await this.upload(appId, file));
}

const description = data.description.slice(0, 4096).trim();

for (const channel of data.options.channels) {
this.checkCancelled(cancellationToken);
const [channel_id, access_hash] = channel.split('-');
Expand All @@ -278,21 +283,48 @@ export class Telegram extends Website {
access_hash,
};
if (files.length === 1) {
let messagePosted = false;
if (description.length > 1024) {
messagePosted = true;
await this.callApi(accountData.appId, 'messages.sendMessage', {
random_id: Date.now(),
message: data.description.slice(0, 4096).trim(),
peer: {
_: 'inputPeerChannel',
channel_id,
access_hash,
},
});
}
await this.callApi(appId, 'messages.sendMedia', {
random_id: Date.now(),
media: fileData[0],
message: data.description,
message: messagePosted ? '' : data.description,
peer,
silent: data.options.silent,
});
} else {
let messagePosted = false;
if (description.length > 1024) {
messagePosted = true;
await this.callApi(accountData.appId, 'messages.sendMessage', {
random_id: Date.now(),
message: data.description.slice(0, 4096).trim(),
peer: {
_: 'inputPeerChannel',
channel_id,
access_hash,
},
});
}

// multimedia send
const id = Date.now();
for (let i = 0; i < fileData.length; i++) {
await this.callApi(appId, 'messages.sendMedia', {
random_id: id + i,
media: fileData[i],
message: i === 0 ? data.description : '',
message: messagePosted ? '' : i === 0 ? data.description : '',
peer,
silent: data.options.silent,
});
Expand All @@ -316,7 +348,7 @@ export class Telegram extends Website {
const [channel_id, access_hash] = channel.split('-');
await this.callApi(accountData.appId, 'messages.sendMessage', {
random_id: Date.now(),
message: data.description,
message: data.description.slice(0, 4096).trim(),
peer: {
_: 'inputPeerChannel',
channel_id,
Expand Down Expand Up @@ -371,6 +403,14 @@ export class Telegram extends Website {
}
});

const description = this.defaultDescriptionParser(
FormContent.getDescription(defaultPart.data.description, submissionPart.data.description),
);

if (description.length > 4096) {
warnings.push('Max description length allowed is 4,096 characters.');
}

return { problems, warnings };
}

Expand All @@ -397,6 +437,14 @@ export class Telegram extends Website {
problems.push('No channel(s) selected.');
}

const description = this.defaultDescriptionParser(
FormContent.getDescription(defaultPart.data.description, submissionPart.data.description),
);

if (description.length > 4096) {
warnings.push('Max description length allowed is 4,096 characters.');
}

return { problems, warnings };
}
}
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"name": "postybirb-plus",
"version": "3.0.28",
"version": "3.0.29",
"description": "PostyBirb is an application that helps artists post art and other multimedia to multiple websites more quickly..",
"main": "index.js",
"scripts": {
"build": "npm run build:common && yarn run build:ui && yarn run build:app",
"build:app": "cd electron-app && npm install && yarn run build",
"build:common": "cd commons && npm install && npm run build",
"build:ui": "cd ui && npm install && yarn run build",
"release:windows": "node create-signer.js && yarn run build && cd electron-app && yarn run release:windows",
"release:linux": "node create-signer.js && yarn run build && cd electron-app && yarn run release:linux"
"install": "run-p install:**",
"install:commons": "cd commons && npm install && npm run build",
"install:app": "cd electron-app && npm install",
"install:ui": "cd ui && npm install",
"build": "run-p build:**",
"build:app": "cd electron-app && npm run build",
"build:ui": "cd ui && npm run build",
"make": "run-s install build",
"release:windows": "node create-signer.js && npm run make && cd electron-app && yarn run release:windows",
"release:linux": "node create-signer.js && npm run make && cd electron-app && yarn run release:linux",
"release:osx": "npm run make && cd electron-app && yarn run release:osx"
},
"repository": {
"type": "git",
Expand All @@ -23,6 +28,7 @@
"homepage": "https://github.com/mvdicarlo/postybirb-plus#readme",
"dependencies": {
"@mtproto/core": "^5.3.0",
"npm-run-all": "^4.1.5",
"yarn": "^1.22.4"
}
}
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postybirb-plus-ui",
"version": "3.0.28",
"version": "3.0.29",
"license": "BSD-3-Clause",
"private": true,
"Author": "Michael DiCarlo",
Expand Down
16 changes: 12 additions & 4 deletions ui/src/websites/patreon/Patreon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,18 @@ export class PatreonFileSubmissionForm extends GenericFileSubmissionSection<Patr
}
/>
</Form.Item>,
<Form.Item
label="Teaser Text"
help={`${(data.teaser || '').length} / 140`}
>
<Form.Item label="Early Access">
<DatePicker
defaultValue={data.earlyAccess ? moment(data.earlyAccess) : undefined}
format="YYYY-MM-DD HH:mm:ss"
showTime={{ format: 'HH:mm:ss', use12Hours: true }}
placeholder="Unscheduled"
onChange={value =>
this.setValue('earlyAccess', value ? value.toDate().toString() : undefined)
}
/>
</Form.Item>,
<Form.Item label="Teaser Text" help={`${(data.teaser || '').length} / 140`}>
<Input.TextArea
value={data.teaser}
rows={3}
Expand Down
Loading

0 comments on commit ce6e57a

Please sign in to comment.