tvbox/0130/道长JS/cat/alist_open.js

1 line
5.7 KiB
JavaScript
Raw Normal View History

2024-02-12 02:37:55 +02:00
import{_}from"assets://js/lib/cat.js";import{findBestLCS}from"./lib/similarity.js";const http=async function(url,options={}){"POST"==options.method&&options.data&&(options.body=JSON.stringify(options.data),options.headers=Object.assign({"content-type":"application/json"},options.headers));const res=await req(url,options);return res.json=()=>res.content?JSON.parse(res.content):null,res.text=()=>res.content,res},__drives=(["get","post"].forEach(method=>{http[method]=function(url,options={}){return http(url,Object.assign(options,{method:method.toUpperCase()}))}}),{}),__subtitle_cache={};async function get_drives_path(tid){var index=tid.indexOf("/",1),name=tid.substring(1,index),tid=tid.substring(index);return{drives:await get_drives(name),path:tid}}async function get_drives(name){var{settings,api,server,headers}=__drives[name];return null==settings.v3&&(settings.v3=!1,server=(await http.get(server+"/api/public/settings",{headers:headers})).json().data,_.isArray(server)?(settings.title=server.find(x=>"title"==x.key)?.value,settings.v3=!1,settings.version=server.find(x=>"version"==x.key)?.value,settings.enableSearch="true"==server.find(x=>"enable search"==x.key)?.value):(settings.title=server.title,settings.v3=!0,settings.version=server.version,settings.enableSearch=!1),api.path=settings.v3?"/api/fs/list":"/api/public/path",api.file=settings.v3?"/api/fs/get":"/api/public/path",api.search=(settings.v3,"/api/public/search"),api.other=settings.v3?"/api/fs/other":null),__drives[name]}let siteKey="",siteType=0;function init(cfg){siteKey=cfg.skey,siteType=cfg.stype,cfg.ext.forEach(item=>__drives[item.name]={name:item.name,server:item.server.endsWith("/")?item.server.substring(0,item.server.length-1):item.server,startPage:item.startPage||"/",showAll:!0===item.showAll,params:item.params||{},headers:item.headers||{},_path_param:item.params?_.sortBy(Object.keys(item.params),function(x){return-x.length}):[],settings:{},api:{},getParams(path){var key=this._path_param.find(x=>path.startsWith(x));return Object.assign({},this.params[key],{path:path})},async getPath(path){path=(await http.post(this.server+this.api.path,{headers:this.headers,data:this.getParams(path)})).json();return this.settings.v3?path.data.content:path.data.files},async getFile(path){path=(await http.post(this.server+this.api.file,{headers:this.headers,data:this.getParams(path)})).json(),path=this.settings.v3?path.data:path.data.files[0];return this.settings.v3||(path.raw_url=path.url),path},async getOther(method,path){path=this.getParams(path),path.method=method,method=(await http.post(this.server+this.api.other,{headers:this.headers,data:path})).json();return method},isFolder(data){return 1==data.type},isVideo(data){return this.settings.v3?2==data.type:3==data.type},isSubtitle(data){return 1!=data.type&&[".srt",".ass",".scc",".stl",".ttml"].some(x=>data.name.endsWith(x))},getType(data){var isVideo=this.isVideo(data);return this.isFolder(data)?0:isVideo?10:1},getPic(data){return(this.settings.v3?data.thumb:data.thumbnail)||(this.isFolder(data)?"http://img1.3png.com/281e284a670865a71d91515866552b5f172b.png":"")},getSize(data){let sz=data.size||0;if(sz<=0)return"";let filesize="";return filesize=1099511627776<sz?(sz/=1099511627776,"TB"):1073741824<sz?(sz/=1073741824,"GB"):1048576<sz?(sz/=1048576,"MB"):(sz/=1024,"KB"),sz.toFixed(2)+filesize},getRemark(data){return""}})}async function dir(dir,pg){for(const k in __subtitle_cache)delete __subtitle_cache[k];if(pg=pg||1,"/"===dir||""===dir)return result=_.map(__drives,function(d){return{name:d.name,path:"/"+d.name+d.startPage,type:0,thumb:""}}),JSON.stringify({parent:"",page:pg,pagecount:pg,list:result});let{drives,path}=await get_drives_path(dir);const id=dir.endsWith("/")?dir:dir+"/";var result=await drives.getPath(path);let subtList=[],videos=[],allList=[];return result.forEach(item=>{drives.isSubtitle(item)&&subtList.push(item.name);var isVideo=drives.isVideo(item);(drives.showAll||drives.isFolder(item)||isVideo)&&(isVideo={name:item.name.replaceAll("$","_").replaceAll("#","_"),path:id+item.name+(drives.isFolder(item)?"/":"