# alist-adaptor **Repository Path**: DoubleTee/alist-adaptor ## Basic Information - **Project Name**: alist-adaptor - **Description**: alist 预览服务适配器 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-02-18 - **Last Updated**: 2026-01-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # alist adaptor > 适配 alist 私有化预览等功能 ## 预览器配置 > 示例中的 `http://localhost:40888` 为本服务地址,请根据部署变更地址 ``` json { "ppt": { "Microsoft":"https://view.officeapps.live.com/op/view.aspx?src=$e_url", "Google":"https://docs.google.com/gview?url=$e_url&embedded=true" }, "pptx": { "PPTXjs":"http://localhost:40888/previewer/pptxjs/viewer.html?url=$e_url" }, "xls,xlsx": { "LuckySheet":"http://localhost:40888/previewer/luckysheet-preview.html?url=$e_url", "vue-excel":"http://localhost:40888/previewer/vue-excel/index.html?url=$e_url", "x-data-spreadsheet":"http://localhost:40888/previewer/xlsx-preview.html?url=$e_url" }, "doc,docx": { "ToPDF.js":"http://localhost:40888/previewer/pdfjs/web/viewer.html?api=%2Fapi%2Fpreviewer%2Fconvert%2Fword2PDF%3FdecodeUrl%3Dtrue%26url%3D&file=$e_url", "ToPDF":"http://localhost:40888/api/previewer/convert/word2PDF?decodeUrl=true&url=$e_url", "ToJs":"http://localhost:40888/previewer/docx-preview.html?url=$e_url" }, "pdf": { "PDF.js":"http://localhost:40888/previewer/pdfjs/web/viewer.html?file=$e_url", "Native":"http://localhost:40888/api/previewer/direct?decodeUrl=true&url=$e_url" }, "epub": { "EPUB.js":"http://localhost:40888/previewer/epub/viewer.html?url=$e_url" }, "txt,java,sql,properties,xml,ini,html,go,bat,sh,cmd,js,css,md,json": { "MonacoEditor":"http://localhost:40888/previewer/monaco-editor/index.html?url=$e_url" }, "ofd": { "ofd-view":"http://localhost:40888/previewer/ofd-view/ofdview.html?url=$e_url", "ofd.js":"http://localhost:40888/previewer/ofd/index.html?url=$e_url" }, "zip,rar": { "zip preview":"http://localhost:40888/previewer/zip-preview.html?url=$e_url" },"drawio":{ "drawio editor":"http://localhost:40888/previewer/drawio/index.html?dev=1&save2Url=true&fn=$name&url=$e_url", "drawio preview":"http://localhost:40888/previewer/drawio-viewer/index.html?url=$e_url" } } ``` ## draw.io * 修改内容 * main.js ```js window.mxLanguage = 'zh'; window.PROXY_URL = '/api/previewer/direct' App.main((ui) => { var urlParams = (function() { var result = new Object(); var params = window.location.search.slice(1).split('&'); for (var i = 0; i < params.length; i++) { var idx = params[i].indexOf('='); if (idx > 0) { result[params[i].substring(0, idx)] = params[i].substring(idx + 1); } } return result; })(); setTimeout(_ => { ui.currentFile.rename(decodeURIComponent(urlParams['fn']), null,null); },500); }); ``` * App.js ``` js // mxscript('https://apis.google.com/js/api.js'); // mxscript(App.ONEDRIVE_URL); // mxscript('https://apis.google.com/js/api.js?onload=DrawGapiClientCallback', null, null, null, mxClient.IS_SVG); // mxscript(App.DROPBOX_URL, function() // { // // Must load this after the dropbox SDK since they use the same namespace // mxscript(App.DROPINS_URL, function() // { // DrawDropboxClientCallback(); // }, 'dropboxjs', App.DROPBOX_APPKEY); // }); // mxscript(App.ONEDRIVE_URL, window.DrawOneDriveClientCallback); if ((window.location.hash == null || window.location.hash.length <= 1) && urlParams['url'] != null) { let furl = urlParams['url']; furl += encodeURIComponent('&alist_ts=' + new Date().getTime()); this.loadFile('U' + furl, true); } if (!this.editor.isCorsEnabledForUrl(realUrl)) { base64 = binary || isVisioFilename; var nocache = 't=' + new Date().getTime(); realUrl = PROXY_URL + '?decodeUrl=true&url=' + encodeURIComponent(url) + '&' + nocache + ((base64) ? '&base64=1' : ''); } ``` * Actions.js ```js let doSave2Url = function(){ if (ui.editor.graph.isEditing()) { ui.editor.graph.stopEditing(); } // 获取当前图表的 XML 字符串 var xml = mxUtils.getXml(ui.editor.getGraphXml()); // 1. 创建 Blob var blob = new Blob([xml], { type: 'application/xml' }); // 2. (可选)创建 File 对象,指定文件名 var file = new File([blob], 'example.xml', { type: 'application/xml', lastModified: Date.now(), }); // 创建FormData对象并附加文件 let formData = new FormData(); formData.append('file', file); let _path = decodeURIComponent(location.hash.substring(2)); var urlObj = new URL(_path) || ''; _path = urlObj.pathname; if(_path && _path.indexOf('/p/') == 0){ _path = _path.substring(2); } // 定义上传文件的服务器端点 let uploadUrl = location.pathname.substr(0,location.pathname.indexOf('/previewer/')) + '/api/previewer/direct?decodeUrl=true&url='+encodeURIComponent(_path); // 使用Fetch API发送文件 let spinner = ui.createSpinner(null,null,24); spinner.spin(document.body, '保存中...') fetch(uploadUrl, { method: 'POST', body: formData }).then(response => response.json()) .then(data => { console.log('文件上传成功:', data); ui.clearStatus(); }) .catch (error => { console.error('上传过程中出现错误:', error); alert('上传过程中出现错误:'+error); }).finally(_ => { spinner.stop(); }); }; this.addAction('save', function() { if(urlParams['save2Url'] == 'true'){ doSave2Url(); } }); this.addAction('saveAs...', function() { if(urlParams['save2Url'] == 'true'){ doSave2Url(); } }); if (urlParams['dev'] == '1' || EditorUi.isElectronApp) //TODO check if we can remove these scripts loading from index.html { // realMain(); mxStencilRegistry.allowEval = false; App.loadScripts(['js/shapes-14-6-5.min.js', 'js/stencils.min.js', 'js/extensions.min.js'], realMain, function(e) { document.body.innerHTML = ''; var pre = document.createElement('pre'); mxUtils.write(pre, e.stack); document.body.appendChild(pre); }); } ``` * ...\diagramly\Menus.js ```js // menu.addItem(mxResources.get('googleDrive') + '...', null, function() // { // editorUi.pickFile(App.MODE_GOOGLE); // }, parent); ```