-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (59 loc) · 1.96 KB
/
Copy pathindex.js
File metadata and controls
59 lines (59 loc) · 1.96 KB
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
gopeed.events.onResolve(async (ctx) => {
const url = ctx.req.url;
try {
const response = await fetch(url, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
}
});
const html = await response.text();
// Ищем прямую ссылку на скачивание
let match = html.match(/https:\/\/download\d+\.mediafire\.com\/[^"'\s]+/);
if (!match) {
// Fallback: искать в href download
match = html.match(/href="([^"]*download[^"]*)"/i);
if (match && match[1].startsWith('http')) {
match = [match[1]];
} else {
match = null;
}
}
if (match) {
const directUrl = match[0];
// Извлекаем имя файла из title
const titleMatch = html.match(/<title>([^<]+)<\/title>/i);
let name = 'mediafire_file';
if (titleMatch) {
name = titleMatch[1].trim().replace(' | MediaFire', '').replace(/[^a-zA-Z0-9._-]/g, '_');
}
// Получаем размер файла
let size = 0;
try {
const headResponse = await fetch(directUrl, { method: 'HEAD' });
const contentLength = headResponse.headers.get('content-length');
if (contentLength) {
size = parseInt(contentLength, 10);
}
} catch (e) {
gopeed.logger.warn('Could not get file size: ' + e.message);
}
ctx.res = {
name: name,
files: [
{
name: name,
size: size,
req: {
url: directUrl,
},
},
],
};
} else {
gopeed.logger.warn('Direct download link not found for: ' + url);
// Fallback: не устанавливать ctx.res, Gopeed обработает как обычную ссылку
}
} catch (error) {
gopeed.logger.error('Error resolving MediaFire link: ' + error.message);
}
});