Browse Source

代码上传

dukuisong 13 hours ago
parent
commit
829f231cf2

BIN
dist/office_helper_main.exe


+ 15 - 18
office_helper.py

@@ -4,22 +4,19 @@ import os.path
 import sys
 import threading
 
+if getattr(sys, 'frozen', False):
+    # 打包后的 exe
+    os.chdir(os.path.dirname(sys.executable))
+else:
+    # 普通 Python 脚本
+    os.chdir(os.path.dirname(os.path.abspath(__file__)))
+
 from config import dl_code
 from core.api_app import start_flask
 from core.monitor_file import start_watchdog
 from tools.logger_handle import logger
 from tools.serve_client import ServerClient
 
-# 初始化 Flask 应用
-
-
-# 初始化桌面通知工具
-
-
-# 存储文档内容和推荐内容
-current_text = ""
-recommendation = "这是默认推荐内容"
-
 
 def ApplicationInstance(func):
     @functools.wraps(func)
@@ -51,19 +48,19 @@ def start_all_services(serve_client, work_path):
 
 
 if __name__ == "__main__":
-    def set_working_directory():
-        if getattr(sys, 'frozen', False):
-            # 打包后的 exe
-            os.chdir(os.path.dirname(sys.executable))
-        else:
-            # 普通 Python 脚本
-            os.chdir(os.path.dirname(os.path.abspath(__file__)))
 
+    if not os.path.exists(f'{dl_code}:\\ProgramData\\OfficeAssistant\\config.json'):
+        logger.error('"config.json" is not find')
+        sys.exit(0)
 
     with open(f'{dl_code}:\\ProgramData\\OfficeAssistant\\config.json', 'r', encoding='utf-8') as f:
-    # with open(f'config.json', 'r', encoding='utf-8') as f:
+        # with open(f'config.json', 'r', encoding='utf-8') as f:
         args = json.load(f)
 
+    if not (args.get('server') and args.get('username') and args.get('password')):
+        logger.error('The config is missing critical information')
+        sys.exit(0)
+
     client = ServerClient(args['server'], args['username'], args['password'])
     if not os.path.exists(os.path.join(args['worker_path'], args['username'])):
         os.makedirs(os.path.join(args['worker_path'], args['username']))

+ 16 - 1
readme

@@ -29,4 +29,19 @@ upload_file
 
 pyinstaller --onefile --noconsole --windowed --icon=../icon.ico init_wps_plug.py
 
-pyinstaller --onefile --noconsole --windowed --icon=icon.ico office_helper.py
+pyinstaller --onefile --noconsole --windowed --icon=icon.ico office_helper.py
+
+
+
+tee /etc/apt/sources.list > /dev/null <<EOF
+deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
+deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
+deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
+deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
+deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
+deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
+deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
+deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
+deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
+deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
+EOF

+ 8 - 0
script/install.bat

@@ -0,0 +1,8 @@
+@echo off
+set "APP_NAME=OfficeHelper"
+set "APP_EXE=office_helper.exe"
+set "SCRIPT_DIR=%~dp0"
+set "FULL_PATH=%SCRIPT_DIR%%APP_EXE%"
+
+rem 添加开机启动项到当前用户(免管理员)
+reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "%APP_NAME%" /d "\"%FULL_PATH%\"" /f >nul 2>&1

+ 2 - 0
script/install_silent.vbs

@@ -0,0 +1,2 @@
+Set WshShell = CreateObject("WScript.Shell")
+WshShell.Run """" & "install.bat" & """", 0, False

+ 8 - 0
script/uninstall.bat

@@ -0,0 +1,8 @@
+@echo off
+set "APP_NAME=OfficeHelper"
+
+rem 删除注册表中的开机启动项(当前用户)
+reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "%APP_NAME%" /f >nul 2>&1
+
+echo 开机启动项已删除。
+pause

+ 2 - 0
script/uninstall_silent.vbs

@@ -0,0 +1,2 @@
+Set WshShell = CreateObject("WScript.Shell")
+WshShell.Run """" & "uninstall.bat" & """", 0, False

+ 35 - 11
setup_wps/init_wps_plug.py

@@ -1,23 +1,47 @@
 import base64
 import json
 import os
+import sys
 
 import requests
 
-url = "ksowpscloudsvr://start=RelayHttpServer&serverId=aef5ac0d-d5a3-49ee-b02f-c31eeb063f9b"
+server_id = 'aef5ac0d-d5a3-49ee-b02f-c31eeb063f9b'
+url = f"ksowpscloudsvr://start=RelayHttpServer&serverId={server_id}"
 
 os.startfile(url)
 
-payload = {'data': {"cmd": "enable", "name": "jx_office", "url": "http://120.195.49.22:7212/", "addonType": "wps",
-                    "online": "true"},
-           'serverId': 'aef5ac0d-d5a3-49ee-b02f-c31eeb063f9b'}
 
-payload['data'] = base64.b64encode(json.dumps(payload['data']).encode('utf-8')).decode('utf-8')
+def base64_encode(data):
+    return base64.b64encode(json.dumps(data).encode('utf-8')).decode('utf-8')
 
-headers = {
-    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36',
-    'content-type': 'text/plain;charset=UTF-8'
-}
-resp = requests.post('http://localhost:58890/deployaddons/runParams', data=json.dumps(payload), headers=headers)
 
-a = resp.text
+if __name__ == '__main__':
+
+    if len(sys.argv) < 2:
+        sys.exit(1)
+
+    command = sys.argv[1].lower()
+
+    if command == "install":
+        cmd = 'enable'
+
+    elif command == "uninstall":
+        cmd = 'disable'
+
+    else:
+        print(f"未知命令: {command}")
+
+    payload = {'data': {"cmd": cmd, "name": "jx_office", "url": "http://120.195.49.22:7212/", "addonType": "wps",
+                        "online": "true"},
+               'serverId': server_id}
+
+    payload['data'] = base64_encode(payload['data'])
+
+    headers = {
+        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36',
+        'content-type': 'text/plain;charset=UTF-8'
+    }
+
+    resp = requests.post('http://localhost:58890/deployaddons/runParams', data=json.dumps(payload), headers=headers)
+
+    print(resp.text)

+ 0 - 0
tools/test.docx


+ 0 - 1
tools/test.docx.metadata

@@ -1 +0,0 @@
-{"serve": "172.10.3.36:9000", "access_key": "miniominio", "secret_key": "miniominio", "bucket_name": "aaa", "file_name": "test.docx", "file_id": "c5a8f3d5811e572265501eeaf6d8b1cf"}