mirror of
https://github.com/thelounge/thelounge
synced 2024-12-12 13:42:32 +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 Utils = require("../../command-line/utils");
|
||||||
|
|
||||||
const stylesheets = [];
|
const stylesheets = [];
|
||||||
|
const files = [];
|
||||||
|
|
||||||
const TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes, in milliseconds
|
const TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes, in milliseconds
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ const cache = {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
getFiles,
|
||||||
getStylesheets,
|
getStylesheets,
|
||||||
getPackage,
|
getPackage,
|
||||||
loadPackages,
|
loadPackages,
|
||||||
|
@ -30,6 +32,9 @@ const packageApis = function(packageName) {
|
||||||
Stylesheets: {
|
Stylesheets: {
|
||||||
addFile: addStylesheet.bind(this, packageName),
|
addFile: addStylesheet.bind(this, packageName),
|
||||||
},
|
},
|
||||||
|
PublicFiles: {
|
||||||
|
add: addFile.bind(this, packageName),
|
||||||
|
},
|
||||||
Commands: {
|
Commands: {
|
||||||
add: inputs.addPluginCommand,
|
add: inputs.addPluginCommand,
|
||||||
runAsUser: (command, targetId, client) =>
|
runAsUser: (command, targetId, client) =>
|
||||||
|
@ -49,6 +54,14 @@ function getStylesheets() {
|
||||||
return stylesheets;
|
return stylesheets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addFile(packageName, filename) {
|
||||||
|
files.push(packageName + "/" + filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFiles() {
|
||||||
|
return files.concat(stylesheets);
|
||||||
|
}
|
||||||
|
|
||||||
function getPackage(name) {
|
function getPackage(name) {
|
||||||
return packageMap.get(name);
|
return packageMap.get(name);
|
||||||
}
|
}
|
||||||
|
@ -90,6 +103,10 @@ function loadPackages() {
|
||||||
|
|
||||||
if (packageInfo.type === "theme") {
|
if (packageInfo.type === "theme") {
|
||||||
themes.addTheme(packageName, packageInfo);
|
themes.addTheme(packageName, packageInfo);
|
||||||
|
|
||||||
|
if (packageInfo.files) {
|
||||||
|
packageInfo.files.forEach((file) => addFile(packageName, file));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
anyPlugins = true;
|
anyPlugins = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ module.exports = function() {
|
||||||
const fileName = req.params.filename;
|
const fileName = req.params.filename;
|
||||||
const packageFile = packages.getPackage(packageName);
|
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");
|
return res.status(404).send("Not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue