|
| 1 | +/* |
| 2 | + * GNU AGPL-3.0 License |
| 3 | + * |
| 4 | + * Modified Work Copyright (c) 2021 - present core.ai . All rights reserved. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU Affero General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License |
| 14 | + * for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Affero General Public License |
| 17 | + * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. |
| 18 | + * |
| 19 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 20 | + * of this software and associated documentation files (the "Software"), to deal |
| 21 | + * in the Software without restriction, including without limitation the rights |
| 22 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 23 | + * copies of the Software, and to permit persons to whom the Software is |
| 24 | + * furnished to do so, subject to the following conditions: |
| 25 | + * |
| 26 | + * The above copyright notice and this permission notice shall be included in all |
| 27 | + * copies or substantial portions of the Software. |
| 28 | + * |
| 29 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 30 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 31 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 32 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 33 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 34 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 35 | + * SOFTWARE. |
| 36 | + */ |
| 37 | + |
| 38 | +/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ |
| 39 | +/*global define, brackets, fs, Phoenix, path */ |
| 40 | +//jshint-ignore:no-start |
| 41 | + |
| 42 | +define(function (require, exports, module) { |
| 43 | + const ProjectManager = brackets.getModule("project/ProjectManager"), |
| 44 | + DocumentManager = brackets.getModule("document/DocumentManager"); |
| 45 | + |
| 46 | + function _isPreviewableFile(filePath) { |
| 47 | + let pathSplit = filePath.split('.'); |
| 48 | + let extension = pathSplit && pathSplit.length>1 ? pathSplit[pathSplit.length-1] : null; |
| 49 | + if(['html', 'htm', 'jpg', 'jpeg', 'png', 'svg', 'pdf'].includes(extension.toLowerCase())){ |
| 50 | + return true; |
| 51 | + } |
| 52 | + return false; |
| 53 | + } |
| 54 | + |
| 55 | + function getPreviewURL() { |
| 56 | + let projectRootName = ProjectManager.getProjectRoot().fullPath; |
| 57 | + let projectRootUrl = `${window.fsServerUrl}${projectRootName}`; |
| 58 | + let currentDocument = DocumentManager.getCurrentDocument(); |
| 59 | + let currentFile = currentDocument? currentDocument.file : ProjectManager.getSelectedItem(); |
| 60 | + let previewUrl = `${projectRootUrl}index.html`; |
| 61 | + if(currentFile){ |
| 62 | + let fullPath = currentFile.fullPath; |
| 63 | + if(_isPreviewableFile(fullPath)){ |
| 64 | + let projectRoot = ProjectManager.getProjectRoot().fullPath; |
| 65 | + let relativePath = path.relative(projectRoot, fullPath); |
| 66 | + previewUrl = `${projectRootUrl}${relativePath}`; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + return previewUrl; |
| 71 | + } |
| 72 | + |
| 73 | + exports.getPreviewURL = getPreviewURL; |
| 74 | +}); |
| 75 | + |
| 76 | + |
0 commit comments