mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-13 20:12:48 +00:00
perf: 优化文件预览
This commit is contained in:
parent
f63c2da37a
commit
6ee1824410
@ -302,60 +302,78 @@ class IndexController extends InvokeController
|
|||||||
abort(404);
|
abort(404);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
if (file_exists($file)) {
|
if (!file_exists($file)) {
|
||||||
parse_str($data['query'], $query);
|
abort(404);
|
||||||
$name = Arr::get($query, 'name');
|
}
|
||||||
$ext = strtolower(Arr::get($query, 'ext'));
|
//
|
||||||
$userAgent = strtolower(Request::server('HTTP_USER_AGENT'));
|
parse_str($data['query'], $query);
|
||||||
if ($ext === 'pdf') {
|
$name = Arr::get($query, 'name');
|
||||||
// 文件超过 10m 不支持在线预览,提示下载
|
$ext = strtolower(Arr::get($query, 'ext'));
|
||||||
if (filesize($file) > 10 * 1024 * 1024) {
|
$userAgent = strtolower(Request::server('HTTP_USER_AGENT'));
|
||||||
return view('download', [
|
if ($ext === 'pdf') {
|
||||||
'name' => $name,
|
// 文件超过 10m 不支持在线预览,提示下载
|
||||||
'size' => Base::readableBytes(filesize($file)),
|
if (filesize($file) > 10 * 1024 * 1024) {
|
||||||
'url' => Base::fillUrl($path),
|
return view('download', [
|
||||||
'button' => Doo::translate('点击下载'),
|
'name' => $name,
|
||||||
]);
|
'size' => Base::readableBytes(filesize($file)),
|
||||||
}
|
'url' => Base::fillUrl($path),
|
||||||
// 浏览器类型
|
'button' => Doo::translate('点击下载'),
|
||||||
$browser = 'none';
|
|
||||||
if (str_contains($userAgent, 'chrome')) {
|
|
||||||
$browser = str_contains($userAgent, 'android') || str_contains($userAgent, 'harmonyos') ? 'android-mobile' : 'chrome-desktop';
|
|
||||||
} elseif (str_contains($userAgent, 'safari') || str_contains($userAgent, 'iphone') || str_contains($userAgent, 'ipad')) {
|
|
||||||
$browser = str_contains($userAgent, 'iphone') || str_contains($userAgent, 'ipad') ? 'safari-mobile' : 'safari-desktop';
|
|
||||||
}
|
|
||||||
// electron 直接在线预览查看
|
|
||||||
if (str_contains($userAgent, 'electron') || str_contains($browser, 'desktop')) {
|
|
||||||
return Response::download($file, $name, [
|
|
||||||
'Content-Type' => 'application/pdf'
|
|
||||||
], 'inline');
|
|
||||||
}
|
|
||||||
// EEUI App 直接在线预览查看
|
|
||||||
if (str_contains($userAgent, 'eeui') && Base::judgeClientVersion("0.34.47")) {
|
|
||||||
if ($browser === 'safari-mobile') {
|
|
||||||
$message = Base::array2json([
|
|
||||||
'type' => 'currentOpen',
|
|
||||||
'url' => Base::fillUrl($path),
|
|
||||||
]);
|
|
||||||
return "<script>window.top.postMessage($message, '*')</script>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
if (in_array($ext, File::localExt)) {
|
|
||||||
$url = Base::fillUrl($path);
|
|
||||||
} else {
|
|
||||||
$url = 'http://' . env('APP_IPPR') . '.3/' . $path;
|
|
||||||
}
|
|
||||||
if ($ext !== 'pdf') {
|
|
||||||
$url = Base::urlAddparameter($url, [
|
|
||||||
'fullfilename' => $name . '.' . $ext
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$toUrl = Base::fillUrl("fileview/onlinePreview?url=" . urlencode(base64_encode($url)));
|
// 浏览器类型
|
||||||
return Redirect::to($toUrl, 301);
|
$browser = 'none';
|
||||||
|
if (str_contains($userAgent, 'chrome')) {
|
||||||
|
$browser = str_contains($userAgent, 'android') || str_contains($userAgent, 'harmonyos') ? 'android-mobile' : 'chrome-desktop';
|
||||||
|
} elseif (str_contains($userAgent, 'safari') || str_contains($userAgent, 'iphone') || str_contains($userAgent, 'ipad')) {
|
||||||
|
$browser = str_contains($userAgent, 'iphone') || str_contains($userAgent, 'ipad') ? 'safari-mobile' : 'safari-desktop';
|
||||||
|
}
|
||||||
|
// electron 直接在线预览查看
|
||||||
|
if (str_contains($userAgent, 'electron') || str_contains($browser, 'desktop')) {
|
||||||
|
return Response::download($file, $name, [
|
||||||
|
'Content-Type' => 'application/pdf'
|
||||||
|
], 'inline');
|
||||||
|
}
|
||||||
|
// EEUI App 直接在线预览查看
|
||||||
|
if (str_contains($userAgent, 'eeui') && Base::judgeClientVersion("0.34.47")) {
|
||||||
|
if ($browser === 'safari-mobile') {
|
||||||
|
$redirectUrl = Base::fillUrl($path);
|
||||||
|
return <<<EOF
|
||||||
|
<script>
|
||||||
|
let t = window.top
|
||||||
|
let \$A = null
|
||||||
|
while (t) {
|
||||||
|
if (t.\$A) {
|
||||||
|
\$A = t.\$A
|
||||||
|
break
|
||||||
|
}
|
||||||
|
t = t.top
|
||||||
|
}
|
||||||
|
if (\$A) {
|
||||||
|
\$A.eeuiAppSendMessage({
|
||||||
|
action: 'setPageData',
|
||||||
|
data: {
|
||||||
|
titleFixed: true,
|
||||||
|
urlFixed: true,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
t.location.href = "{$redirectUrl}"
|
||||||
|
</script>
|
||||||
|
EOF;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
abort(404);
|
//
|
||||||
|
if (in_array($ext, File::localExt)) {
|
||||||
|
$url = Base::fillUrl($path);
|
||||||
|
} else {
|
||||||
|
$url = 'http://' . env('APP_IPPR') . '.3/' . $path;
|
||||||
|
}
|
||||||
|
$url = Base::urlAddparameter($url, [
|
||||||
|
'fullfilename' => Base::rightDelete($name, '.' . $ext) . '_' . filemtime($file) . '.' . $ext
|
||||||
|
]);
|
||||||
|
$redirectUrl = Base::fillUrl("fileview/onlinePreview?url=" . urlencode(base64_encode($url)));
|
||||||
|
return Redirect::to($redirectUrl, 301);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -104,7 +104,7 @@ services:
|
|||||||
|
|
||||||
fileview:
|
fileview:
|
||||||
container_name: "dootask-fileview-${APP_ID}"
|
container_name: "dootask-fileview-${APP_ID}"
|
||||||
image: "kuaifan/fileview:4.2.0-SNAPSHOT-RC22"
|
image: "kuaifan/fileview:4.2.0-SNAPSHOT-RC23"
|
||||||
environment:
|
environment:
|
||||||
KK_CONTEXT_PATH: "/fileview"
|
KK_CONTEXT_PATH: "/fileview"
|
||||||
KK_OFFICE_PREVIEW_SWITCH_DISABLED: true
|
KK_OFFICE_PREVIEW_SWITCH_DISABLED: true
|
||||||
|
|||||||
@ -61,14 +61,12 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
window.addEventListener('resize', this.windowSizeListener);
|
window.addEventListener('resize', this.windowSizeListener);
|
||||||
window.addEventListener('scroll', this.windowScrollListener);
|
window.addEventListener('scroll', this.windowScrollListener);
|
||||||
window.addEventListener('message', this.windowHandleMessage)
|
|
||||||
this.searchInter = setInterval(this.searchEnter, 1000);
|
this.searchInter = setInterval(this.searchEnter, 1000);
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
window.removeEventListener('resize', this.windowSizeListener);
|
window.removeEventListener('resize', this.windowSizeListener);
|
||||||
window.removeEventListener('scroll', this.windowScrollListener);
|
window.removeEventListener('scroll', this.windowScrollListener);
|
||||||
window.removeEventListener('message', this.windowHandleMessage)
|
|
||||||
this.searchInter && clearInterval(this.searchInter);
|
this.searchInter && clearInterval(this.searchInter);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -238,15 +236,6 @@ export default {
|
|||||||
this.$store.state.windowScrollY = window.scrollY
|
this.$store.state.windowScrollY = window.scrollY
|
||||||
},
|
},
|
||||||
|
|
||||||
windowHandleMessage({data}) {
|
|
||||||
data = $A.jsonParse(data);
|
|
||||||
if (data.type === 'currentOpen') {
|
|
||||||
if ($A.getDomain(window.location.href) === $A.getDomain(data.url) || $A.getDomain($A.apiUrl('../')) === $A.getDomain(data.url)) {
|
|
||||||
window.location.href = data.url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
electronEvents() {
|
electronEvents() {
|
||||||
if (!this.$Electron) {
|
if (!this.$Electron) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Subproject commit a6ebc5ab089fab50e95ae614487782b69566412e
|
Subproject commit cdbbf1f0e237d6b38713ed327d974177fcae9f85
|
||||||
Loading…
x
Reference in New Issue
Block a user