|
@@ -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 + '×tamp=' + 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 + '×tamp=' + timestamp + '&nonce=' + nonce + '&appid=' + appid + '&signature=' + signature + '&uid=' + uid + '&page='
|
|
|
|
|
|
- self.write(content)
|
|
|
+ return url
|
|
|
|
|
|
# 下载源文件
|
|
|
class down_path(Load):
|