dever před 6 roky
rodič
revize
4225cb06fd

+ 109 - 39
front/api/main.py

@@ -235,62 +235,132 @@ class auth_path(Load):
 class view_path(Load):
 	@Web.setting
 	def get(self):
-		import re
-
-		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')
+		callback = self.input('callback')
+		source = self.input('source')
 
 		self.data = {}
 		file = Common.signature(self, 11)
 
+		# 读取源文件
+		user = self.service.getAuth(self.data['site']['id'], uid, file['id'])
+
+		limit = -1
+		if not user and file['file_type'] == 1:
+			# 没有文件信息,则有限制
+			limit = self.data['site']['page']
+
 		if page:
-			url = self.request.protocol + "://" + self.request.host
-			static = url + path
-			page = Demeter.path + 'runtime' + path + page
-			content = File.readContent(page)
-			content = content.replace('src="', 'src="' + str(static))
+			content = self.getPage(path, page, limit)
+		elif source:
+			content = self.getSource(file, limit, uid)
+		else:
+			content = self.getContent(file, limit, uid)
+
+		if callback:
+			self.out(content)
+		else:
+			self.write(content)
+
+	def getPage(self, path, page, limit):
+		num = page.replace('.page', '')
+		if limit > 0 and int(num) > limit:
+			self.out('您没有权限查看')
+		url = self.request.protocol + "://" + self.request.host
+		static = url + path
+		page = Demeter.path + 'runtime' + path + page
+		content = File.readContent(page)
+		content = content.replace('src="', 'src="' + str(static))
+		return content
+
+	def getContent(self, file, limit, uid):
+		if limit < 0:
+			limit = int(file['page'])
+		url = self.request.protocol + "://" + self.request.host
+		style = ['document.css']
+		script = ['jquery.js']
+		content = ''
+		static = self.static(url)
+		assets = self.assets(url, file['path'])
+
+		for i in style:
+			content = content + '<link rel="stylesheet" href="'+static+i+'"/>'
+
+		content = content + '<link rel="stylesheet" href="'+assets+file['key']+'.css"/>'
+
+		for i in script:
+			content = content + '<script src="'+static+i+'"></script>'
+
+		content = content + self.style()
+		content = content + '<div id="page-container">'
+		page_url = self.url(url, file['path'], file['key'], uid)
+		for i in range(limit):
+			n = str(i+1)
+			content = content + '<div id="pf'+n+'" style="display:none;" class="demeter_document pf w0 h0" data-page-no="'+n+'" data-page-url="'+page_url+n+'.page"></div>'
+
+		content = content + '</div>'
+		#content = content + '<script>try{pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({});}catch(e){}</script>'
+		return content
+
+
+	def getSource(self, file, limit, uid):
+		view = file['html'] + '_p' + str(limit) + '.html'
+		if File.exists(view):
+			content = File.readContent(view)
+			File.write(view, content)
 		else:
-			user = self.service.getAuth(self.data['site']['id'], uid, file['id'])
+			content = File.readContent(file['html'])
+			url = self.request.protocol + "://" + self.request.host
+
+			static = self.static(url) + 'pdf/'
+			content = content.replace('src="', 'src="' + static)
+			content = content.replace('href="', 'href="' + self.assets(url, file['path']))
+
+			if limit > 0:
+				content = self.pattern(limit,content)
+
+			content = content.replace('data-page-url="', 'data-page-url="' + self.url(url, file['path'], file['key'], uid))
 
-			limit = -1
-			if not user and file['file_type'] == 1:
-				# 没有文件信息,则有限制
-				limit = self.data['site']['page']
+			#content = self.domain(content)
 			
-			path = file['path']
-			view = file['html'] + '_p' + str(limit) + '.html'
-			if File.exists(view):
-				content = File.readContent(view)
-				File.write(view, content)
-			else:
-				url = self.request.protocol + "://" + self.request.host
-				static = url + '/static/'
-				content = File.readContent(file['html'])
-				content = content.replace('src="', 'src="' + static)
+			content = content.replace('</head>', self.style() + '<head>')
+		return content
+
+	def static(self, url):
+		return url + '/static/'
+
+	def assets(self, url, path):
+		path = path.replace(Demeter.path + 'runtime', '')
+		return url + path
+
+	def pattern(self, limit, content):
+		import re
+		pattern = '<div id="pf([0-9][a-zA-Z]+|[a-zA-Z0]+|['+str(limit+1)+'-9]|([1-9][0-9]+))"(.*?)<\/div>'
+		content = re.sub(pattern, '', content)
+		return content
 
-				if limit > 0:
-					pattern = '<div id="pf([0-9][a-zA-Z]+|[a-zA-Z0]+|['+str(limit+1)+'-9]|([1-9][0-9]+))"(.*?)<\/div>'
-					content = re.sub(pattern, '', content)
+	def domain(self, content):
+		script = '<script>document.domain="'+self.host+'";</script>'
+		content = content.replace('</body>', script + '</body>')
+		return content
 
-				path = path.replace(Demeter.path + 'runtime', '')
-				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)
+	def style(self):
+		return '<style>body{zoom:100%;}#page-container{position: static;background-color: white;background-image: none;overflow: hidden;}#sidebar{background-color: white;background-image: none;}.pf{border:1px solid #d3d3d3;box-shadow:none;width:98%}</style>'
 
-				script = '<script>document.domain="'+self.host+'";</script>'
-				content = content.replace('</body>', script + '</body>')
+	def url(self, url, path, key, uid):
+		appid = self.input('appid')
+		nonce = self.input('nonce')
+		timestamp = self.input('timestamp')
+		signature = self.input('signature')
+		file_id = self.input('file_id')
 
-				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>'
+		path = path.replace(Demeter.path + 'runtime', '')
 
-				content = content.replace('</head>', style + '<head>')
+		url = url + '/main/view?path=' + str(path) + '&file=' + key + '&file_id=' + file_id + '&timestamp=' + timestamp + '&nonce=' + nonce + '&appid=' + appid + '&signature=' + signature + '&uid=' + uid + '&page='
 
-		self.write(content)
+		return url
 
 # 下载源文件
 class down_path(Load):

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 298 - 0
front/static/document.css


+ 155 - 0
front/static/document.js

@@ -0,0 +1,155 @@
+/* ================================================================================
+ * document.js v1.0
+ * http://git.shemic.com/dever/script
+ * ================================================================================
+ * Copyright 2017-2018 Dever(dever.cc)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+
+//文档工具包
+var Document = 
+{
+    option : {},
+    reader : '#document',
+    show : 1,
+    page : 0,
+    width : 0,
+    Init : function(option)
+    {
+        var self = this;
+        self.Option(option);
+        $.getJSON(self.option.document + '&callback=?', function(t)
+        {
+            $(self.option.reader).html(t.msg);
+
+            self.width = $(self.option.reader).width();
+            if (self.option.tool) {
+                self.Tool();
+            }
+
+            self.Border();
+            self.Scroll();
+
+            $('.pf').each(function(i)
+            {
+                if (i < self.show) {
+                    self.Load(i);
+                }
+            });
+        });
+    }
+
+    ,Load : function(i)
+    {
+        var self = this;
+        self.page = i;
+        var doc = $('.pf').eq(i);
+        var url = doc.attr('data-page-url');
+        var parent = doc.parent();
+        $.getJSON(url + '&callback=?', function(t)
+        {
+            doc.prop('outerHTML', t.msg).show();
+            var e = $('.pf').eq(i);
+            var w = e.find('.w0').width();
+            if (w > self.width) {
+                var z = 100 - ((w - self.width)/10);
+                $(self.option.reader).css('zoom', z + '%');
+                self.width = w;
+            }
+            
+        });
+    }
+
+    ,Option : function(option)
+    {
+        this.option = option;
+        if (!this.option.border) {
+            this.option.border = 'yes';
+        }
+
+        if (this.option.reader) {
+            this.reader = this.option.reader;
+        }
+
+        if (this.option.show) {
+            this.show = this.option.show;
+        }
+    }
+
+    ,Border : function() {
+        if (this.option.border == 'no') {
+            $(this.option.reader).find('style').append('<style>.pf{border:0px;width:100%;}</style>');
+        }
+    }
+
+    ,Tool : function()
+    {
+        var html = '<div class="document-toolsbar-mod" style="visibility: visible;width: 98.2%; position: static;margin-top: 10px;margin-left: 8px;margin-bottom: -14px;"><div class="document-toolsbar-inner"><div class="document-toolsbar-content"><div class="document-toolsbar-nav" style="margin-left: 230px;"><a class="document-toolsbar-top" href="###" style="visibility: visible;"><b>top</b></a><input class="document-toolsbar-input" type="text" value="" style="visibility: visible;"><span class="document-toolsbar-pageCount" style="visibility: visible;">&nbsp;/&nbsp;3</span><a class="document-toolsbar-bottom" href="###" style="visibility: visible;"><b>bottom</b></a></div><div class="document-toolsbar-zoom"><a class="document-toolsbar-zoomin" href="###" style="visibility: visible;">zoom in</a><a class="document-toolsbar-zoomout" href="###" style="visibility: visible;">zoom out</a></div></div></div></div></div>';
+        $('#page-container').prepend(html);
+        this.Scoll();
+    }
+
+    ,Scroll : function()
+    {
+        var self = this;
+        var total = $('.pf').length;
+
+        if (self.option.more) {
+
+            if (self.page > total) {
+                $(self.option.more).hide();
+            } else {
+                $(self.option.more).show();
+                $(self.option.more).click(function()
+                {
+                    var p = self.page;
+                    for (var i = 1; i <= self.show; i++) {
+                        var page = p + i;
+                        self.MorePage(total-1, page);
+                        self.Load(page);
+                    }
+                });
+                self.MorePage(total, self.show);
+            }
+        } else {
+            $(window).scroll(function(){
+                var scroll = $(window).scrollTop();
+                var height = self.Height();
+                if (scroll >= height && self.page < total) {
+                    var page = self.page + 1;
+                    self.Load(page);
+                }
+            });
+        }
+    }
+
+    ,MorePage : function(total, page)
+    {
+        var num = total-page;
+        if (num <= 0) {
+            $(this.option.more).hide();
+        }
+        $(this.option.more + '_page').html(num);
+    }
+
+    ,Height : function()
+    {
+        var height = 0;
+        for (var i = 0; i < this.page; i++) {
+            height += $('.pf').eq(i).height();
+        }
+        return height;
+    }
+};

binární
front/static/img/api_icon.png


binární
front/static/img/api_loading.gif


binární
front/static/img/api_logo.png


binární
front/static/img/api_toolsbar_bg.png


binární
front/static/img/toolbar-icons.png


+ 0 - 0
front/static/compatibility.min.js → front/static/pdf/compatibility.min.js


+ 0 - 0
front/static/pdf2htmlEX-64x64.png → front/static/pdf/pdf2htmlEX-64x64.png


+ 0 - 0
front/static/pdf2htmlEX.min.js → front/static/pdf/pdf2htmlEX.min.js


+ 2 - 2
service/convert.py

@@ -196,8 +196,8 @@ class Convert(object):
 			convert = convert + ' && '
 		else:
 			info['pdf'] = info['local']
-		convert = convert + 'pdf2htmlEX --zoom 1.3 --no-drm 1 --split-pages 1 '
-		convert = convert + '--embed-css 0  --embed-javascript 0 --embed-image 0 --embed-font 0 --process-outline 0 '
+		convert = convert + 'pdf2htmlEX --zoom 1.5 --no-drm 1 --split-pages 1 '
+		convert = convert + '--embed-css 0  --embed-javascript 0 --embed-image 0 --embed-font 1 --process-outline 0 '
 		convert = convert + '--embed-external-font 0 --dest-dir '+info['path']+' --page-filename %d.page ' + info['pdf']
 
 		return convert

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů