Skip to content

Commit

Permalink
Merge pull request #352 from mvdicarlo/develop
Browse files Browse the repository at this point in the history
v3.1.46
  • Loading branch information
mvdicarlo authored Aug 9, 2024
2 parents 299dc10 + c651b9a commit c11a624
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 64 deletions.
40 changes: 40 additions & 0 deletions electron-app/hasher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
const { version } = require('./package.json');
const { parse, stringify } = require('yaml');

const BASE_PATH = path.join(__dirname, 'release');
const SETUP_PATH = path.join(BASE_PATH, `postybirb-plus-setup-${version}.exe`);
const YAML_PATH = path.join(BASE_PATH, `latest.yml`);

function hashFile(file, algorithm = 'sha512', encoding = 'base64', options) {
return new Promise((resolve, reject) => {
const hash = crypto.createHash(algorithm);
hash.on('error', reject).setEncoding(encoding);
fs.createReadStream(
file,
Object.assign({}, options, {
highWaterMark: 1024 * 1024,
/* better to use more memory but hash faster */
}),
)
.on('error', reject)
.on('end', () => {
hash.end();
resolve(hash.read());
})
.pipe(hash, {
end: false,
});
});
}

hashFile(SETUP_PATH).then(hash => {
console.log(hash);
const yaml = parse(fs.readFileSync(YAML_PATH, 'utf8'));
yaml.sha512 = hash;
yaml.files[0].sha512 = hash;
console.log(stringify(yaml));
fs.writeFileSync(YAML_PATH, stringify(yaml));
});
58 changes: 31 additions & 27 deletions electron-app/package-lock.json

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

8 changes: 6 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.1.45",
"version": "3.1.46",
"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 @@ -18,6 +18,7 @@
"build:linux": "electron-builder -l",
"build:osx": "electron-builder -m",
"build:windows": "electron-builder -w",
"build:rehash": "node hasher.js",
"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",
Expand Down Expand Up @@ -108,7 +109,8 @@
"ts-jest": "^26.5.6",
"ts-loader": "^8.3.0",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.11.0"
"tsconfig-paths": "^3.11.0",
"yaml": "^2.5.0"
},
"build": {
"appId": "com.lemonynade.postybirb.plus",
Expand Down Expand Up @@ -144,9 +146,11 @@
]
},
"nsis": {
"artifactName": "postybirb-plus-setup-${version}.${ext}",
"deleteAppDataOnUninstall": true
},
"win": {
"artifactName": "postybirb-plus-${version}.${ext}",
"publisherName": [
"Michael DiCarlo"
],
Expand Down
68 changes: 35 additions & 33 deletions electron-app/src/server/websites/deviant-art/deviant-art.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ValidationParts } from 'src/server/submission/validator/interfaces/vali
import BrowserWindowUtil from 'src/server/utils/browser-window.util';
import FileSize from 'src/server/utils/filesize.util';
import FormContent from 'src/server/utils/form-content.util';
import { HttpExperimental } from 'src/server/utils/http-experimental';
import WebsiteValidator from 'src/server/utils/website-validator.util';
import { GenericAccountProp } from '../generic/generic-account-props.enum';
import { LoginResponse } from '../interfaces/login-response.interface';
Expand Down Expand Up @@ -66,17 +67,13 @@ export class DeviantArt extends Website {

async checkLoginStatus(data: UserAccountEntity): Promise<LoginResponse> {
const status: LoginResponse = { loggedIn: false, username: null };
const res = await Http.get<string>(this.BASE_URL, data._id);
if (!res.body.includes('https://www.deviantart.com/users/login')) {
const res = await HttpExperimental.get<string>(this.BASE_URL, { partition: data._id });
const cookies = await Http.getWebsiteCookies(data._id, this.BASE_URL);
const userInfoCookie = cookies.find(c => c.name === 'userinfo');
if (userInfoCookie) {
status.loggedIn = true;
status.username = res.body.match(/data-username="(\w+)"/)[1];

const csrf = res.body.match(/window.__CSRF_TOKEN__ = '(.*)'/)?.[1];
if (csrf) {
await this.getFolders(data._id, status.username);
} else {
this.logger.warn('Could not find CSRF token for DeviantArt to retrieve folders.');
}
status.username = JSON.parse(decodeURIComponent(userInfoCookie.value).split(';')[1]).username;
await this.getFolders(data._id, status.username);
}

return status;
Expand All @@ -85,16 +82,13 @@ export class DeviantArt extends Website {
private async getFolders(profileId: string, username: string) {
try {
const csrf = await this.getCSRF(profileId);
const res = await Http.get<{ results: DeviantArtFolder[] }>(
const res = await HttpExperimental.get<{ results: DeviantArtFolder[] }>(
`${
this.BASE_URL
}/_puppy/dashared/gallection/folders?offset=0&limit=250&type=gallery&with_all_folder=true&with_permissions=true&username=${encodeURIComponent(
username,
)}&da_minor_version=20230710&csrf_token=${csrf}`,
profileId,
{
requestOptions: { json: true },
},
{ partition: profileId },
);
const folders: Folder[] = [];
res.body.results.forEach((f: DeviantArtFolder) => {
Expand Down Expand Up @@ -126,7 +120,7 @@ export class DeviantArt extends Website {
}

private async getCSRF(profileId: string) {
const url = await Http.get<string>(this.BASE_URL, profileId);
const url = await HttpExperimental.get<string>(this.BASE_URL, { partition: profileId });
return url.body.match(/window.__CSRF_TOKEN__ = '(.*)'/)?.[1];
}

Expand All @@ -135,15 +129,16 @@ export class DeviantArt extends Website {
data: FilePostData<DeviantArtFileOptions>,
accountData: DeviantArtAccountData,
): Promise<PostResponse> {
const fileUpload = await Http.post<{
const fileUpload = await HttpExperimental.post<{
deviationId: number;
status: string;
stashId: number;
privateId: number;
size: number;
cursor: string;
title: string;
}>(`${this.BASE_URL}/_puppy/dashared/deviation/submit/upload/deviation`, data.part.accountId, {
}>(`${this.BASE_URL}/_puppy/dashared/deviation/submit/upload/deviation`, {
partition: data.part.accountId,
type: 'multipart',
data: {
upload_file: data.primary.file,
Expand All @@ -152,7 +147,6 @@ export class DeviantArt extends Website {
da_minor_version: '20230710',
csrf_token: await this.getCSRF(data.part.accountId),
},
requestOptions: { json: true },
});

if (fileUpload.body.status !== 'success') {
Expand Down Expand Up @@ -207,7 +201,7 @@ export class DeviantArt extends Website {
subject_tags: '_empty',
tags: this.formatTags(data.tags),
tierids: '_empty',
title: data.title,
title: this.truncateTitle(data.title),
csrf_token: await this.getCSRF(data.part.accountId),
};

Expand Down Expand Up @@ -247,18 +241,18 @@ export class DeviantArt extends Website {
);
}

const publish = await Http.post<{
const publish = await HttpExperimental.post<{
status: string;
url: string;
deviationId: number;
}>(`${this.BASE_URL}/_puppy/dashared/deviation/publish`, data.part.accountId, {
}>(`${this.BASE_URL}/_puppy/dashared/deviation/publish`, {
partition: data.part.accountId,
type: 'json',
data: {
stashid: fileUpload.body.deviationId,
da_minor_version: 20230710,
csrf_token: await this.getCSRF(data.part.accountId),
},
requestOptions: { json: true },
});

if (publish.body.status !== 'success') {
Expand Down Expand Up @@ -299,15 +293,15 @@ export class DeviantArt extends Website {
title: data.title,
};

const create = await Http.post<{
const create = await HttpExperimental.post<{
deviation: {
deviationId: number;
url: string;
};
}>(`${this.BASE_URL}/_napi/shared_api/journal/create`, data.part.accountId, {
}>(`${this.BASE_URL}/_napi/shared_api/journal/create`, {
partition: data.part.accountId,
type: 'json',
data: form,
requestOptions: { json: true },
});

if (!create.body.deviation?.deviationId) {
Expand All @@ -319,20 +313,20 @@ export class DeviantArt extends Website {
);
}

const publish = await Http.post<{
const publish = await HttpExperimental.post<{
deviation: {
deviationId: number;
url: string;
};
}>(`${this.BASE_URL}/_puppy/dashared/journal/publish`, data.part.accountId, {
}>(`${this.BASE_URL}/_puppy/dashared/journal/publish`, {
partition: data.part.accountId,
type: 'json',
data: {
deviationid: create.body.deviation.deviationId,
da_minor_version: 20230710,
csrf_token: await this.getCSRF(data.part.accountId),
featured: true,
},
requestOptions: { json: true },
});

if (!publish.body.deviation?.deviationId) {
Expand All @@ -347,6 +341,12 @@ export class DeviantArt extends Website {
return this.createPostResponse({ source: publish.body.deviation.url });
}

private titleLimit = 50;
private truncateTitle(title: string) {
const newTitle = title.substring(0, this.titleLimit);
return { title: newTitle, exceedsLimit: newTitle !== title };
}

validateFileSubmission(
submission: FileSubmission,
submissionPart: SubmissionPart<DeviantArtFileOptions>,
Expand All @@ -356,9 +356,11 @@ export class DeviantArt extends Website {
const warnings: string[] = [];
const isAutoscaling: boolean = submissionPart.data.autoScale;

const title = submissionPart.data.title || defaultPart.data.title || submission.title;
if (title.length > 50) {
warnings.push(`Title will be truncated to 50 characters: ${title.substring(0, 50)}`);
const { title, exceedsLimit } = this.truncateTitle(
submissionPart.data.title || defaultPart.data.title || submission.title,
);
if (exceedsLimit) {
warnings.push(`Title will be truncated to ${this.titleLimit} characters: ${title}`);
}

if (submissionPart.data.folders && submissionPart.data.folders.length) {
Expand All @@ -369,7 +371,7 @@ export class DeviantArt extends Website {
);
submissionPart.data.folders.forEach(f => {
if (!WebsiteValidator.folderIdExists(f, folders)) {
problems.push(`Folder (${f}) not found.`);
warnings.push(`Folder (${f}) not found.`);
}
});
}
Expand Down
Loading

0 comments on commit c11a624

Please sign in to comment.