Spaces:
Paused
Paused
File size: 2,304 Bytes
b60b4f4 c3bdfc2 b60b4f4 c3bdfc2 b60b4f4 c3bdfc2 b60b4f4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
//!/usr/bin/env node
const Fastify = require('fastify');
const fs = require('fs');
const { chromium } = require('playwright-extra');
const stealth = require('puppeteer-extra-plugin-stealth')();
chromium.use(stealth);
const configFile = fs.readFileSync(__dirname + '/config.json', 'utf8');
const configData = JSON.parse(configFile);
const fastify = Fastify();
const PORT = 7860;
fastify.post('/search', async (request, reply) => {
const { searchText } = request.body;
const url = 'https://chat.deepseek.com';
const buttonSubmit = '.f6d670';
const textareaSearchBox = '#chat-input';
const textMessage = '.ds-markdown';
const profileButton = '.d65532b2';
const deleteAllButton = '.ds-dropdown-menu-option__label:has-text("Delete all chats")';
const confirmDeleteButton = '.ds-button:has-text("Confirm deletion")';
const totalLoopCount = 60;
const printIntervalTime = 1000;
const browser = await chromium.launch({ headless: true, timeout: 30000 });
const context = await browser.newContext({ userAgent: configData.userAgent });
await context.addCookies([{
'name': 'cf_clearance',
'value': configData.cfClearance,
'domain': '.deepseek.com',
'path': '/',
'httpOnly': true,
'secure': true
}]);
const page = await context.newPage();
await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.evaluate(userToken => {
localStorage.setItem('searchEnabled', 'true');
localStorage.setItem('userToken', `{"value":"${userToken}","__version":"0"}`);
}, configData.userToken);
await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.fill(textareaSearchBox, searchText);
await page.click(buttonSubmit);
let prevResult = '';
for (let i = 0; i < totalLoopCount; i++) {
await new Promise(resolve => setTimeout(resolve, printIntervalTime));
const result = await page.locator(textMessage).innerText();
if (prevResult === result && i !== totalLoopCount - 1) break;
prevResult = result;
}
await page.click(profileButton);
await page.click(deleteAllButton);
await page.click(confirmDeleteButton);
await browser.close();
return reply.send({ response: prevResult });
});
fastify.listen({ port: PORT }, (err, address) => {
if (err) throw err;
console.log(`Server running at ${address}`);
});
|