侧边栏壁纸
  • 累计撰写 57 篇文章
  • 累计创建 43 个标签
  • 累计收到 85 条评论

目 录CONTENT

文章目录

docker安装kkFileView,并加入alist的Iframe预览

草莓牛奶
2023-04-15 / 0 评论 / 1 点赞 / 560 阅读 / 647 字 / 正在检测是否收录...
温馨提示:
「博客文章out of date 会及时更新,无特殊说明仍然有效,欢迎指正内容中的错误」

kkFileView - 在线文件预览 (keking.cn)是一款使用spring boot打造的文件文档在线预览项目解决方案,支持doc、docx、ppt、pptx、xls、xlsx、zip、rar、mp4、mp3以及众多类文本如txt、html、xml、java、properties、sql、js、md、json、conf、ini、vue、php、py、bat、gitignore等文件在线预览

kkFileView自2017年开源至今,已经支持23种文件类型,上百种文件后缀的文件在线预览

可以解决Alist无法预览文件的问题。

一、使用docker安装kkFileView

拉取镜像

# 网络环境方便访问docker中央仓库
docker pull keking/kkfileview:latest
docker run -it -p 8012:8012 keking/kkfileview:latest

浏览器访问容器8012端口 http://127.0.0.1:8012 即可看到项目演示用首页

Docker容器环境环境运行

二、Nginx反代

location /
{
    proxy_pass http://127.0.0.1:8012;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
}

三、配合Alist使用

以下主要解决alist自带的文件预览有时会无法访问
kkFileView的访问链接需要Base64处理

var url = 'http://127.0.0.1:8080/file/test.txt'; *//要预览文件的访问地址* 

window.open('http://127.0.0.1:8012/onlinePreview?url=' + encodeURIComponent(base64Encode(url)));

alist已经适配了增加外部预览的变量种类 · Issue #4090

对于外部 url,我们提供了一些变量供您使用:

基础变量:

  • $url: the file url
  • $durl: the file of alist URL
  • $name: the file name

拓展变量:
在基础变量前添加[eb_],其中e表示encodeURIComponent,b表示base64, 如

  • $e_url: encodeURIComponent($url)
  • $b_url: btoa($url)
  • $eb_url: encodeURIComponent(btoa($url))

所以只需要在alist管理→设置→预览→Iframe预览除加入kkFileView的访问链接,将url参数设置为$b_url

{
	"doc,docx,xls,xlsx,ppt,pptx": {
		"FileView":"https://【kkfileview的域名或IP】/onlinePreview?url=$b_url",
		"Microsoft":"https://view.officeapps.live.com/op/view.aspx?src=$e_url",
		"Google":"https://docs.google.com/gview?url=$e_url&embedded=true"
	},
	"pdf": {
		"PDF.js":"https://alist-org.github.io/pdf.js/web/viewer.html?file=$e_url",
		"FileView":"https://【kkfileview的域名或IP】/onlinePreviewEncoded?url=$b_url"
	},
	"epub": {
		"EPUB.js":"https://alist-org.github.io/static/epub.js/viewer.html?url=$e_url",
		"FileView":"https://【kkfileview的域名或IP】/onlinePreviewEncoded?url=$b_url"
	}
}

不需要使用该方法office文件、压缩文档等在线预览的新方案

1

评论区