当前位置:   article > 正文

alist配合onlyoffice 实现在线预览

alist配合onlyoffice 实现在线预览

alist配合onlyoffice 实现在线预览


一、安装onlyoffice

我是采用docker安装,采用的版本是7.2, aarch64 可以支持,端口号为 18081

docker run --restart=always --name onlyoffice \
    -p 18081:80 \
    -e JWT_ENABLED=false \
    -v /app/onlyoffice/DocumentServer/logs:/var/log/onlyoffice \
    -v /app/onlyoffice/DocumentServer/data:/var/www/onlyoffice/Data \
    -v /app/onlyoffice/DocumentServer/lib:/var/lib/onlyoffice \
    -v /app/onlyoffice/DocumentServer/db:/var/lib/postgresql \
    onlyoffice/documentserver:7.2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

二、增加view.html文件

创建文件夹

mkdir -p /opt/onlyoffice
  • 1
vim /opt/onlyoffice/view.html
  • 1

注意:配置文件中的主机IP需要修改为自己机器的IP

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>OnlyOffice Viewer</title>
</head>
 
<body>
    <div id="placeholder"></div>
    <script type="text/javascript" src="http://主机IP:18081/web-apps/apps/api/documents/api.js"></script>
    <script>
        function getQueryParamValue(name) {
            const searchParams = new URLSearchParams(window.location.search);
            return searchParams.get(name);
        }
 
        const url = decodeURIComponent(getQueryParamValue("src"));
        const fileName = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('?') != -1 ? url.lastIndexOf('?') : url.length);
        const fileExtension = fileName.split('.').pop();
        const docEditor = new DocsAPI.DocEditor("placeholder", {
            "document": {
                "fileType": fileExtension,
                "permissions": {
                    "edit": false,
                    "comment": true,
                    "download": true,
                    "print": true,
                    "fillForms": true,
                },
                "title": fileName,
                "url": url,
            },
            "editorConfig": {
                "lang": "zh-CN",
                "mode": "view",
            },
            "height": "1080px",
            "type": "desktop",
        });
    </script>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

三、安装nginx,并增加conf配置文件

sudo apt update
sudo apt install -y nginx
  • 1
  • 2

增加conf配置文件
vim /etc/nginx/conf.d/onlyoffice.conf

server {
    listen       18082;
    server_name  localhost;
 
    location / {
       root /opt/onlyoffice;  #这里修改为自己的view.html的目录
       index index.html index.htm;
    }
 
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

重启nginx

systemctl restart nginx 
  • 1

查看nginx状态

systemctl status nginx 
  • 1

四、alist预览配置增加

配置文件里面的主机IP,需要修改为安装onlyoffice 的ip

{
   "doc,docx,xls,xlsx,ppt,pptx": {
      "onlyoffice":"http://主机IP:18082/view.html?src=$e_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": {
      "onlyoffice":"http://主机IP:18082/view.html?src=$e_url",
      "PDF.js":"https://alist-org.github.io/pdf.js/web/viewer.html?file=$e_url"
   },
   "epub": {
      "EPUB.js":"https://alist-org.github.io/static/epub.js/viewer.html?url=$e_url"
   }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/670225
推荐阅读
  

闽ICP备14008679号