Skip to content

Commit

Permalink
Merge pull request #51 from mvdicarlo/develop
Browse files Browse the repository at this point in the history
v3.0.36
  • Loading branch information
mvdicarlo authored Jun 22, 2021
2 parents e2562cd + 83aec1f commit 0a5abc8
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 46 deletions.
2 changes: 1 addition & 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.0.35",
"version": "3.0.36",
"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
2 changes: 1 addition & 1 deletion electron-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.commandLine.appendSwitch('disable-renderer-backgrounding');
app.commandLine.appendSwitch('disable-background-timer-throttling');

process.env.PORT = process.env.PORT || '9247';
global.AUTH_SERVER_URL = 'https://postybirb-api.cleverapps.io';
global.AUTH_SERVER_URL = 'https://postybirb-auth.azurewebsites.net';
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ export class DescriptionParser {
private parseShortcuts(description: string): ShortcutData[] {
const matches = description.match(/\{([^\{]*?)\}/gms) || [];
return matches.map((m) => {
const [originalText, modifiersText, mods, key, additionalText] = m.match(
/\{(\[([^\[\]]*)\])?(\w+):?(.*?)\}/s,
);
const matchInfo = m.match(/\{(\[([^\[\]]*)\])?(\w+):?(.*?)\}/s);
if (!matchInfo) {
throw new Error(`Invalid shortcut: ${m}`);
}
const [originalText, modifiersText, mods, key, additionalText] = matchInfo;
const modifiers = {};
if (mods) {
mods
Expand Down
6 changes: 3 additions & 3 deletions electron-app/src/server/submission/post/poster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class Poster extends EventEmitter {
return new Promise(async (resolve, reject) => {
let totalTries = this.retries + 1;
let error = null;
// Timeout after 15 minutes
// Timeout after 20 minutes
const timeoutTimer = setTimeout(() => {
if (!this.isDone) {
this.cancel();
Expand All @@ -201,8 +201,8 @@ export class Poster extends EventEmitter {
),
);
}
}, 15 * 60000);
while (totalTries > 0) {
}, 20 * 60000);
while (totalTries > 0 && !this.isCancelled()) {
try {
totalTries--;
const accountData: any = (await this.accountService.get(this.part.accountId)).data;
Expand Down
75 changes: 40 additions & 35 deletions electron-app/src/server/submission/submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,20 @@ export class SubmissionService {
@Interval(60000)
async queueScheduledSubmissions() {
this.logger.debug('Schedule Post Check', 'Schedule Check');
const submissions: Array<SubmissionPackage<any>> = await this.getAllAndValidate();
const submissions: Array<SubmissionPackage<SubmissionEntity>> = await this.getAllAndValidate();
const now = Date.now();
submissions
.filter(p => p.submission.schedule.isScheduled)
.filter(p => p.submission.schedule.postAt <= now)
.filter(p => !this.postService.isCurrentlyPosting(p.submission))
.filter(p => !this.postService.isCurrentlyQueued(p.submission))
.sort((a, b) => a.submission.schedule.postAt - b.submission.schedule.postAt)
.forEach(p => {
.filter((p) => p.submission.schedule.isScheduled)
.filter((p) => p.submission.schedule.postAt <= now)
.filter((p) => !this.postService.isCurrentlyPosting(p.submission))
.filter((p) => !this.postService.isCurrentlyQueued(p.submission))
.sort((a, b) => {
if (a.submission.schedule.postAt === b.submission.schedule.postAt) {
return a.submission.order - b.submission.order;
}
return a.submission.schedule.postAt - b.submission.schedule.postAt;
})
.forEach((p) => {
this.scheduleSubmission(p.submission._id, false);
this.postService.queue(p.submission);
});
Expand All @@ -88,7 +93,7 @@ export class SubmissionService {
async checkForQueuedOrScheduled() {
this.logger.debug('Queued/Scheduled Check');
const submissions: Array<SubmissionPackage<any>> = await this.getAllAndValidate();
const hasScheduled = !!submissions.filter(p => p.submission.schedule.isScheduled).length;
const hasScheduled = !!submissions.filter((p) => p.submission.schedule.isScheduled).length;
const hasQueuedOrPosting =
this.postService.hasAnyQueued() || this.postService.isCurrentlyPostingToAny();

Expand Down Expand Up @@ -126,7 +131,7 @@ export class SubmissionService {
}

const submissions = await this.repository.find(query);
submissions.forEach(submission => {
submissions.forEach((submission) => {
submission.isPosting = this.postService.isCurrentlyPosting(submission);
submission.isQueued = this.postService.isCurrentlyQueued(submission);
});
Expand All @@ -135,8 +140,8 @@ export class SubmissionService {
}

async getAllAndValidate(type?: SubmissionType): Promise<Array<SubmissionPackage<any>>> {
return (await Promise.all((await this.getAll(type)).map(s => this.validate(s)))).filter(
s => Object.keys(s.parts).length,
return (await Promise.all((await this.getAll(type)).map((s) => this.validate(s)))).filter(
(s) => Object.keys(s.parts).length,
); // filter out submissions that are missing parts entirely (assumes it is currently being deleted)
}

Expand Down Expand Up @@ -180,7 +185,7 @@ export class SubmissionService {
if (createDto.parts) {
const parts: Array<SubmissionPart<any>> = JSON.parse(createDto.parts);
await Promise.all(
parts.map(part => {
parts.map((part) => {
delete part._id;
delete part.lastUpdated;
delete part.created;
Expand Down Expand Up @@ -228,14 +233,14 @@ export class SubmissionService {

try {
const submissionParts: Array<SubmissionPartEntity<any>> = parts
.map(responsePart => responsePart.part)
.map(part => {
.map((responsePart) => responsePart.part)
.map((part) => {
part.submissionId = newSubmission._id;
part.postStatus = 'UNPOSTED';
part.postedTo = undefined;
return part;
})
.filter(async part => {
.filter(async (part) => {
try {
if (part.isDefault) {
return true;
Expand All @@ -246,13 +251,13 @@ export class SubmissionService {
return false;
}
})
.map(part => new SubmissionPartEntity(part));
.map((part) => new SubmissionPartEntity(part));

const defaultEntity = new SubmissionPartEntity(defaultPart);
defaultEntity.submissionId = newSubmission._id;

await Promise.all([
...submissionParts.map(p =>
...submissionParts.map((p) =>
this.partService.createOrUpdateSubmissionPart(p, newSubmission.type),
),
this.partService.createOrUpdateSubmissionPart(defaultEntity, newSubmission.type),
Expand Down Expand Up @@ -324,21 +329,21 @@ export class SubmissionService {

const unsupportedAdditionalWebsites = this.websiteProvider
.getAllWebsiteModules()
.filter(w => !w.acceptsAdditionalFiles)
.map(w => w.constructor.name);
.filter((w) => !w.acceptsAdditionalFiles)
.map((w) => w.constructor.name);

const parts = await this.partService.getPartsForSubmission(submission._id, true);

const websitePartsThatNeedSplitting = parts
.filter(p => !p.isDefault)
.filter(p => unsupportedAdditionalWebsites.includes(p.website));
.filter((p) => !p.isDefault)
.filter((p) => unsupportedAdditionalWebsites.includes(p.website));

if (!websitePartsThatNeedSplitting.length) {
return; // Nothing needs to be done
}

// Reintroduce default part
websitePartsThatNeedSplitting.push(parts.find(p => p.isDefault));
websitePartsThatNeedSplitting.push(parts.find((p) => p.isDefault));

let order: number = submission.order;
for (const additional of submission.additional) {
Expand All @@ -353,7 +358,7 @@ export class SubmissionService {
newSubmission = await this.fileSubmissionService.duplicateSubmission(newSubmission);
const createdSubmission = await this.repository.save(newSubmission);
await Promise.all(
websitePartsThatNeedSplitting.map(p => {
websitePartsThatNeedSplitting.map((p) => {
p.submissionId = newSubmission._id;
p.postStatus = 'UNPOSTED';
return this.partService.createOrUpdateSubmissionPart(p, newSubmission.type);
Expand Down Expand Up @@ -397,7 +402,7 @@ export class SubmissionService {
// Duplicate parts
const parts = await this.partService.getPartsForSubmission(originalId, true);
await Promise.all(
parts.map(p => {
parts.map((p) => {
p.submissionId = duplicate._id;
p.postStatus = 'UNPOSTED';
return this.partService.createOrUpdateSubmissionPart(p, duplicate.type);
Expand All @@ -423,7 +428,7 @@ export class SubmissionService {
const submissions = (await this.getAll(movingSubmission.type)).sort(
(a, b) => a.order - b.order,
);
const fromSubmission = submissions.find(s => s._id === id);
const fromSubmission = submissions.find((s) => s._id === id);
fromSubmission.order = from < to ? to + 0.1 : to - 0.1;
await Promise.all(
submissions
Expand All @@ -444,10 +449,10 @@ export class SubmissionService {
record.order = index;
return record;
});
await Promise.all(ordered.map(record => this.repository.update(record)));
await Promise.all(ordered.map((record) => this.repository.update(record)));

const orderRecord: Record<string, number> = {};
Object.values(ordered).forEach(submission => {
Object.values(ordered).forEach((submission) => {
orderRecord[submission._id] = submission.order;
});
this.eventEmitter.emit(Events.SubmissionEvent.REORDER, orderRecord);
Expand All @@ -468,7 +473,7 @@ export class SubmissionService {
}

const mappedParts: Parts = {};
parts.forEach(part => (mappedParts[part.accountId] = part.asPlain())); // asPlain to expose the _id (a model might work better)
parts.forEach((part) => (mappedParts[part.accountId] = part.asPlain())); // asPlain to expose the _id (a model might work better)
return {
submission,
parts: mappedParts,
Expand Down Expand Up @@ -529,8 +534,8 @@ export class SubmissionService {
}
await this.repository.update(submissionToUpdate);

await Promise.all(removedParts.map(partId => this.partService.removeSubmissionPart(partId)));
await Promise.all(parts.map(p => this.setPart(submissionToUpdate, p)));
await Promise.all(removedParts.map((partId) => this.partService.removeSubmissionPart(partId)));
await Promise.all(parts.map((p) => this.setPart(submissionToUpdate, p)));

const packaged: SubmissionPackage<any> = await this.validate(submissionToUpdate);
this.eventEmitter.emit(Events.SubmissionEvent.UPDATED, [packaged]);
Expand All @@ -546,11 +551,11 @@ export class SubmissionService {
}

const allParts = await this.partService.getPartsForSubmission(submission._id, false);
const keepIds = submissionOverwrite.parts.map(p => p.accountId);
const removeParts = allParts.filter(p => !keepIds.includes(p.accountId));
const keepIds = submissionOverwrite.parts.map((p) => p.accountId);
const removeParts = allParts.filter((p) => !keepIds.includes(p.accountId));

await Promise.all(submissionOverwrite.parts.map(part => this.setPart(submission, part)));
await Promise.all(removeParts.map(p => this.partService.removeSubmissionPart(p._id)));
await Promise.all(submissionOverwrite.parts.map((part) => this.setPart(submission, part)));
await Promise.all(removeParts.map((p) => this.partService.removeSubmissionPart(p._id)));

const packaged: SubmissionPackage<any> = await this.validate(submission);
this.eventEmitter.emit(Events.SubmissionEvent.UPDATED, [packaged]);
Expand Down Expand Up @@ -788,7 +793,7 @@ export class SubmissionService {

if (submission.additional) {
const recordToUpdate: FileRecord = submission.additional.find(
r => r.location === record.location,
(r) => r.location === record.location,
);
if (recordToUpdate) {
recordToUpdate.ignoredAccounts = record.ignoredAccounts || [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class Telegram extends Website {
// Roundabout way to set username and save it after authentication
if (this.usernameMap[appId]) {
status.data = {
...data.data,
username: this.usernameMap[appId],
};
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postybirb-plus",
"version": "3.0.35",
"version": "3.0.36",
"description": "PostyBirb is an application that helps artists post art and other multimedia to multiple websites more quickly..",
"main": "index.js",
"scripts": {
Expand Down
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.35",
"version": "3.0.36",
"license": "BSD-3-Clause",
"private": true,
"Author": "Michael DiCarlo",
Expand Down
4 changes: 3 additions & 1 deletion ui/src/websites/telegram/TelegramLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export default class TelegramLogin extends React.Component<LoginDialogProps, Sta
<Input
className="w-full"
value={this.state.phoneNumber}
onChange={({ target }) => this.setState({ phoneNumber: target.value })}
onChange={({ target }) =>
this.setState({ phoneNumber: target.value.replace(/[^0-9+]/g, '') })
}
/>
</Form.Item>
<Form.Item>
Expand Down

0 comments on commit 0a5abc8

Please sign in to comment.