This commit is contained in:
2026-05-22 14:36:34 +08:00
parent 40f13989c2
commit 1336695068
11 changed files with 115 additions and 16 deletions

View File

@@ -50,9 +50,30 @@ export function openApplovinUpload(_context: vscode.ExtensionContext) {
});
}
const USER_AGENTS = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
];
function pickUserAgent(randomize: boolean): string {
if (!randomize) return USER_AGENTS[0];
return USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)];
}
function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function handleUpload(panel: vscode.WebviewPanel, filePaths: string[]) {
const cfg = vscode.workspace.getConfiguration('hplToolbox.applovin');
const cookie = (cfg.get<string>('cookie') || '').trim();
const delayMs = Math.max(0, cfg.get<number>('delayMs') ?? 1500);
const randomizeUA = cfg.get<boolean>('randomizeUserAgent') ?? true;
const paths = Array.isArray(filePaths) ? filePaths : [filePaths];
if (!paths.length) {
@@ -60,14 +81,17 @@ async function handleUpload(panel: vscode.WebviewPanel, filePaths: string[]) {
return;
}
const headers: Record<string, string> = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Origin': 'https://p.applov.in',
'Referer': 'https://p.applov.in/playablePreview?create=1&qr=1',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (HPL-Toolbox-VSCode)',
const buildHeaders = (): Record<string, string> => {
const headers: Record<string, string> = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Origin': 'https://p.applov.in',
'Referer': 'https://p.applov.in/playablePreview?create=1&qr=1',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': pickUserAgent(randomizeUA),
};
if (cookie) headers['Cookie'] = `__Host-APPLOVINID=${cookie}`;
return headers;
};
if (cookie) headers['Cookie'] = `__Host-APPLOVINID=${cookie}`;
const buildForm = (filePath: string): FormData => {
const buf = fs.readFileSync(filePath);
@@ -90,12 +114,17 @@ async function handleUpload(panel: vscode.WebviewPanel, filePaths: string[]) {
if (!filePath || !fs.existsSync(filePath)) { reportError('File missing'); continue; }
if (!/\.html?$/i.test(filePath)) { reportError('Must be .html'); continue; }
if (i > 0 && delayMs > 0) {
panel.webview.postMessage({ type: 'status', message: `[${idx}/${paths.length}] Waiting ${delayMs}ms before ${fileName}...` });
await sleep(delayMs);
}
panel.webview.postMessage({ type: 'status', message: `[${idx}/${paths.length}] Validating ${fileName}...` });
let res: Response;
try {
res = await fetch('https://p.applov.in/validateHTMLContent', {
method: 'POST', body: buildForm(filePath), headers,
method: 'POST', body: buildForm(filePath), headers: buildHeaders(),
});
} catch (err: any) { reportError('Network error (validate): ' + (err?.message || err)); continue; }
const validateText = await res.text();
@@ -110,7 +139,7 @@ async function handleUpload(panel: vscode.WebviewPanel, filePaths: string[]) {
try {
res = await fetch('https://p.applov.in/getCachedAdURL', {
method: 'POST', body: buildForm(filePath), headers,
method: 'POST', body: buildForm(filePath), headers: buildHeaders(),
});
} catch (err: any) { reportError('Network error (cache): ' + (err?.message || err)); continue; }
const cacheText = await res.text();