├── .gitignore ├── icon.png ├── docs ├── img_1.png ├── img_2.png └── img_3.png ├── info.json ├── README.md ├── .github └── workflows │ └── release.yml ├── alidrive_server.py ├── install.sh ├── alidrive_main.py ├── index.html └── static └── js └── app.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | tasks.json 3 | core 4 | test* -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoaostar/alidrive-uploader-for-baota/HEAD/icon.png -------------------------------------------------------------------------------- /docs/img_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoaostar/alidrive-uploader-for-baota/HEAD/docs/img_1.png -------------------------------------------------------------------------------- /docs/img_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoaostar/alidrive-uploader-for-baota/HEAD/docs/img_2.png -------------------------------------------------------------------------------- /docs/img_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aoaostar/alidrive-uploader-for-baota/HEAD/docs/img_3.png -------------------------------------------------------------------------------- /info.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "阿里云盘上传工具", 3 | "name": "alidrive", 4 | "ps": "阿里云盘上传工具", 5 | "versions": "2.2.6", 6 | "checks": "/www/server/panel/plugin/alidrive", 7 | "author": "Pluto", 8 | "home": "https://www.aoaostar.com" 9 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 说明 2 | 本项目为阿里云盘上传工具的宝塔插件 3 | 可以将服务器内的文件快速上传到阿里云盘 4 | 5 | ## 演示图 6 | ![](docs/img_1.png) 7 | ![](docs/img_2.png) 8 | ![](docs/img_3.png) 9 | ## 安装 10 | ### Centos7 11 | ```shell script 12 | yum install -y wget && wget -O install.sh https://raw.githubusercontent.com/aoaostar/alidrive-uploader-for-baota/v2/install.sh && bash install.sh install 13 | ``` 14 | ### Debian 15 | ```shell script 16 | wget -O install.sh https://raw.githubusercontent.com/aoaostar/alidrive-uploader-for-baota/v2/install.sh && bash install.sh install 17 | ``` 18 | ## 更新 19 | ``` 20 | wget -O install.sh https://raw.githubusercontent.com/aoaostar/alidrive-uploader-for-baota/v2/install.sh && bash install.sh update 21 | ``` 22 | ## 配置账号信息 23 | ![](https://z3.ax1x.com/2021/03/27/6zB8JA.png) 24 | 25 | * 控制台快速获取代码 26 | ```javascript 27 | var d = JSON.parse(localStorage.getItem('token')); 28 | console.log(` drive_id: ${d.default_drive_id}\n refresh_token: ${d.refresh_token}`); 29 | ``` -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | on: 3 | push: 4 | tags: 5 | - '*' 6 | jobs: 7 | release: 8 | strategy: 9 | matrix: 10 | platform: [ubuntu-latest] 11 | name: Build 12 | runs-on: ${{ matrix.platform }} 13 | steps: 14 | - name: Get version 15 | id: get_version 16 | run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} 17 | 18 | - name: Check out code into the Go module directory 19 | uses: actions/checkout@v2 20 | 21 | - name: Build Changelog 22 | id: github_release 23 | uses: mikepenz/release-changelog-builder-action@main 24 | env: 25 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | 27 | - name: Create Release 28 | id: create_release 29 | uses: actions/create-release@v1 30 | env: 31 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | with: 33 | tag_name: ${{ github.ref }} 34 | release_name: Release ${{ github.ref }} 35 | body: ${{steps.github_release.outputs.changelog}} 36 | draft: false 37 | prerelease: false -------------------------------------------------------------------------------- /alidrive_server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # +------------------------------------------------------------------- 4 | # | Date: 2022/4/4 5 | # +------------------------------------------------------------------- 6 | # | Author: Pluto 7 | # +------------------------------------------------------------------- 8 | import json 9 | import os 10 | import sys 11 | 12 | os.chdir("/www/server/panel") 13 | 14 | # 添加包引用位置并引用公共包 15 | sys.path.append("class/") 16 | import public 17 | import time 18 | import threading 19 | 20 | 21 | class alidrive_server: 22 | __plugin_path = "/www/server/panel/plugin/alidrive/" 23 | __tasks_file = __plugin_path + "tasks.json" 24 | __core_file = __plugin_path + "core/alidrive" 25 | __logs_file = __plugin_path + "core/logs/alidrive.log" 26 | 27 | def __init__(self): 28 | pass 29 | 30 | def alidrive_status(self): 31 | exec_shell = public.ExecShell("ps -ef | grep alidrive | grep -v python | grep -v grep | wc -l") 32 | if exec_shell[1] == "" and int(exec_shell[0]) > 0: 33 | return True 34 | return False 35 | 36 | def server_status(self, num=0): 37 | exec_shell = public.ExecShell("ps -ef | grep alidrive_server.py | grep -v grep | wc -l") 38 | if exec_shell[1] == "" and int(exec_shell[0]) > num: 39 | return True 40 | return False 41 | 42 | def server_start(self): 43 | if self.server_status(1): 44 | return 45 | 46 | # 启动定时任务 47 | t = threading.Thread(target=self.__cron) 48 | t.start() 49 | 50 | while True: 51 | if not self.alidrive_status(): 52 | tasks = self.__load_task() 53 | if len(tasks) > 0: 54 | try: 55 | id = list(tasks.keys())[0] 56 | task = tasks.pop(id) 57 | command = f"chmod 755 \"{self.__core_file}\" && \"{self.__core_file}\" --root_path=\"{task['root_path']}\" \"{task['filename']}\" /" 58 | exec_shell = public.ExecShell(command) 59 | self.log(command) 60 | self.log(f"resp-length={len(exec_shell[0])},error={exec_shell[1]}") 61 | # 获取最新task后删除旧的 62 | tasks = self.__load_task() 63 | if id in tasks: 64 | tasks.pop(id) 65 | public.writeFile(self.__tasks_file, json.dumps(tasks)) 66 | except Exception as e: 67 | self.log(e) 68 | pass 69 | 70 | time.sleep(1) 71 | 72 | def server_stop(self): 73 | public.ExecShell("ps -ef | grep alidrive_server.py | grep -v 'grep' | cut -c 9-15 | xargs kill -9") 74 | public.ExecShell("ps -ef | grep alidrive | grep -v python | grep -v 'grep' | cut -c 9-15 | xargs kill -9") 75 | return True, "" 76 | 77 | def log(self, message): 78 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 79 | log = f"[插件日志][{now}] {message}\n" 80 | public.writeFile(self.__logs_file, log, "a") 81 | 82 | def __cron(self): 83 | # 启动定时刷新refresh_token 84 | while True: 85 | if not self.alidrive_status(): 86 | self.__refresh_token() 87 | time.sleep(3600) 88 | else: 89 | time.sleep(10) 90 | 91 | def __refresh_token(self): 92 | command = f"chmod 755 \"{self.__core_file}\" && \"{self.__core_file}\" --refresh" 93 | self.log(f"[定时刷新token] {command}") 94 | public.ExecShell(command) 95 | 96 | def __load_task(self): 97 | if os.path.exists(self.__tasks_file): 98 | task_file = public.readFile(self.__tasks_file) 99 | tasks = json.loads(task_file) 100 | else: 101 | tasks = {} 102 | return tasks 103 | 104 | 105 | if __name__ == '__main__': 106 | server = alidrive_server() 107 | if len(sys.argv) > 2 and sys.argv[1] == "stop": 108 | server.server_stop() 109 | else: 110 | server.server_start() 111 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | hash tar uname grep curl head 4 | 5 | #配置插件安装目录 6 | install_path=/www/server/panel/plugin/alidrive 7 | panel_path=/www/server/panel 8 | 9 | PROXY="https://proxy.aoaostar.workers.dev/" 10 | OS="$(uname)" 11 | case $OS in 12 | Linux) 13 | OS='linux' 14 | ;; 15 | Darwin) 16 | OS='darwin' 17 | ;; 18 | *) 19 | echo 'OS not supported' 20 | exit 2 21 | ;; 22 | esac 23 | 24 | ARCH="$(uname -m)" 25 | case $ARCH in 26 | x86_64 | amd64) 27 | ARCH='amd64' 28 | ;; 29 | aarch64) 30 | ARCH='arm64' 31 | ;; 32 | i?86 | x86) 33 | ARCH='386' 34 | ;; 35 | arm*) 36 | ARCH='arm' 37 | ;; 38 | *) 39 | echo 'OS type not supported' 40 | exit 2 41 | ;; 42 | esac 43 | 44 | if [[ $2 == "-y" ]]; then 45 | echo "使用加速代理" 46 | elif [[ $2 == "-n" ]]; then 47 | echo "不使用加速代理" 48 | PROXY="" 49 | elif [[ $(curl -m 10 -s https://ipapi.co/json | grep 'China') != "" ]]; then 50 | echo "根据ipapi.co提供的信息,当前IP可能在中国" 51 | read -e -r -p "是否选用使用加速代理完成安装? [Y/n] " input 52 | case $input in 53 | [yY][eE][sS] | [yY]) 54 | echo "使用加速代理" 55 | ;; 56 | 57 | [nN][oO] | [nN]) 58 | echo "不使用加速代理" 59 | PROXY="" 60 | ;; 61 | *) 62 | echo "使用加速代理" 63 | ;; 64 | esac 65 | fi 66 | #安装 67 | Install() { 68 | Uninstall 69 | rm -rf $panel_path/BTPanel/static/img/soft_ico/ico-alidrive.png 70 | rm -rf $install_path 71 | echo '正在安装阿里云盘上传工具...' 72 | #================================================================== 73 | #依赖安装开始 74 | echo '下载插件中' 75 | DOWNLOAD_URL=$(curl -fsSL "$PROXY"https://api.github.com/repos/aoaostar/alidrive-uploader-for-baota/releases/latest | grep "tarball_url.*" | cut -d '"' -f 4) 76 | curl -L "$PROXY$DOWNLOAD_URL" | tar -xz 77 | mv $(ls | grep "alidrive-uploader-for-baota") $install_path 78 | echo '下载上传驱动中' 79 | CORE_DOWNLOAD_URL=$(curl -fsSL "$PROXY"https://api.github.com/repos/aoaostar/alidrive-uploader/releases/latest | grep "browser_download_url.*$OS.*$ARCH" | cut -d '"' -f 4) 80 | curl -L "$PROXY$CORE_DOWNLOAD_URL" | tar -xz 81 | mv $(ls | grep "alidrive_uploader") $install_path/core 82 | cp $install_path/icon.png $panel_path/BTPanel/static/img/soft_ico/ico-alidrive.png 83 | cp $install_path/core/example.config.yaml $install_path/core/config.yaml 84 | #依赖安装结束 85 | #================================================================== 86 | echo '================================================' 87 | echo '阿里云盘上传工具安装完成' 88 | } 89 | # 更新 90 | Update() { 91 | rm -rf $install_path\_temp 92 | mkdir -p $install_path\_temp/core 93 | cp $install_path/core/config.yaml $install_path\_temp/core/config.yaml 94 | Uninstall 95 | cd $install_path\_temp 96 | echo '正在更新阿里云盘上传工具...' 97 | #================================================================== 98 | #依赖安装开始 99 | echo '更新插件中' 100 | DOWNLOAD_URL=$(curl -fsSL "$PROXY"https://api.github.com/repos/aoaostar/alidrive-uploader-for-baota/releases/latest | grep "tarball_url.*" | cut -d '"' -f 4) 101 | curl -L "$PROXY$DOWNLOAD_URL" | tar -xz 102 | mv $(ls | grep "alidrive-uploader-for-baota") $install_path 103 | echo '更新插件上传驱动中' 104 | CORE_DOWNLOAD_URL=$(curl -fsSL "$PROXY"https://api.github.com/repos/aoaostar/alidrive-uploader/releases/latest | grep "browser_download_url.*$OS.*$ARCH" | cut -d '"' -f 4) 105 | curl -L "$PROXY$CORE_DOWNLOAD_URL" | tar -xz 106 | mv $(ls | grep "alidrive_uploader") $install_path/core 107 | chmod 755 $install_path/core/alidrive 108 | cp $install_path/icon.png $panel_path/BTPanel/static/img/soft_ico/ico-alidrive.png 109 | cp $install_path/core/example.config.yaml $install_path/core/config.yaml 110 | mv -f $install_path\_temp/core/config.yaml $install_path/core/config.yaml 111 | rm -rf $install_path\_temp 112 | #依赖安装结束 113 | #================================================================== 114 | echo '================================================' 115 | echo '阿里云盘上传工具更新完成!请重启插件!' 116 | } 117 | 118 | #卸载 119 | Uninstall() { 120 | rm -rf $install_path 121 | } 122 | 123 | #操作判断 124 | if [ "${1}" == 'install' ]; then 125 | Install 126 | elif [ "${1}" == 'uninstall' ]; then 127 | Uninstall 128 | elif [ "${1}" == 'update' ]; then 129 | Update 130 | else 131 | echo 'Error!' 132 | fi 133 | -------------------------------------------------------------------------------- /alidrive_main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # +------------------------------------------------------------------- 4 | # | Date: 2022/4/4 5 | # +------------------------------------------------------------------- 6 | # | Author: Pluto 7 | # +------------------------------------------------------------------- 8 | import sys, os, json 9 | from alidrive_server import alidrive_server 10 | 11 | # 设置运行目录 12 | os.chdir("/www/server/panel") 13 | 14 | # 添加包引用位置并引用公共包 15 | sys.path.append("class/") 16 | import public 17 | 18 | 19 | class alidrive_main: 20 | __plugin_path = "/www/server/panel/plugin/alidrive/" 21 | __tasks_file = __plugin_path + "tasks.json" 22 | __config_file = __plugin_path + "core/config.yaml" 23 | __logs_file = __plugin_path + "core/logs/alidrive.log" 24 | __core_file = __plugin_path + "core/alidrive" 25 | __python = "/www/server/panel/pyenv/bin/python" 26 | __config = None 27 | __tasks = None 28 | 29 | # 构造方法 30 | def __init__(self): 31 | self.__tasks = self.__get_tasks() 32 | self.__config = self.__get_config() 33 | 34 | def index(self, args): 35 | from BTPanel import cache 36 | check_update = cache.get("check_update") 37 | if not check_update or len(check_update) < 4: 38 | check_update = self.check_update(args) 39 | cache.set("check_update", check_update, 3600) 40 | return check_update 41 | 42 | def check_update(self, args): 43 | from BTPanel import cache 44 | import requests 45 | cache.delete("check_update") 46 | file = public.readFile(self.__plugin_path + "info.json") 47 | loads = json.loads(file) 48 | exec_shell = public.ExecShell(f"chmod 755 {self.__core_file} && {self.__core_file} -v") 49 | get = requests.get("https://api.github.com/repos/aoaostar/alidrive-uploader-for-baota/releases/latest") 50 | plugin_json = get.json() 51 | get = requests.get("https://api.github.com/repos/aoaostar/alidrive-uploader/releases/latest") 52 | core_json = get.json() 53 | return { 54 | "version": loads["versions"], 55 | "core_version": exec_shell[0], 56 | "lastest_version": plugin_json["tag_name"], 57 | "lastest_core_version": core_json["tag_name"], 58 | } 59 | 60 | def update(self, args): 61 | shell = public.ExecShell( 62 | f"chmod 755 {self.__plugin_path}install.sh && bash {self.__plugin_path}install.sh update") 63 | 64 | if not shell[0] == "": 65 | return public.returnMsg(True, shell[0]) 66 | return public.returnMsg(False, shell[1]) 67 | 68 | def add_task(self, args): 69 | if "filepath" not in args: 70 | return public.returnMsg(False, "请传入文件路径") 71 | if not os.path.exists(args.filepath): 72 | return public.returnMsg(False, "文件不存在") 73 | import uuid 74 | import yaml 75 | yaml_load = yaml.safe_load(self.__config) 76 | self.__tasks[str(uuid.uuid1())] = { 77 | "filename": args.filepath, 78 | "root_path": yaml_load.get("ali_drive").get("root_path"), 79 | } 80 | self.__save_tasks() 81 | return public.returnMsg(True, "添加成功") 82 | 83 | def get_tasks(self, args): 84 | return self.__tasks 85 | 86 | def delete_task(self, args): 87 | if "id" not in args: 88 | return public.returnMsg(False, "请传入任务id") 89 | if args.id in self.__tasks: 90 | del self.__tasks[args.id] 91 | self.__save_tasks() 92 | return public.returnMsg(True, "删除成功") 93 | 94 | def get_config(self, args): 95 | return self.__config 96 | 97 | def save_config(self, args): 98 | 99 | if "data" not in args: 100 | return public.returnMsg(False, "请传入配置文件内容") 101 | self.__config = args.data 102 | self.__save_config() 103 | return public.returnMsg(True, "保存成功") 104 | 105 | def get_logs(self, args): 106 | f_body = "" 107 | if os.path.exists(self.__logs_file): 108 | f_body = public.readFile(self.__logs_file) 109 | return f_body 110 | 111 | def clear_logs(self, args): 112 | if os.path.isfile(self.__logs_file): 113 | dirname = os.path.dirname(self.__logs_file) 114 | listdir = os.listdir(dirname) 115 | for p in listdir: 116 | path_join = os.path.join(dirname, p) 117 | if os.path.isfile(path_join): 118 | os.remove(path_join) 119 | return public.returnMsg(True, "清除成功") 120 | 121 | def exec_clean(self, args): 122 | command = f"chmod 755 \"{self.__core_file}\" && \"{self.__core_file}\" --clean" 123 | server = alidrive_server() 124 | server.log(f"[清理缓存] {command}") 125 | exec_shell = public.ExecShell(command) 126 | if exec_shell[1] != "": 127 | server.log(f"[清理缓存] {exec_shell[1]}") 128 | return public.returnMsg(False, f"清除失败, {exec_shell[1]}") 129 | server.log(f"[清理缓存] {exec_shell[0]}") 130 | return public.returnMsg(True, "清除成功") 131 | 132 | def server_status(self, args): 133 | server = alidrive_server() 134 | return { 135 | "status": server.server_status(), 136 | "core_status": server.alidrive_status(), 137 | } 138 | 139 | def server_start(self, args): 140 | exec_shell = public.ExecShell( 141 | f"nohup {self.__python} {self.__plugin_path}alidrive_server.py >/dev/null 2>error.log 2>&1 &") 142 | if exec_shell[1] == "": 143 | return public.returnMsg(True, "启动成功") 144 | return public.returnMsg(False, exec_shell[1]) 145 | 146 | def server_stop(self, args): 147 | from alidrive_server import alidrive_server 148 | server = alidrive_server() 149 | stop = server.server_stop() 150 | if stop[0]: 151 | return public.returnMsg(True, "停止成功") 152 | return public.returnMsg(stop[0], stop[1]) 153 | 154 | def server_restart(self, args): 155 | from alidrive_server import alidrive_server 156 | server = alidrive_server() 157 | stop = server.server_stop() 158 | if stop[0]: 159 | start = public.ExecShell( 160 | f"nohup {self.__python} {self.__plugin_path}alidrive_server.py >/dev/null 2>error.log 2>&1 &") 161 | if start[1] == "": 162 | return public.returnMsg(True, "重启成功") 163 | else: 164 | return public.returnMsg(start[0], start[1]) 165 | else: 166 | return public.returnMsg(stop[0], stop[1]) 167 | 168 | def __get_config(self): 169 | # 判断是否从文件读取配置 170 | f_body = "" 171 | if os.path.exists(self.__config_file): 172 | f_body = public.ReadFile(self.__config_file) 173 | return f_body 174 | 175 | def __save_config(self): 176 | public.WriteFile(self.__config_file, self.__config) 177 | return True 178 | 179 | def __get_tasks(self): 180 | tasks = {} 181 | if os.path.exists(self.__tasks_file): 182 | file = public.readFile(self.__tasks_file) 183 | tasks = json.loads(file) 184 | if not isinstance(tasks, dict): 185 | tasks = {} 186 | 187 | return tasks 188 | 189 | def __save_tasks(self): 190 | public.writeFile(self.__tasks_file, json.dumps(self.__tasks)) 191 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 85 |
86 |
87 | 88 |
89 |

概览

90 |

配置

91 |

任务列表

92 |

查看文件

93 |

实时日志

94 |
95 | 96 |
97 |
98 |
99 |
100 |
101 |

102 | 任务池状态:运行 103 | 105 |

106 |

107 | 任务池状态:停止 108 |

110 |
111 |
112 |

113 | Core 状态:运行 114 | 116 |

117 |

118 | Core 状态:停止 119 |

121 |
122 |
123 |
124 | 128 | 131 | 134 | 137 | 140 |
141 | 143 | 144 | 145 |
146 |
    147 |
  • 任务池为监控上传任务的后台应用
  • 148 |
  • Core 状态在未上传时为停止状态,正在上传时才为运行状态
  • 149 |
150 |
151 |
152 |
153 | 155 |
    156 |
  • 此处为yaml类型配置文件,请严格按照语法修改。
  • 157 |
158 |
159 |
160 |
161 | 164 | 167 |
168 |
169 |
170 | 171 | 172 | 173 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 |
174 | ID文件路径网盘根目录
183 |
184 |
185 |
186 | 187 |
188 |
189 |
190 | 共0条 191 |
192 |
193 |
194 |
195 |
196 |
197 | 200 | 203 | 205 |
206 |
207 |
208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 |
名称大小更新时间操作
220 |
221 |
222 |
223 | 227 |
228 |
229 |
230 |
231 |
232 |
233 | 234 | -------------------------------------------------------------------------------- /static/js/app.js: -------------------------------------------------------------------------------- 1 | var alidrive_message = { 2 | instance: 0, 3 | loading: function (message) { 4 | this.instance = layer.msg(message, { 5 | icon: 16, 6 | shade: 0.4, 7 | time: 0, 8 | }); 9 | return this.instance 10 | }, 11 | success: function (message) { 12 | this.instance = layer.msg(message, { 13 | icon: 1 14 | }); 15 | return this.instance 16 | }, 17 | error: function (message) { 18 | this.instance = layer.msg(message, { 19 | icon: 2 20 | }); 21 | return this.instance 22 | }, 23 | close: function (instance) { 24 | if (instance) { 25 | layer.close(instance) 26 | } else { 27 | layer.close(this.instance) 28 | } 29 | } 30 | } 31 | 32 | var alidrive_view_files = { 33 | page: 1, 34 | index: function () { 35 | show('p-files') 36 | this.get_dir() 37 | }, 38 | get_dir: function (p, path) { 39 | 40 | if (p === undefined) p = 1; 41 | if (path === undefined) { 42 | path = getCookie('Path'); 43 | } 44 | setCookie('Path', path); 45 | this.page = p 46 | request_post('/files?action=GetDir', { 47 | p: p, 48 | showRow: 100, 49 | path: path, 50 | }).then(res => { 51 | //href='p=2' 52 | $("#p-file-page").html(res.PAGE.replace(/href='p=(\d+)'/g, `onclick="alidrive_view_files.get_dir($1,'${res.PATH}')"`)) 53 | let path_split = res.PATH.split('/'); 54 | let tmp_path = `
  • 根目录
  • ` 55 | 56 | for (let i = 0; i < path_split.length; i++) { 57 | if (path_split[i] === "") { 58 | continue 59 | } 60 | let full_path = path_split.slice(0, i + 1).join('/') 61 | tmp_path += `
  • ${path_split[i]}
  • ` 62 | } 63 | $('#p-files-path').html(tmp_path) 64 | 65 | let tmp = '' 66 | for (const d of res.DIR) { 67 | const fileinfo = d.split(';'); 68 | const realpath = res.PATH + '/' + fileinfo[0]; 69 | tmp += ` 70 | 71 | ${fileinfo[0]} 72 | 73 | ${ToSize(fileinfo[1])} 74 | ${getLocalTime(fileinfo[2])} 75 | 76 | 上传 77 | 78 | ` 79 | } 80 | for (const d of res.FILES) { 81 | const fileinfo = d.split(';'); 82 | const realpath = res.PATH + '/' + fileinfo[0]; 83 | tmp += ` 84 | 85 | ${fileinfo[0]} 86 | 87 | ${ToSize(fileinfo[1])} 88 | ${getLocalTime(fileinfo[2])} 89 | 90 | 上传 91 | 92 | ` 93 | } 94 | $('#p-files-list').html(tmp) 95 | }) 96 | }, 97 | back: function () { 98 | let path = getCookie('Path'); 99 | this.get_dir(1, path.slice(0, path.lastIndexOf('/') + 1)) 100 | } 101 | } 102 | var alidrive = { 103 | task: null, 104 | update: function () { 105 | const loading = alidrive_message.loading('正在更新中'); 106 | request_plugin("alidrive", 'update', {}, 0).then(res => { 107 | if (res.status) { 108 | alidrive_message.success("更新成功") 109 | } else { 110 | alidrive_message.error(res.msg) 111 | } 112 | }).finally(() => { 113 | alidrive_message.close(loading) 114 | setTimeout(() => { 115 | this.check_update() 116 | alidrive_server.restart() 117 | }, 2000) 118 | }) 119 | }, 120 | check_update: function (type = "check_update") { 121 | const loading = alidrive_message.loading('正在检查更新中'); 122 | request_plugin("alidrive", type).then(res => { 123 | let tmp = ` 124 | 插件版本 125 | ${res.version} 126 | Core 版本 127 | ${res.core_version} 128 | 129 | 130 | 最新插件版本 131 | ${res.lastest_version} 132 | 最新 Core 版本 133 | ${res.lastest_core_version} 134 | 135 | 136 | 作者 137 | Pluto 138 | Github 139 | https://github.com/aoaostar/alidrive-uploader 140 | ` 141 | $('#p-index-content').html(tmp) 142 | }).finally(() => { 143 | alidrive_message.close(loading) 144 | }) 145 | }, 146 | get_index: function () { 147 | show("p-index") 148 | this.check_update("index") 149 | alidrive_server.status() 150 | }, 151 | get_config: function () { 152 | show("p-config") 153 | request_plugin("alidrive", "get_config").then(res => { 154 | $('#p-config-content').text(res) 155 | }) 156 | }, 157 | save_config: function () { 158 | const loading = alidrive_message.loading('提交中'); 159 | request_plugin("alidrive", "save_config", { 160 | data: $('#p-config-content').text() 161 | }).then(res => { 162 | layer.msg(res.msg, {icon: res.status ? 1 : 2}); 163 | }).finally(() => { 164 | alidrive_message.close(loading) 165 | }) 166 | }, 167 | get_tasks: function () { 168 | show('p-task') 169 | request_plugin("alidrive", "get_tasks").then(res => { 170 | let tmp = '' 171 | for (const k in res) { 172 | tmp += ` 173 | 174 | 175 |
    ${k}
    176 | 177 | 178 |
    ${res[k]["filename"]}
    179 | 180 | 181 |
    ${res[k]["root_path"]}
    182 | 183 | ` 184 | } 185 | $('#p-task-content').html(tmp) 186 | $('#p-task-count').text(`共${Object.keys(res).length}条`) 187 | }) 188 | }, 189 | add_task: function (filepath) { 190 | const loading = alidrive_message.loading('提交中'); 191 | request_plugin("alidrive", "add_task", { 192 | filepath: filepath 193 | }).then(res => { 194 | layer.msg(res.msg, {icon: res.status ? 1 : 2}); 195 | }).finally(() => { 196 | alidrive_message.close(loading) 197 | }) 198 | }, 199 | delete_task: function (id) { 200 | const loading = alidrive_message.loading('提交中'); 201 | return request_plugin("alidrive", "delete_task", { 202 | id: id 203 | }).finally(() => { 204 | alidrive_message.close(loading) 205 | }) 206 | }, 207 | get_logs: function () { 208 | show("p-log") 209 | const task = () => request_plugin("alidrive", "get_logs").then(res => { 210 | let $p = $('#p-log-content'); 211 | $p.text(res) 212 | $p.scrollTop($p.prop("scrollHeight")) 213 | }) 214 | this.task = task 215 | $('#p-log-content').on('mouseenter', () => { 216 | this.task = null 217 | }) 218 | $('#p-log-content').on('mouseleave', () => { 219 | this.task = task 220 | }) 221 | }, 222 | clear_logs: function () { 223 | request_plugin("alidrive", "clear_logs").then(res => { 224 | layer.msg(res.msg, {icon: res.status ? 1 : 2}); 225 | this.get_logs() 226 | }) 227 | }, 228 | exec_clean: function () { 229 | request_plugin("alidrive", "exec_clean").then(res => { 230 | layer.msg(res.msg, {icon: res.status ? 1 : 2}); 231 | this.get_logs() 232 | }) 233 | }, 234 | } 235 | 236 | var alidrive_server = { 237 | status: function () { 238 | const loading = alidrive_message.loading('正在获取系统状态'); 239 | request_plugin("alidrive", "server_status").then(res => { 240 | $('#p-index .status').hide() 241 | let status_change = $('#p-index .status-change'); 242 | status_change.hide() 243 | if (res.status || res.core_status) { 244 | $(status_change[1]).show() 245 | } else { 246 | $(status_change[0]).show() 247 | } 248 | if (res.status) { 249 | $('#p-index .plugin-status .status.ok').show() 250 | } else { 251 | $('#p-index .plugin-status .status.no').show() 252 | } 253 | if (res.core_status) { 254 | $('#p-index .core-status .status.ok').show() 255 | } else { 256 | $('#p-index .core-status .status.no').show() 257 | } 258 | }).finally(() => { 259 | alidrive_message.close(loading) 260 | }) 261 | }, 262 | start: function () { 263 | const loading = alidrive_message.loading('正在发送启动命令'); 264 | request_plugin("alidrive", "server_start").then(res => { 265 | if (res.status) { 266 | alidrive_message.success("启动成功") 267 | } else { 268 | alidrive_message.error(res.message) 269 | } 270 | }).finally(() => { 271 | alidrive_message.close(loading) 272 | setTimeout(() => { 273 | this.status() 274 | }, 2000) 275 | }) 276 | }, 277 | stop: function () { 278 | const loading = alidrive_message.loading('正在发送停止命令'); 279 | request_plugin("alidrive", "server_stop").then(res => { 280 | if (res.status) { 281 | alidrive_message.success("停止成功") 282 | } else { 283 | alidrive_message.error(res.message) 284 | } 285 | }).finally(() => { 286 | alidrive_message.close(loading) 287 | setTimeout(() => { 288 | this.status() 289 | }, 2000) 290 | }) 291 | }, 292 | restart: function () { 293 | const loading = alidrive_message.loading('正在发送重启命令'); 294 | request_plugin("alidrive", "server_restart").then(res => { 295 | if (res.status) { 296 | alidrive_message.success("重启成功") 297 | } else { 298 | alidrive_message.error(res.message) 299 | } 300 | }).finally(() => { 301 | alidrive_message.close(loading) 302 | setTimeout(() => { 303 | this.status() 304 | }, 2000) 305 | }) 306 | }, 307 | } 308 | 309 | function request_plugin(plugin_name, function_name, args, timeout) { 310 | return new Promise((resolve, reject) => { 311 | $.ajax({ 312 | type: 'POST', 313 | url: '/plugin?action=a&s=' + function_name + '&name=' + plugin_name, 314 | data: args, 315 | timeout: timeout, 316 | success: function (rdata) { 317 | resolve(rdata) 318 | }, 319 | error: function (e) { 320 | alidrive_message.error("请求异常" + e.responseText) 321 | reject(e) 322 | } 323 | }) 324 | }) 325 | } 326 | 327 | function request_post(url, args, callback, timeout) { 328 | if (!timeout) timeout = 3600; 329 | return new Promise((resolve, reject) => { 330 | $.ajax({ 331 | type: 'POST', 332 | url: url, 333 | data: args, 334 | timeout: timeout, 335 | dataType: 'json', 336 | success: function (rdata) { 337 | resolve(rdata) 338 | }, 339 | error: function (e) { 340 | alidrive_message.error("请求异常" + e.responseText) 341 | reject(e) 342 | } 343 | }) 344 | }) 345 | } --------------------------------------------------------------------------------