Skip to content

Commit

Permalink
fix clicknupload
Browse files Browse the repository at this point in the history
  • Loading branch information
mnsrulz committed Sep 1, 2024
1 parent 8f59c0e commit 54d7d20
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 50 deletions.
52 changes: 4 additions & 48 deletions src/libs/clicknUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import debug from 'debug';
const _debug = debug('nurl:ClicknUploadResolver');

import { BaseUrlResolver, ResolvedMediaItem } from "../BaseResolver.js";
import { simpleCaptcha } from '../utils/helper.js';

export class ClicknUploadResolver extends BaseUrlResolver {
constructor() {
Expand All @@ -15,7 +16,7 @@ export class ClicknUploadResolver extends BaseUrlResolver {
async resolveInner(_urlToResolve: string): Promise<ResolvedMediaItem | ResolvedMediaItem[]> {
const response = await this.gotInstance(_urlToResolve);
const response2 = await this.postHiddenForm(response.url, response.body, 0, false);
const parsedCode = this.parseCaptchaCode(response2.body);
const parsedCode = simpleCaptcha(response2.body, 'td[align=right] span');
const formToPost = this.getHiddenForm(response2.body, 0);

if (formToPost) {
Expand All @@ -30,15 +31,15 @@ export class ClicknUploadResolver extends BaseUrlResolver {
elapsedSecond=elapsedSecond+3;
}, 3000);

await this.wait(10000);

await this.wait(15000);
clearInterval(logTimer);

const response3 = await this.gotInstance.post(urlToPost, {
form: formToPost,
headers: {
Referer: urlToPost
},
throwHttpErrors: false,
followRedirect: false //it can raise some unhandled error which can potentially cause whole application shutdown.
});

Expand All @@ -55,49 +56,4 @@ export class ClicknUploadResolver extends BaseUrlResolver {
}
return [];
}

private parseCaptchaCode(html: string): string {
const result: { code: [{ codeValue: string, codePosition: number }] } = this.scrapeHtml(html, {
// code: "td[align=right]",
// codeValues: {
// listItem: 'td[align=right] span'
// },
code: {
listItem: 'td[align=right] span',
data: {
codeValue: {},
codePosition: {
attr: 'style',
convert: (x) => {
const rxResult = /padding-left:(\d*)px/.exec(x);
return rxResult && parseInt(rxResult[1]);
}
}
}
},
// tag: {
// listItem: 'td[align=right] span',
// data: {
// code: {
// selector: '',
// how: (i: cheerio.Selector) => {
// const vals = Object.values(i);
// const codeValue = vals['0']['children'][0]['data'];
// const styleAttribute = vals['0']['attribs']['style'];
// const rxResult = /padding-left:(\d*)px/.exec(styleAttribute);
// const position = rxResult && parseInt(rxResult[1]);
// return {
// codeValue, position
// };
// }
// }
// },
// }
});

return result.code
.sort((a, b) => a.codePosition - b.codePosition)
.map(x => x.codeValue)
.join('');
}
}
26 changes: 24 additions & 2 deletions src/tests/helper.tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { parseGoogleFileId, parseElementAttributes, parseAllLinks, isValidHttpUrl, getSecondLevelDomain } from '../utils/helper.js';
import { parseGoogleFileId, parseElementAttributes, parseAllLinks, isValidHttpUrl, getSecondLevelDomain, simpleCaptcha } from '../utils/helper.js';

const data = `
<html>
Expand Down Expand Up @@ -38,4 +38,26 @@ test('google drive parse links', t => {
t.is(parseGoogleFileId('https://drive.google.com/file/d/1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT/view'), '1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT');
t.is(parseGoogleFileId('https://drive.usercontent.google.com/download?export=download&id=1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT'), '1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT');
t.is(parseGoogleFileId('https://drives.othergoogle.com/file/d/1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT/view'), null);
});
});

test('parse simple captcha', t=>{
const html = `
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody><tr>
<td align="center">
<center>
<span id="countdown" style="visibility: hidden;">Wait <span class="seconds">1</span> Seconds</span>
<br><table><tbody><tr><td colspan="2"><b>Enter code below:</b></td></tr>
<tr>
<td align="right"><div style="width:80px;height:26px;font:bold 13px Arial;background:#ccc;text-align:left;direction:ltr;"><span style="position:absolute;padding-left:9px;padding-top:6px;">1</span><span style="position:absolute;padding-left:61px;padding-top:4px;">6</span><span style="position:absolute;padding-left:44px;padding-top:6px;">4</span><span style="position:absolute;padding-left:27px;padding-top:6px;">1</span></div></td>
<td align="left" valign="middle"><input type="text" name="code" class="captcha_code"></td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
`;

const code = simpleCaptcha(html, 'td[align=right] span') ;
t.is(code, '1146');
})

0 comments on commit 54d7d20

Please sign in to comment.