Skip to content

Commit

Permalink
Merge pull request #74 from mvdicarlo/develop
Browse files Browse the repository at this point in the history
v3.0.43
  • Loading branch information
mvdicarlo authored Jan 26, 2022
2 parents be85232 + e23294c commit d2edb41
Show file tree
Hide file tree
Showing 22 changed files with 663 additions and 51 deletions.
2 changes: 2 additions & 0 deletions commons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export * from './interfaces/websites/tumblr/tumblr.file.options.interface';
export * from './interfaces/websites/tumblr/tumblr.notification.options.interface';
export * from './interfaces/websites/username-shortcut.interface';
export * from './interfaces/websites/weasyl/weasyl.file.options.interface';
export * from './interfaces/websites/itaku/itaku.file.options.interface';
export * from './interfaces/websites/itaku/itaku.notification.options.interface';
export * from './interfaces/websites/telegram/telegram.account.interface';
export * from './interfaces/websites/telegram/telegram.file.options.interface';
export * from './interfaces/websites/telegram/telegram.notification.options.interface';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DefaultFileOptions } from '../../submission/default-options.interface';

export interface ItakuFileOptions extends DefaultFileOptions {
folders: string[];
visibility: string;
shareOnFeed: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DefaultOptions } from '../../submission/default-options.interface';

export interface ItakuNotificationOptions extends DefaultOptions {
folders: string[];
visibility: string;
}
27 changes: 27 additions & 0 deletions commons/src/websites/itaku/itaku.file.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Expose } from 'class-transformer';
import { IsArray, IsBoolean, IsOptional, IsString } from 'class-validator';
import { DefaultFileOptions } from '../../interfaces/submission/default-options.interface';
import { ItakuFileOptions } from '../../interfaces/websites/itaku/itaku.file.options.interface';
import { DefaultValue } from '../../models/decorators/default-value.decorator';
import { DefaultFileOptionsEntity } from '../../models/default-file-options.entity';

export class ItakuFileOptionsEntity extends DefaultFileOptionsEntity implements ItakuFileOptions {
@Expose()
@IsArray()
@DefaultValue([])
folders!: string[];

@Expose()
@IsString()
@DefaultValue('PUBLIC')
visibility!: string;

@Expose()
@IsBoolean()
@DefaultValue(true)
shareOnFeed!: boolean;

constructor(entity?: Partial<ItakuFileOptions>) {
super(entity as DefaultFileOptions);
}
}
23 changes: 23 additions & 0 deletions commons/src/websites/itaku/itaku.notification.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Expose } from 'class-transformer';
import { IsArray, IsString } 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';
import { DefaultOptionsEntity } from '../../models/default-options.entity';

export class ItakuNotificationOptionsEntity extends DefaultOptionsEntity
implements ItakuNotificationOptions {
@Expose()
@IsArray()
@DefaultValue([])
folders!: string[];

@Expose()
@IsString()
@DefaultValue('PUBLIC')
visibility!: string;

constructor(entity?: Partial<ItakuNotificationOptions>) {
super(entity as DefaultOptions);
}
}
7 changes: 7 additions & 0 deletions commons/src/websites/itaku/itaku.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ItakuFileOptionsEntity } from './itaku.file.options';
import { ItakuNotificationOptionsEntity } from './itaku.notification.options';

export class Itaku {
static readonly FileOptions = ItakuFileOptionsEntity;
static readonly NotificationOptions = ItakuNotificationOptionsEntity;
}
1 change: 1 addition & 0 deletions commons/src/websites/websites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from './subscribe-star/subscribe-star.options';
export * from './telegram/telegram.options';
export * from './tumblr/tumblr.options';
export * from './weasyl/weasyl.options';
export * from './itaku/itaku.options';
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.42",
"version": "3.0.43",
"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
80 changes: 43 additions & 37 deletions electron-app/src/server/http/http.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,37 +204,40 @@ export default class Http {
if (typeof body === 'string' && body.includes('resolve_captcha')) {
if (options.type === 'multipart') {
const win = new BrowserWindow({
show: true,
show: false,
webPreferences: {
partition: `persist:${partitionId}`,
enableRemoteModule: false,
},
});

const form = new FormData();
Object.entries(options.data).forEach(([key, value]: [string, any]) => {
if (value.options && value.value) {
form.append(key, value.value, value.options);
} else if (Array.isArray(value)) {
form.append(key, JSON.stringify(value));
} else {
form.append(key, value);
}
});

const opts: LoadURLOptions = {
postData: [
{
type: 'rawData',
bytes: form.getBuffer(),
},
],
extraHeaders: [
`Content-Type: ${form.getHeaders()['content-type']}`,
...Object.entries(options.headers || {}).map(([key, value]) => `${key}: ${value}`),
].join('\n'),
};
try {
const form = new FormData();
Object.entries(options.data).forEach(([key, value]: [string, any]) => {
if (value.options && value.value) {
form.append(key, value.value, value.options);
} else if (Array.isArray(value)) {
form.append(key, JSON.stringify(value));
} else {
form.append(key, value);
}
});

const opts: LoadURLOptions = {
postData: [
{
type: 'rawData',
bytes: form.getBuffer(),
},
],
extraHeaders: [
`Content-Type: ${form.getHeaders()['content-type']}`,
...Object.entries(options.headers || {}).map(
([key, value]) => `${key}: ${value}`,
),
].join('\n'),
};

await win.loadURL(uri, opts);
const result = await win.webContents.executeJavaScript('document.body.innerText');
let data = null;
Expand All @@ -253,26 +256,29 @@ export default class Http {
}
} else if (options.type === 'json') {
const win = new BrowserWindow({
show: true,
show: false,
webPreferences: {
partition: `persist:${partitionId}`,
enableRemoteModule: false,
},
});

const opts: LoadURLOptions = {
postData: [
{
type: 'rawData',
bytes: Buffer.from(JSON.stringify(options.data)),
},
],
extraHeaders: [
`Content-Type: application/json`,
...Object.entries(options.headers || {}).map(([key, value]) => `${key}: ${value}`),
].join('\n'),
};
try {
const opts: LoadURLOptions = {
postData: [
{
type: 'rawData',
bytes: Buffer.from(JSON.stringify(options.data)),
},
],
extraHeaders: [
`Content-Type: application/json`,
...Object.entries(options.headers || {}).map(
([key, value]) => `${key}: ${value}`,
),
].join('\n'),
};

await win.loadURL(uri, opts);
const result = await win.webContents.executeJavaScript('document.body.innerText');
let data = null;
Expand Down
28 changes: 23 additions & 5 deletions electron-app/src/server/utils/browser-window.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ export default class BrowserWindowUtil {
},
});

await bw.loadURL(url);
try {
await bw.loadURL(url);
} catch (err) {
bw.destroy();
throw err;
}

return bw;
}

Expand All @@ -23,9 +29,12 @@ export default class BrowserWindowUtil {
}
return await bw.webContents.executeJavaScript('JSON.parse(JSON.stringify(localStorage))');
} catch (err) {
bw.destroy();
throw err;
} finally {
bw.destroy();
if (!bw.isDestroyed()) {
bw.destroy();
}
}
}

Expand All @@ -42,9 +51,12 @@ export default class BrowserWindowUtil {
})).reduce((obj, [k, v]) => ({...obj, [k]: v}), {})))`,
);
} catch (err) {
bw.destroy();
throw err;
} finally {
bw.destroy();
if (!bw.isDestroyed()) {
bw.destroy();
}
}
}

Expand Down Expand Up @@ -76,9 +88,12 @@ export default class BrowserWindowUtil {
const page = await bw.webContents.executeJavaScript(script);
return page;
} catch (err) {
bw.destroy();
throw err;
} finally {
bw.destroy();
if (!bw.isDestroyed()) {
bw.destroy();
}
}
}

Expand All @@ -103,9 +118,12 @@ export default class BrowserWindowUtil {
});
return await bw.webContents.executeJavaScript('document.body.innerText');
} catch (err) {
bw.destroy();
throw err;
} finally {
bw.destroy();
if (!bw.isDestroyed()) {
bw.destroy();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Artconomy extends Website {
usernameShortcuts: UsernameShortcut[] = [
{
key: 'ac',
url: 'https://artconomy.com/$1',
url: 'https://artconomy.com/profile/$1/about',
},
];

Expand Down
18 changes: 18 additions & 0 deletions electron-app/src/server/websites/itaku/itaku.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ItakuController } from './itaku.controller';

describe('ItakuController', () => {
let controller: ItakuController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ItakuController],
}).compile();

controller = module.get<ItakuController>(ItakuController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
10 changes: 10 additions & 0 deletions electron-app/src/server/websites/itaku/itaku.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Controller } from '@nestjs/common';
import { GenericWebsiteController } from '../generic/generic.controller';
import { Itaku } from './itaku.service';

@Controller('itaku')
export class ItakuController extends GenericWebsiteController {
constructor(readonly service: Itaku) {
super(service);
}
}
10 changes: 10 additions & 0 deletions electron-app/src/server/websites/itaku/itaku.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { Itaku } from './itaku.service';
import { ItakuController } from './itaku.controller';

@Module({
providers: [Itaku],
controllers: [ItakuController],
exports: [Itaku],
})
export class ItakuModule {}
Loading

0 comments on commit d2edb41

Please sign in to comment.