参考教程:alist网盘增加onlyoffice_alist onlyoffice
由于各位的OpenList普遍使用https,因此OnlyOffice也需要启用https才可以正常访问,否则就会显示空白界面(无显式报错信息)。使用参考教程给出的私有镜像,docker命令如下:
sudo docker run -it -d \
-p 10000:443 \ # 将外部端口映射到容器内部的https端口
--restart=always \
--name onlyoffice \
-v /证书目录/fullchain.pem:/etc/onlyoffice/ssl/fullchain.pem \
-v /证书目录/privkey.pem:/etc/onlyoffice/ssl/privkey.pem \
-e SSL_CERTIFICATE_PATH=/etc/onlyoffice/ssl/fullchain.pem \
-e SSL_KEY_PATH=/etc/onlyoffice/ssl/privkey.pem \
-e JWT_ENABLED=false \ # 可无此行配置
registry.cn-chengdu.aliyuncs.com/software-yxl/onlyoffice:7.2
接下来,找一个目录创建view.html,写入以下内容:
<!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="https://你的域名:10000/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>
然后,使用你的Web服务器创建配置。由于我惯用Apache2,以下使用Apache2的配置作为示例。
Apache2启用监听的步骤
新建文件/etc/apache2/sites-available/onlyoffice-preview.conf,写入:
<VirtualHost *:10001>
DocumentRoot /view.html所在目录
# SSL 配置
SSLEngine on
SSLCertificateFile /证书目录
SSLCertificateKeyFile /证书目录
<Directory "/view.html所在目录">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/onlyoffice-preview-error.log
CustomLog ${APACHE_LOG_DIR}/onlyoffice-preview-access.log combined
</VirtualHost>
在ports.conf中添加一行“Listen 10001”,然后依次是:
sudo a2ensite onlyoffice-preview
sudo systemctl reload apache2
这样就大功告成了!打开你的OpenList,找到后台设置中的“预览”→“iframe预览”,添加OnlyOffice行,注意最好放在第一个:
{
"doc,docx,xls,xlsx,ppt,pptx": {
"OnlyOffice": "https://你的域名:10001/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": "https://你的域名:10001/view.html?src=$e_url"
},
"epub": {
"EPUB.js":"https://res.oplist.org/epub.js/viewer.html?url=$e_url"
}
}