1 Star 0 Fork 1

xiaogg / ctfileGet

forked from Fuwenyue / ctfileGet 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ctget.js 3.71 KB
一键复制 编辑 原始数据 按行查看 历史
琴梨梨 提交于 2022-12-08 17:02 . fix backward compability
window.ctfile = {
version: () => { return "2.6.1" },
getByLink: (link, password, token, firstcallback) => {
return ctfile.getByID(link.substring(link.lastIndexOf("/") + 1, (link.lastIndexOf("?") == -1) ? undefined : link.lastIndexOf("?")), (link.lastIndexOf("p=") == -1) ? password : link.substring(link.lastIndexOf("p=") + 2), token, firstcallback);
},
getByID: async (fileid, password, token, firstcallback) => {
const origin = () => {
//兼容node.js
if (document && !(document.location.origin == 'file://')) {
return document.location.origin;
} else {
return "https://ctfile.qinlili.workers.dev";
}
};
const path = id => {
switch (id.split("-").length) {
case 2: {
return "file";
};
case 3:
default: {
return "f";
}
}
}
jsonText = JSON.parse(await (await fetch("https://webapi.ctfile.com/getfile.php?path=" + path(fileid) + "&f=" + fileid + "&passcode=" + password + "&token=" + token + "false&r=" + Math.random() + "&ref=" + origin(), {
"headers": {
"origin": origin(),
"referer": origin()
},
})).text());
if (jsonText.code == 200) {
if (firstcallback) {
firstcallback({
"name": jsonText.file.file_name,
"size": jsonText.file.file_size,
"time": jsonText.file.file_time,
})
};
if (jsonText.file.is_vip == 1) {
return {
"success": true,
"name": jsonText.file.file_name,
"size": jsonText.file.file_size,
"time": jsonText.file.file_time,
"link": jsonText.file.vip_dx_url
};
} else {
jsonText2 = JSON.parse(await (await fetch("https://webapi.ctfile.com/get_file_url.php?uid=" + jsonText.file.userid + "&fid=" + jsonText.file.file_id + "&file_chk=" + jsonText.file.file_chk + "&app=0&acheck=2&rd=" + Math.random(), {
"headers": {
"origin": origin(),
"referer": origin()
},
})).text());
if (jsonText2.code == 200) {
return {
"success": true,
"name": jsonText.file.file_name,
"size": jsonText.file.file_size,
"time": jsonText.file.file_time,
"link": jsonText2.downurl
};
} else {
if (jsonText2.code == 302) {
return {
"success": false,
"name": jsonText.file.file_name,
"size": jsonText.file.file_size,
"time": jsonText.file.file_time,
"errormsg": "需要登录!"
};
} else {
return {
"success": false,
"name": jsonText.file.file_name,
"size": jsonText.file.file_size,
"time": jsonText.file.file_time,
"errormsg": jsonText2.message
};
}
}
}
} else {
return {
"success": false,
"errormsg": jsonText.file.message
};
}
}
}
1
https://gitee.com/web/ctfileGet.git
git@gitee.com:web/ctfileGet.git
web
ctfileGet
ctfileGet
main

搜索帮助