Merge pull request #3432 from thelounge/mcinkay/1537-plugin-files

Add public files for plugins
This commit is contained in:
Pavel Djundik 2019-10-03 16:30:09 +03:00 committed by GitHub
commit 75f7666548
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -11,6 +11,7 @@ const fs = require("fs");
const Utils = require("../../command-line/utils");
const stylesheets = [];
const files = [];
const TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes, in milliseconds
@ -19,6 +20,7 @@ const cache = {
};
module.exports = {
getFiles,
getStylesheets,
getPackage,
loadPackages,
@ -30,6 +32,9 @@ const packageApis = function(packageName) {
Stylesheets: {
addFile: addStylesheet.bind(this, packageName),
},
PublicFiles: {
add: addFile.bind(this, packageName),
},
Commands: {
add: inputs.addPluginCommand,
runAsUser: (command, targetId, client) =>
@ -49,6 +54,14 @@ function getStylesheets() {
return stylesheets;
}
function addFile(packageName, filename) {
files.push(packageName + "/" + filename);
}
function getFiles() {
return files.concat(stylesheets);
}
function getPackage(name) {
return packageMap.get(name);
}
@ -90,6 +103,10 @@ function loadPackages() {
if (packageInfo.type === "theme") {
themes.addTheme(packageName, packageInfo);
if (packageInfo.files) {
packageInfo.files.forEach((file) => addFile(packageName, file));
}
} else {
anyPlugins = true;
}

View file

@ -79,7 +79,7 @@ module.exports = function() {
const fileName = req.params.filename;
const packageFile = packages.getPackage(packageName);
if (!packageFile || !packages.getStylesheets().includes(`${packageName}/${fileName}`)) {
if (!packageFile || !packages.getFiles().includes(`${packageName}/${fileName}`)) {
return res.status(404).send("Not found");
}