dever 7 years ago
parent
commit
f9cd9670ce
3 changed files with 53 additions and 26 deletions
  1. 12 14
      front/api/main.py
  2. 15 0
      front/static/pdf2htmlEX.min.js
  3. 26 12
      service/convert.py

+ 12 - 14
front/api/main.py

@@ -46,7 +46,7 @@ class Common(object):
 
 		self.service = Demeter.service('convert')
 
-		self.referer = self.request.headers['referer']
+		self.referer = self.request.headers.get("Referer")
 		self.host = Demeter.host(self.data['site']['link'])
 
 		if not self.referer:
@@ -56,7 +56,7 @@ class Common(object):
 			self.out('验证失败')
 
 
-		self.param = self.service.signature(self.data['site']['id'], appid, self.data['site']['appsecret'], timestamp, nonce, file, file_id, uid)
+		self.param = self.service.signature(self.data['site']['id'], appid, self.data['site']['appsecret'], timestamp, nonce, file, file_id, uid, status)
 
 		if not self.param:
 			self.out('验证失败')
@@ -65,6 +65,7 @@ class Common(object):
 			self.out('验证失败')
 
 		if status == 1:
+			file_type = self.input('file_type')
 			file = self.service.update(self.data['site']['id'], self.data['site']['appid'], file, file_id, file_type, uid)
 		else:
 			file = self.service.get(self.data['site']['id'], self.data['site']['appid'], file);
@@ -175,8 +176,6 @@ class convert_path(Load):
 			config = Demeter.config['redis']
 			redis.rpush(config['name'], file['id'])
 
-		del self.data['site']['token']
-
 		url = self.request.protocol + "://" + self.request.host
 
 		self.data['file'] = {
@@ -187,7 +186,7 @@ class convert_path(Load):
 			'file' : file['key']
 		}
 
-		self.out('yes', self.data)
+		self.out('yes', self.data['file'])
 
 # 获取信息 后端接口,token不允许暴露
 class get_path(Load):
@@ -198,15 +197,13 @@ class get_path(Load):
 		self.data = {}
 		file = Common.signature(self, 2)
 
-		del self.data['site']['token']
-
 		url = self.request.protocol + "://" + self.request.host
 
 		self.data['file'] = {
 			#'id' : file['id'],
 			'status' : file['status'],
 			'url' : url + file['url'],
-			'pic' : url + file['url'] + '.jpg',
+			'img' : url + file['url'] + '.jpg',
 			'page' : file['page'],
 			'ext' : file['ext'],
 			'name' : file['name'],
@@ -214,7 +211,7 @@ class get_path(Load):
 			'size' : file['size']
 		}
 
-		self.out('yes', self.data)
+		self.out('yes', self.data['file'])
 
 # 授权用户可以访问html的接口 后端接口,token不允许暴露
 class auth_path(Load):
@@ -238,14 +235,16 @@ class view_path(Load):
 
 		appid = self.input('appid')
 		nonce = self.input('nonce')
+		timestamp = self.input('timestamp')
 		signature = self.input('signature')
 		file = self.input('file')
+		file_id = self.input('file_id')
 		uid = self.input('uid')
 		page = self.input('page')
 		path = self.input('path')
 
 		self.data = {}
-		file = Common.signature(self, 2)
+		file = Common.signature(self, 11)
 
 		if page:
 			url = self.request.protocol + "://" + self.request.host
@@ -277,14 +276,13 @@ class view_path(Load):
 					content = re.sub(pattern, '', content)
 
 				path = path.replace(Demeter.path + 'runtime', '')
-				url = url + '/main/view?path=' + str(path) + '&file=' + file['key'] + '&nonce=' + nonce + '&appid=' + appid + '&signature=' + signature + '&uid=' + uid + '&page='
+				url = url + '/main/view?path=' + str(path) + '&file=' + file['key'] + '&file_id=' + file_id + '&timestamp=' + timestamp + '&nonce=' + nonce + '&appid=' + appid + '&signature=' + signature + '&uid=' + uid + '&page='
 				content = content.replace('data-page-url="', 'data-page-url="' + url)
 
-				script = '<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>'
-				script = script + '<script>document.domain="'+self.host+'";$(function(){var e = pdf2htmlEX.defaultViewer;var page = e.pages.length;var original_height = 0;var height = e.container.clientHeight;for(var i in e.pages){height = height + e.pages[i].original_height;original_height = e.pages[i].original_height;};parent.setHeight(height, original_height, page)})</script>'
+				script = script + '<script>document.domain="'+self.host+'";</script>'
 				content = content.replace('</body>', script + '</body>')
 
-				style = '<style>#page-container{background-color: white;background-image: none;}#sidebar{background-color: white;background-image: none;}.pf{border:1px solid #bababa;box-shadow:none}</style>'
+				style = '<style>body{zoom:100%;}#page-container{background-color: white;background-image: none;overflow: hidden;}#sidebar{background-color: white;background-image: none;}.pf{margin-top:0px;margin-bottom:0px;border:0px solid #bababa;box-shadow:none}</style>'
 
 				content = content.replace('</head>', style + '<head>')
 

+ 15 - 0
front/static/pdf2htmlEX.min.js

@@ -335,6 +335,21 @@ Viewer.prototype = {
 
     this.initialize_radio_button();
     this.render();
+    if (parent) {
+      var e = this;
+      var page = e.pages.length;
+      var original_height = [];
+      var height = e.container.clientHeight;
+      var width = 0;
+      for (var i in e.pages) {
+        height = height + e.pages[i].original_height;
+        if (width < e.pages[i].original_width) {
+          width = e.pages[i].original_width
+        }
+        original_height.push(e.pages[i].original_height);
+      };
+      parent.docView(width, height, original_height, page);
+    }
   },
 
   /*

+ 26 - 12
service/convert.py

@@ -9,21 +9,22 @@ class Convert(object):
 		model.cdate.assign(num, exp='<=')
 		model.delete()
 
-	def signature(self, site_id, appid, appsecret, timestamp, nonce, file, file_id, uid):
+	def signature(self, site_id, appid, appsecret, timestamp, nonce, file, file_id, uid, status):
 		sign = Demeter.sha1(appid + '&' + appsecret + '&' + str(timestamp) + '&' + str(nonce) + '&' + file + '&' + str(file_id) + '&' + str(uid));
 
 		time = Demeter.time()
 		num = 3600*12
-		if time - timestamp > num:
+		if time - int(timestamp) > num:
 			return False
 
 		# sign 只能使用一次
-		model = Demeter.model('signature')
-		model.signature = sign
-		model.site_id = site_id
-		info = model.select(type='fetchone')
-		if info:
-			return False
+		if status < 10:
+			model = Demeter.model('signature')
+			model.signature = sign
+			model.site_id = site_id
+			info = model.select(type='fetchone')
+			if info:
+				return False
 
 		param = {}
 		param['signature'] = sign
@@ -35,9 +36,10 @@ class Convert(object):
 		param['file_id'] = file_id
 		param['uid'] = uid
 
-		model.signature = sign
-		model.site_id = site_id
-		model.insert()
+		if status < 10:
+			model.signature = sign
+			model.site_id = site_id
+			model.insert()
 
 		return param
 
@@ -114,6 +116,18 @@ class Convert(object):
 
 		return True
 
+	def get(self, site, appid, file):
+		convert = Demeter.model('convert')
+		convert.site_id = site
+		#convert.key = self.getKey(appid, file)
+		convert.key = file
+
+		data = convert.select(type='fetchone')
+
+		return data
+
+	def getKey(self, appid, file):
+		return Demeter.sha1(str(appid) + '_' + str(file))
 
 	def getFile(self, appid, file):
 		info = {}
@@ -258,7 +272,7 @@ class Convert(object):
 			appid = site['appid']
 			appsecret = site['appsecret']
 			timestamp = Demeter.time()
-			nonce = Demeter.nonce()
+			nonce = Demeter.hash()
 			file = info['key']
 			file_id = info['file_id']
 			uid = info['uid']