mirror of
https://github.com/thelounge/thelounge
synced 2024-12-03 17:29:14 +00:00
Merge pull request #3432 from thelounge/mcinkay/1537-plugin-files
Add public files for plugins
This commit is contained in:
commit
75f7666548
2 changed files with 18 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue