-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathftp[盘].js
More file actions
143 lines (140 loc) · 4.55 KB
/
ftp[盘].js
File metadata and controls
143 lines (140 loc) · 4.55 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
@header({
searchable: 0,
filterable: 0,
quickSearch: 0,
title: 'ftp[盘]',
'类型': '影视',
lang: 'ds'
})
*/
var rule = {
类型: '影视',
title: 'ftp[盘]',
host: '',
url: '',
searchUrl: '',
headers: {'User-Agent': 'UC_UA'},
searchable: 0,
quickSearch: 0,
filterable: 0,
double: true,
play_parse: true,
limit: 6,
class_name: '',
class_url: '',
pans: [],
hostJs: async function () {
let {HOST} = this;
return rule.params;
},
预处理: async function () {
log('rule.host:', rule.host);
let data = await request(rule.host);
try {
rule.pans = JSON.parse(data);
} catch (e) {
log('获取ftp配置错误:', e.message);
}
},
class_parse: async function () {
let {input, pdfa, pdfh, pd} = this;
let classList = [];
rule.pans.forEach(pan => {
classList.push({
type_name: pan.name,
type_id: pan.id || pan.baseURL,
})
})
return {class: classList}
},
lazy: async function () {
let {input, ftpProxyUrl} = this;
// log('input:', input);
// log('ftpProxyUrl:', ftpProxyUrl);
return {
parse: 0,
url: ftpProxyUrl + input
}
},
推荐: async function () {
let {input, pdfa, pdfh, pd} = this;
let d = [];
return setResult(d)
},
一级: async function (tid, pg, filter, extend) {
let d = [];
if (Number(pg) > 1) {
return d
}
const _id = tid.split('$')[0];
const _tid = tid.split('$')[1] || '/';
let pan = rule.pans.find(it => it.id === _id || it.baseURL === _id);
if (pan) {
const ftp = createFTPClient(setAnonymous(pan));
const isConnected = await ftp.testConnection();
if (isConnected) {
const rootItems = await ftp.listDirectory(_tid);
console.log('Root directory contents:');
rootItems.forEach(item => {
log(item);
// const type = item.isDirectory ? 'folder' : undefined;
const type = item.isDirectory ? 'folder' : 'file';
const size = item.isDirectory ? '' : `${item.size} bytes`;
const content = item.isDirectory ? '' : `${item.contentType}`;
// console.log(` ${type} ${item.name}${size}`);
d.push({
vod_name: item.name,
vod_remarks: size,
vod_tag: type,
vod_id: _id + '$' + item.path,
vod_content: content,
})
});
}
}
return d
},
二级: async function (ids) {
// log('ids:',ids);
let VOD = {};
let tid = ids[0];
const _id = tid.split('$')[0];
const _tid = tid.split('$')[1] || '/';
let pan = rule.pans.find(it => it.id === _id || it.baseURL === _id);
if (pan) {
const ftp = createFTPClient(setAnonymous(pan));
const isConnected = await ftp.testConnection();
if (isConnected) {
const itemInfo = await ftp.getInfo(_tid);
// log('itemInfo:');
// log(itemInfo);
VOD.vod_name = itemInfo.name;
VOD.vod_content = itemInfo.path + '\n' + '上次修改时间:' + itemInfo.lastModified;
VOD.vod_remarks = itemInfo.size;
VOD.vod_director = itemInfo.etag;
VOD.vod_actor = itemInfo.contentType;
VOD.vod_pic = '/default-poster.svg';
VOD.vod_play_from = '在线观看';
const proxy_params_url = `file?config=${encodeURIComponent(JSON.stringify(pan))}&path=${encodeURIComponent(_tid)}`;
VOD.vod_play_url = itemInfo.name + '$' + proxy_params_url;
}
}
return VOD
},
搜索: async function () {
let {input, pdfa, pdfh, pd} = this;
let d = [];
return setResult(d)
}
}
function setAnonymous(ftpConfig) {
// 支持匿名 FTP 访问
if (!ftpConfig.username || ftpConfig.username === 'your-username' || ftpConfig.username === '') {
ftpConfig.username = 'anonymous';
}
if (!ftpConfig.password || ftpConfig.password === 'your-password' || ftpConfig.password === '') {
ftpConfig.password = 'anonymous@example.com';
}
return ftpConfig;
}