|
@@ -1,27 +1,20 @@
|
|
import datetime
|
|
import datetime
|
|
-import gc
|
|
|
|
import logging
|
|
import logging
|
|
import os
|
|
import os
|
|
-import shutil
|
|
|
|
import socket
|
|
import socket
|
|
|
|
+import subprocess
|
|
|
|
|
|
-import pythoncom
|
|
|
|
-import pywintypes
|
|
|
|
import requests
|
|
import requests
|
|
-import win32com.client
|
|
|
|
|
|
+
|
|
from flask import Flask, jsonify, request, current_app, send_from_directory, Response
|
|
from flask import Flask, jsonify, request, current_app, send_from_directory, Response
|
|
from flask_cors import CORS
|
|
from flask_cors import CORS
|
|
from requests_toolbelt import MultipartEncoder
|
|
from requests_toolbelt import MultipartEncoder
|
|
-from win10toast import ToastNotifier
|
|
|
|
-
|
|
|
|
|
|
|
|
from config import file_type_map, TARGET_URL
|
|
from config import file_type_map, TARGET_URL
|
|
-from tools.check import is_file_open_in_wps
|
|
|
|
from tools.file_manager import get_file_md5
|
|
from tools.file_manager import get_file_md5
|
|
from tools.logger_handle import logger
|
|
from tools.logger_handle import logger
|
|
|
|
|
|
socket.getfqdn = lambda name=None: 'localhost'
|
|
socket.getfqdn = lambda name=None: 'localhost'
|
|
-toaster = ToastNotifier()
|
|
|
|
|
|
|
|
app = Flask(__name__, static_folder='../static')
|
|
app = Flask(__name__, static_folder='../static')
|
|
|
|
|
|
@@ -128,30 +121,13 @@ def proxy(path):
|
|
@logger.catch()
|
|
@logger.catch()
|
|
def open_file_by_wps(file_path):
|
|
def open_file_by_wps(file_path):
|
|
ext = file_path.split(".")[-1]
|
|
ext = file_path.split(".")[-1]
|
|
- shutil.rmtree(win32com.client.gencache.GetGeneratePath())
|
|
|
|
if ext not in file_type_map:
|
|
if ext not in file_type_map:
|
|
return jsonify({'code': 3001, 'msg': '不支持该类型的文件'})
|
|
return jsonify({'code': 3001, 'msg': '不支持该类型的文件'})
|
|
|
|
|
|
if not os.path.exists(file_path):
|
|
if not os.path.exists(file_path):
|
|
return jsonify({'code': 3006, 'msg': '文件不存在'})
|
|
return jsonify({'code': 3006, 'msg': '文件不存在'})
|
|
|
|
|
|
- pythoncom.CoInitialize()
|
|
|
|
- try:
|
|
|
|
- wps = win32com.client.DispatchEx(file_type_map[ext][0])
|
|
|
|
- wps.Visible = True
|
|
|
|
- if ext in ['csv', 'xlsx', 'xls']:
|
|
|
|
- getattr(wps, file_type_map[ext][1]).Open(os.path.abspath(file_path))
|
|
|
|
- else:
|
|
|
|
- getattr(wps, file_type_map[ext][1]).open(os.path.abspath(file_path))
|
|
|
|
-
|
|
|
|
- except pywintypes.com_error as e:
|
|
|
|
- logger.exception(e)
|
|
|
|
- pass
|
|
|
|
-
|
|
|
|
- finally:
|
|
|
|
- del wps
|
|
|
|
- gc.collect()
|
|
|
|
- pythoncom.CoUninitialize()
|
|
|
|
|
|
+ subprocess.run([file_type_map[ext], file_path])
|
|
|
|
|
|
return jsonify({'code': 1000, 'msg': '操作完成'})
|
|
return jsonify({'code': 1000, 'msg': '操作完成'})
|
|
|
|
|
|
@@ -195,10 +171,6 @@ def download_and_open_with_wps():
|
|
|
|
|
|
return open_file_by_wps(local_file)
|
|
return open_file_by_wps(local_file)
|
|
|
|
|
|
- # 判断本地文件是否被打开
|
|
|
|
- if is_file_open_in_wps(local_file):
|
|
|
|
- return jsonify({'code': 1000, 'msg': '检测到文件已被打开'})
|
|
|
|
-
|
|
|
|
# 判断本地文件和线上文件是否一致
|
|
# 判断本地文件和线上文件是否一致
|
|
local_file_metadata = current_app.config['serve_client'].load_metadata(local_file)
|
|
local_file_metadata = current_app.config['serve_client'].load_metadata(local_file)
|
|
if local_file_metadata['update_time'] == file_info['updateTime']:
|
|
if local_file_metadata['update_time'] == file_info['updateTime']:
|
|
@@ -216,8 +188,6 @@ def download_and_open_with_wps():
|
|
@app.route('/upload_local_file', methods=['POST'])
|
|
@app.route('/upload_local_file', methods=['POST'])
|
|
def upload_local_file():
|
|
def upload_local_file():
|
|
file_name = request.get_json()['file_name']
|
|
file_name = request.get_json()['file_name']
|
|
- if is_file_open_in_wps(os.path.join(current_app.config['work_path'], file_name)):
|
|
|
|
- return jsonify({'code': 3004, 'msg': '操作失败,文件已被打开无法操作'})
|
|
|
|
|
|
|
|
metadata = app.config['serve_client'].load_metadata(os.path.join(current_app.config['work_path'], file_name))
|
|
metadata = app.config['serve_client'].load_metadata(os.path.join(current_app.config['work_path'], file_name))
|
|
code = app.config['serve_client'].upload_file(os.path.join(current_app.config['work_path'], file_name))
|
|
code = app.config['serve_client'].upload_file(os.path.join(current_app.config['work_path'], file_name))
|
|
@@ -244,8 +214,6 @@ def upload_local_file():
|
|
@app.route('/update_local_file', methods=['POST'])
|
|
@app.route('/update_local_file', methods=['POST'])
|
|
def update_local_file():
|
|
def update_local_file():
|
|
file_name = request.get_json()['file_name']
|
|
file_name = request.get_json()['file_name']
|
|
- if is_file_open_in_wps(os.path.join(current_app.config['work_path'], file_name)):
|
|
|
|
- return jsonify({'code': 3004, 'msg': '操作失败,文件已被打开无法操作'})
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
metadata = current_app.config['serve_client'].load_metadata(os.path.join(current_app.config['work_path'], file_name))
|
|
metadata = current_app.config['serve_client'].load_metadata(os.path.join(current_app.config['work_path'], file_name))
|
|
@@ -355,9 +323,6 @@ def open_file():
|
|
if not os.path.exists(file_path):
|
|
if not os.path.exists(file_path):
|
|
return jsonify({'code': '3006', 'msg': '文件不存在'})
|
|
return jsonify({'code': '3006', 'msg': '文件不存在'})
|
|
|
|
|
|
- if is_file_open_in_wps(file_path):
|
|
|
|
- return jsonify({'code': 1000, 'msg': '检测到文件已被打开'})
|
|
|
|
-
|
|
|
|
return open_file_by_wps(file_path)
|
|
return open_file_by_wps(file_path)
|
|
|
|
|
|
|
|
|
|
@@ -432,10 +397,6 @@ def download_cloud_file():
|
|
|
|
|
|
return jsonify({'code': 1000, 'msg': '操作成功', 'file_path': local_file})
|
|
return jsonify({'code': 1000, 'msg': '操作成功', 'file_path': local_file})
|
|
|
|
|
|
- # 判断本地文件是否被打开
|
|
|
|
- if is_file_open_in_wps(local_file):
|
|
|
|
- return jsonify({'code': 2001, 'msg': '检测到文档正在被编辑,无法下载'})
|
|
|
|
-
|
|
|
|
# 判断本地文件和线上文件是否一致
|
|
# 判断本地文件和线上文件是否一致
|
|
local_file_metadata = current_app.config['serve_client'].load_metadata(local_file)
|
|
local_file_metadata = current_app.config['serve_client'].load_metadata(local_file)
|
|
if local_file_metadata['update_time'] == file_info['updateTime']:
|
|
if local_file_metadata['update_time'] == file_info['updateTime']:
|