Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
//!/usr/bin/env node
|
2 |
-
|
3 |
const Fastify = require('fastify');
|
4 |
const fs = require('fs');
|
5 |
const { chromium } = require('playwright-extra');
|
@@ -8,6 +6,8 @@ chromium.use(stealth);
|
|
8 |
|
9 |
const configFile = fs.readFileSync(__dirname + '/config.json', 'utf8');
|
10 |
const configData = JSON.parse(configFile);
|
|
|
|
|
11 |
const fastify = Fastify();
|
12 |
const PORT = 7860;
|
13 |
|
@@ -16,53 +16,89 @@ fastify.get('/', async (request, reply) => {
|
|
16 |
});
|
17 |
|
18 |
fastify.post('/search', async (request, reply) => {
|
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 |
-
await page.click(confirmDeleteButton);
|
63 |
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
});
|
67 |
|
68 |
fastify.listen({ port: PORT, host: '0.0.0.0' }, (err, address) => {
|
|
|
|
|
|
|
1 |
const Fastify = require('fastify');
|
2 |
const fs = require('fs');
|
3 |
const { chromium } = require('playwright-extra');
|
|
|
6 |
|
7 |
const configFile = fs.readFileSync(__dirname + '/config.json', 'utf8');
|
8 |
const configData = JSON.parse(configFile);
|
9 |
+
console.log('Loaded config data:', configData);
|
10 |
+
|
11 |
const fastify = Fastify();
|
12 |
const PORT = 7860;
|
13 |
|
|
|
16 |
});
|
17 |
|
18 |
fastify.post('/search', async (request, reply) => {
|
19 |
+
try {
|
20 |
+
const { searchText } = request.body;
|
21 |
+
console.log('Received searchText:', searchText);
|
22 |
+
|
23 |
+
const url = 'https://chat.deepseek.com';
|
24 |
+
const buttonSubmit = '.f6d670';
|
25 |
+
const textareaSearchBox = '#chat-input';
|
26 |
+
const textMessage = '.ds-markdown';
|
27 |
+
const profileButton = '.d65532b2';
|
28 |
+
const deleteAllButton = '.ds-dropdown-menu-option__label:has-text("Delete all chats")';
|
29 |
+
const confirmDeleteButton = '.ds-button:has-text("Confirm deletion")';
|
30 |
+
const totalLoopCount = 60;
|
31 |
+
const printIntervalTime = 1000;
|
32 |
+
|
33 |
+
const browser = await chromium.launch({ headless: true, timeout: 30000 });
|
34 |
+
console.log('Browser launched');
|
35 |
+
|
36 |
+
const context = await browser.newContext({ userAgent: configData.userAgent });
|
37 |
+
console.log('Context created with userAgent:', configData.userAgent);
|
38 |
+
|
39 |
+
await context.addCookies([{
|
40 |
+
name: 'cf_clearance',
|
41 |
+
value: configData.cfClearance,
|
42 |
+
domain: '.deepseek.com',
|
43 |
+
path: '/',
|
44 |
+
httpOnly: true,
|
45 |
+
secure: true
|
46 |
+
}]);
|
47 |
+
console.log('Cookies added');
|
48 |
+
|
49 |
+
const page = await context.newPage();
|
50 |
+
console.log('New page created');
|
51 |
+
|
52 |
+
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
53 |
+
console.log('Navigated to:', url);
|
54 |
+
|
55 |
+
await page.evaluate(userToken => {
|
56 |
+
localStorage.setItem('searchEnabled', 'false');
|
57 |
+
localStorage.setItem('userToken', `{"value":"${userToken}","__version":"0"}`);
|
58 |
+
console.log('Local storage set for userToken');
|
59 |
+
}, configData.userToken);
|
60 |
|
61 |
+
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
62 |
+
console.log('Page reloaded after setting local storage');
|
|
|
63 |
|
64 |
+
await page.fill(textareaSearchBox, searchText);
|
65 |
+
console.log('Filled search text into textarea');
|
66 |
+
|
67 |
+
await page.click(buttonSubmit);
|
68 |
+
console.log('Clicked submit button');
|
69 |
+
|
70 |
+
let prevResult = '';
|
71 |
+
for (let i = 0; i < totalLoopCount; i++) {
|
72 |
+
console.log(`Iteration ${i + 1}: waiting for ${printIntervalTime}ms`);
|
73 |
+
await new Promise(resolve => setTimeout(resolve, printIntervalTime));
|
74 |
+
|
75 |
+
const result = await page.locator(textMessage).innerText();
|
76 |
+
console.log(`Iteration ${i + 1}: result:`, result);
|
77 |
+
|
78 |
+
if (prevResult === result && i !== totalLoopCount - 1) {
|
79 |
+
console.log('No change in result, breaking the loop.');
|
80 |
+
break;
|
81 |
+
}
|
82 |
+
prevResult = result;
|
83 |
+
}
|
84 |
+
|
85 |
+
await page.click(profileButton);
|
86 |
+
console.log('Clicked profile button');
|
87 |
+
|
88 |
+
await page.click(deleteAllButton);
|
89 |
+
console.log('Clicked delete all button');
|
90 |
+
|
91 |
+
await page.click(confirmDeleteButton);
|
92 |
+
console.log('Confirmed deletion');
|
93 |
+
|
94 |
+
await browser.close();
|
95 |
+
console.log('Browser closed');
|
96 |
+
|
97 |
+
return reply.send({ response: prevResult });
|
98 |
+
} catch (error) {
|
99 |
+
console.error('Error during search operation:', error);
|
100 |
+
return reply.status(500).send({ error: 'Internal Server Error' });
|
101 |
+
}
|
102 |
});
|
103 |
|
104 |
fastify.listen({ port: PORT, host: '0.0.0.0' }, (err, address) => {
|