From 2b4c3d38270deab4c2c2e8bff48e48f6fb59f93a Mon Sep 17 00:00:00 2001 From: Michael DiCarlo Date: Fri, 13 Aug 2021 10:13:53 -0400 Subject: [PATCH] FurAffinity updates --- .../fur-affinity/fur-affinity.service.ts | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/app/websites/website-services/fur-affinity/fur-affinity.service.ts b/src/app/websites/website-services/fur-affinity/fur-affinity.service.ts index 304870f47..72023428c 100644 --- a/src/app/websites/website-services/fur-affinity/fur-affinity.service.ts +++ b/src/app/websites/website-services/fur-affinity/fur-affinity.service.ts @@ -293,6 +293,16 @@ export class FurAffinity extends BaseWebsiteService implements WebsiteService { } } + private processForError(body: string): string | undefined { + if (body.includes('redirect-message')) { + const body$ = $.parseHTML(body); + const msg = $(body$).find('.redirect-message').first().text(); + return msg; + } + + return undefined; + } + private async postSubmission( submission: Submission, postData: SubmissionPostData @@ -307,13 +317,10 @@ export class FurAffinity extends BaseWebsiteService implements WebsiteService { ); const part1Body = part1Response.body; - if (part1Body.includes('Flood protection')) { - return Promise.reject( - this.createPostResponse( - 'Encountered flood protection', - `Flood Protection\n\n${part1Body.body}` - ) - ); + let err = this.processForError(part1Body); + + if (err) { + return Promise.reject(this.createPostResponse(err, part1Body)); } const part2Data = { @@ -339,12 +346,10 @@ export class FurAffinity extends BaseWebsiteService implements WebsiteService { return Promise.reject(this.createPostResponse('Unknown error', uploadResponse.error)); } else { const uploadBody = uploadResponse.success.body; - if (uploadBody.includes('Flood protection')) { - return Promise.reject(this.createPostResponse('Encountered flood protection', {})); - } + err = this.processForError(uploadBody); - if (uploadBody.includes('pageid-error') || !uploadBody.includes('pageid-submit-finalize')) { - return Promise.reject(this.createPostResponse('Unknown error', uploadBody)); + if (err) { + return Promise.reject(this.createPostResponse(err, uploadBody)); } const options = postData.options || {}; @@ -362,8 +367,7 @@ export class FurAffinity extends BaseWebsiteService implements WebsiteService { }; if (postData.typeOfSubmission !== TypeOfSubmission.ART) { - delete finalizeData.cat; - finalizeData.cat_duplicate = this.getContentCategory(postData.typeOfSubmission); + finalizeData.cat = this.getContentCategory(postData.typeOfSubmission); } if (options.disableComments) finalizeData.lock_comments = 'on'; @@ -389,19 +393,13 @@ export class FurAffinity extends BaseWebsiteService implements WebsiteService { const body = postResponse.success.body; if (!postResponse.success.response.request.uri.href.includes('?upload-successful')) { - if (body.includes('CAPTCHA verification error')) { - return Promise.reject( - this.createPostResponse('You must have 10+ posts on your account first', body) - ); - } - - if (body.includes('pageid-submit-finalize')) { - return Promise.reject(this.createPostResponse('Unknown error', body)); - } - - if (postResponse.success.response.request.uri.href.includes('/submit')) { - return Promise.reject(this.createPostResponse('Something went wrong', body)); + err = this.processForError(body); + + if (err) { + return Promise.reject(this.createPostResponse(err, body)); } + + return Promise.reject(this.createPostResponse('Unknown error', body)); } try { @@ -423,7 +421,10 @@ export class FurAffinity extends BaseWebsiteService implements WebsiteService { console.error(e); } finally { const res = this.createPostResponse(null); - res.srcURL = postResponse.success.response.request.uri.href.replace('?upload-successful', ''); + res.srcURL = postResponse.success.response.request.uri.href.replace( + '?upload-successful', + '' + ); return res; } }