Bug fix and verb standardization
This commit is contained in:
@@ -11,7 +11,7 @@ const getSearchHistory = async (_req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const addSearchHistoryItem = async (req, res) => {
|
||||
const createSearchHistoryItem = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.searchHistory (prefix, provider, searchTerm) VALUES (${escapeString(req.body.prefix)}, ${escapeString(req.body.provider)}, ${escapeString(req.body.searchTerm)})`;
|
||||
conn
|
||||
@@ -41,6 +41,6 @@ const deleteSearchHistoryItem = async (req, res) => {
|
||||
|
||||
module.exports = {
|
||||
getSearchHistory,
|
||||
addSearchHistoryItem,
|
||||
createSearchHistoryItem,
|
||||
deleteSearchHistoryItem,
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ const getEnabledApplications = async (_req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const postApplication = async (req, res) => {
|
||||
const createApplication = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.applications (name, url, icon, baseUrl, filterName, enabled, \`index\`) VALUES (${escapeString(req.body.name)}, ${escapeString(req.body.url)}, ${escapeString(req.body.icon)}, ${escapeString(req.body.baseUrl)}, ${escapeString(req.body.filterName)}, ${req.body.enabled}, ${req.body.index});`;
|
||||
conn
|
||||
@@ -34,7 +34,7 @@ const postApplication = async (req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const patchApplication = async (req, res) => {
|
||||
const updateApplication = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.applications SET name = ${escapeString(req.body.name)}, url = ${escapeString(req.body.url)}, icon = ${escapeString(req.body.icon)}, baseUrl = ${escapeString(req.body.baseUrl)}, filterName = ${escapeString(req.body.filterName)}, enabled = ${req.body.enabled} WHERE id = ${req.body.id};`;
|
||||
conn
|
||||
@@ -91,8 +91,8 @@ const updateApplicationOrder = async (req, res) => {
|
||||
module.exports = {
|
||||
getApplications,
|
||||
getEnabledApplications,
|
||||
postApplication,
|
||||
patchApplication,
|
||||
createApplication,
|
||||
updateApplication,
|
||||
deleteApplication,
|
||||
getAppCategories,
|
||||
updateApplicationOrder,
|
||||
|
||||
@@ -10,7 +10,7 @@ const getBookmarks = async (_req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const postBookmark = async (req, res) => {
|
||||
const createBookmark = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.bookmarks (name, url, category, \`index\`, enabled) VALUES (${escapeString(req.body.name)}, ${escapeString(req.body.url)}, ${escapeString(req.body.category)}, ${req.body.index}, ${req.body.enabled});`;
|
||||
conn
|
||||
@@ -24,7 +24,7 @@ const postBookmark = async (req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const patchBookmark = async (req, res) => {
|
||||
const updateBookmark = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.bookmarks SET name = ${escapeString(req.body.name)}, url = ${escapeString(req.body.url)}, category = ${escapeString(req.body.category)}, \`index\` = ${req.body.index}, enabled = ${req.body.enabled} WHERE id = ${req.body.id}`;
|
||||
conn
|
||||
@@ -65,7 +65,7 @@ const deleteBookmark = async (req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const patchBookmarkOrder = async (req, res) => {
|
||||
const updateBookmarkOrder = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
req.body.map(async (link) => {
|
||||
return conn
|
||||
@@ -90,7 +90,7 @@ const getBookmarkCategories = async (_req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const postBookmarkCategory = async (req, res) => {
|
||||
const createBookmarkCategory = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.bookmarkCategories (categoryName, categoryIndex, filterName) VALUES (${escapeString(req.body.categoryName)},${req.body.categoryIndex || 0},${escapeString(req.body.filterName)})`;
|
||||
conn.query(query).then((_rows) => {
|
||||
@@ -99,7 +99,7 @@ const postBookmarkCategory = async (req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const patchBookmarkCategory = async (req, res) => {
|
||||
const updateBookmarkCategory = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.bookmarkCategories SET categoryName = ${escapeString(req.body.categoryName)}, filterName = ${escapeString(req.body.filterName)}, enabled = ${req.body.enabled} WHERE id = ${req.body.id};`;
|
||||
conn
|
||||
@@ -127,7 +127,7 @@ const deleteBookmarkCategory = async (req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const patchBookmarkCategoryOrder = async (req, res) => {
|
||||
const updateBookmarkCategoryOrder = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
req.body.map(async (category) => {
|
||||
return conn
|
||||
@@ -145,13 +145,13 @@ const patchBookmarkCategoryOrder = async (req, res) => {
|
||||
|
||||
module.exports = {
|
||||
getBookmarks,
|
||||
postBookmark,
|
||||
patchBookmark,
|
||||
createBookmark,
|
||||
updateBookmark,
|
||||
deleteBookmark,
|
||||
patchBookmarkOrder,
|
||||
updateBookmarkOrder,
|
||||
getBookmarkCategories,
|
||||
postBookmarkCategory,
|
||||
patchBookmarkCategory,
|
||||
createBookmarkCategory,
|
||||
updateBookmarkCategory,
|
||||
deleteBookmarkCategory,
|
||||
patchBookmarkCategoryOrder,
|
||||
updateBookmarkCategoryOrder,
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ const getDisplayedGreeting = async (_req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const postMessage = async (req, res) => {
|
||||
const createMessage = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.messages (message) VALUES (${escapeString(req.body.message)});`;
|
||||
conn
|
||||
@@ -34,7 +34,7 @@ const postMessage = async (req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const patchMessage = async (req, res) => {
|
||||
const updateMessage = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.messages SET message = ${escapeString(req.body.message)}, customGreeting = ${req.body.customGreeting} WHERE id = ${req.body.id};`;
|
||||
conn
|
||||
@@ -65,7 +65,7 @@ const deleteMessage = async (req, res) => {
|
||||
module.exports = {
|
||||
getMessages,
|
||||
getDisplayedGreeting,
|
||||
postMessage,
|
||||
patchMessage,
|
||||
createMessage,
|
||||
updateMessage,
|
||||
deleteMessage,
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ const getDefaultProvider = async (_req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const postProvider = async (req, res) => {
|
||||
const createProvider = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
if (req.body.default === true || req.body.default === 1) {
|
||||
const query = `UPDATE trigger_database.providers SET \`default\` = 0;`;
|
||||
@@ -37,7 +37,7 @@ const postProvider = async (req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const patchProvider = async (req, res) => {
|
||||
const updateProvider = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
if (req.body.default === true || req.body.default === 1) {
|
||||
const query = `UPDATE trigger_database.providers SET \`default\` = 0;`;
|
||||
@@ -72,7 +72,7 @@ const deleteProvider = async (req, res) => {
|
||||
module.exports = {
|
||||
getProviders,
|
||||
getDefaultProvider,
|
||||
postProvider,
|
||||
patchProvider,
|
||||
createProvider,
|
||||
updateProvider,
|
||||
deleteProvider,
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ const getThemes = async (_req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const addTheme = async (req, res) => {
|
||||
const createTheme = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.themes (name, backgroundImage, backgroundColor, searchColor, primaryColor, accentColor, borderColor, themeFont) VALUES (${escapeString(req.body.name)},${escapeString(req.body.backgroundImage)},${escapeString(req.body.backgroundColor)},${escapeString(req.body.searchColor)},${escapeString(req.body.primaryColor)},${escapeString(req.body.accentColor)},${escapeString(req.body.borderColor)},${escapeString(req.body.themeFont)})`;
|
||||
conn
|
||||
@@ -62,7 +62,7 @@ const getThemePlaylists = async (_req, res) => {
|
||||
conn.end();
|
||||
};
|
||||
|
||||
const addThemePlaylist = async (req, res) => {
|
||||
const createThemePlaylist = async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.themePlaylists (name, themeList) VALUES (${escapeString(req.body.name)},${escapeString(req.body.themeList)});`;
|
||||
conn
|
||||
@@ -111,12 +111,12 @@ const getBackgrounds = async (_req, res) => {
|
||||
(_err, files) => {
|
||||
res
|
||||
.status(200)
|
||||
.send(files.filter((file) => file.isFile()).map((file) => file.name));
|
||||
.send(files?.filter((file) => file.isFile()).map((file) => file.name));
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const uploadBackground = async (req, res) => {
|
||||
const addBackground = async (req, res) => {
|
||||
const image = req.file.path;
|
||||
const thumbnail = `${req.file.destination}thumbs/${req.file.filename}`;
|
||||
exec(`convert ${image} -resize 'x1080' -define jpeg:extent=300kb ${image}`);
|
||||
@@ -177,15 +177,15 @@ const deleteBackground = async (req, res) => {
|
||||
|
||||
module.exports = {
|
||||
getThemes,
|
||||
addTheme,
|
||||
createTheme,
|
||||
updateTheme,
|
||||
deleteTheme,
|
||||
getThemePlaylists,
|
||||
addThemePlaylist,
|
||||
createThemePlaylist,
|
||||
updateThemePlaylist,
|
||||
deleteThemePlaylist,
|
||||
getBackgrounds,
|
||||
uploadBackground,
|
||||
addBackground,
|
||||
updateBackground,
|
||||
deleteBackground,
|
||||
};
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
require("dotenv").config();
|
||||
const express = require("express");
|
||||
const cors = require("cors");
|
||||
const _wol = require("wol");
|
||||
const mariadb = require("mariadb");
|
||||
const bodyParser = require("body-parser");
|
||||
const _escapeString = require("sql-escape-string");
|
||||
const multer = require("multer");
|
||||
|
||||
const pool = mariadb.createPool({
|
||||
@@ -27,50 +25,50 @@ const {
|
||||
const {
|
||||
getMessages,
|
||||
getDisplayedGreeting,
|
||||
postMessage,
|
||||
patchMessage,
|
||||
createMessage,
|
||||
updateMessage,
|
||||
deleteMessage,
|
||||
} = require("./commands/messageData.cjs");
|
||||
const {
|
||||
getApplications,
|
||||
getEnabledApplications,
|
||||
postApplication,
|
||||
patchApplication,
|
||||
createApplication,
|
||||
updateApplication,
|
||||
deleteApplication,
|
||||
getAppCategories,
|
||||
updateApplicationOrder,
|
||||
} = require("./commands/applicationData.cjs");
|
||||
const {
|
||||
getBookmarks,
|
||||
postBookmark,
|
||||
patchBookmark,
|
||||
createBookmark,
|
||||
updateBookmark,
|
||||
deleteBookmark,
|
||||
patchBookmarkOrder,
|
||||
updateBookmarkOrder,
|
||||
getBookmarkCategories,
|
||||
postBookmarkCategory,
|
||||
patchBookmarkCategory,
|
||||
createBookmarkCategory,
|
||||
updateBookmarkCategory,
|
||||
deleteBookmarkCategory,
|
||||
patchBookmarkCategoryOrder,
|
||||
updateBookmarkCategoryOrder,
|
||||
} = require("./commands/bookmarkData.cjs");
|
||||
const {
|
||||
getProviders,
|
||||
getDefaultProvider,
|
||||
postProvider,
|
||||
patchProvider,
|
||||
createProvider,
|
||||
updateProvider,
|
||||
deleteProvider,
|
||||
} = require("./commands/providerData.cjs");
|
||||
|
||||
const {
|
||||
getThemes,
|
||||
addTheme,
|
||||
createTheme,
|
||||
updateTheme,
|
||||
deleteTheme,
|
||||
getThemePlaylists,
|
||||
addThemePlaylist,
|
||||
createThemePlaylist,
|
||||
updateThemePlaylist,
|
||||
deleteThemePlaylist,
|
||||
getBackgrounds,
|
||||
uploadBackground,
|
||||
addBackground,
|
||||
updateBackground,
|
||||
deleteBackground,
|
||||
} = require("./commands/themeData.cjs");
|
||||
@@ -92,7 +90,7 @@ const {
|
||||
|
||||
const {
|
||||
getSearchHistory,
|
||||
addSearchHistoryItem,
|
||||
createSearchHistoryItem,
|
||||
deleteSearchHistoryItem,
|
||||
} = require("./commands/SearchData.cjs");
|
||||
|
||||
@@ -139,9 +137,9 @@ app.get(`/${process.env.API_URI}/api/messages`, getMessages);
|
||||
|
||||
app.get(`/${process.env.API_URI}/api/displayedGreeting`, getDisplayedGreeting);
|
||||
|
||||
app.post(`/${process.env.API_URI}/api/messages`, postMessage);
|
||||
app.post(`/${process.env.API_URI}/api/messages`, createMessage);
|
||||
|
||||
app.patch(`/${process.env.API_URI}/api/messages`, patchMessage);
|
||||
app.patch(`/${process.env.API_URI}/api/messages`, updateMessage);
|
||||
|
||||
app.delete(`/${process.env.API_URI}/api/messages`, deleteMessage);
|
||||
|
||||
@@ -156,9 +154,9 @@ app.get(
|
||||
getEnabledApplications,
|
||||
);
|
||||
|
||||
app.post(`/${process.env.API_URI}/api/applications`, postApplication);
|
||||
app.post(`/${process.env.API_URI}/api/applications`, createApplication);
|
||||
|
||||
app.patch(`/${process.env.API_URI}/api/applications`, patchApplication);
|
||||
app.patch(`/${process.env.API_URI}/api/applications`, updateApplication);
|
||||
|
||||
app.delete(`/${process.env.API_URI}/api/applications`, deleteApplication);
|
||||
|
||||
@@ -175,13 +173,13 @@ app.patch(
|
||||
|
||||
app.get(`/${process.env.API_URI}/api/bookmarks`, getBookmarks);
|
||||
|
||||
app.post(`/${process.env.API_URI}/api/bookmarks`, postBookmark);
|
||||
app.post(`/${process.env.API_URI}/api/bookmarks`, createBookmark);
|
||||
|
||||
app.patch(`/${process.env.API_URI}/api/bookmarks`, patchBookmark);
|
||||
app.patch(`/${process.env.API_URI}/api/bookmarks`, updateBookmark);
|
||||
|
||||
app.delete(`/${process.env.API_URI}/api/bookmarks`, deleteBookmark);
|
||||
|
||||
app.patch(`/${process.env.API_URI}/api/bookmarkOrder`, patchBookmarkOrder);
|
||||
app.patch(`/${process.env.API_URI}/api/bookmarkOrder`, updateBookmarkOrder);
|
||||
|
||||
app.get(
|
||||
`/${process.env.API_URI}/api/bookmarkCategories`,
|
||||
@@ -190,12 +188,12 @@ app.get(
|
||||
|
||||
app.post(
|
||||
`/${process.env.API_URI}/api/bookmarkCategories`,
|
||||
postBookmarkCategory,
|
||||
createBookmarkCategory,
|
||||
);
|
||||
|
||||
app.patch(
|
||||
`/${process.env.API_URI}/api/bookmarkCategories`,
|
||||
patchBookmarkCategory,
|
||||
updateBookmarkCategory,
|
||||
);
|
||||
|
||||
app.delete(
|
||||
@@ -205,7 +203,7 @@ app.delete(
|
||||
|
||||
app.patch(
|
||||
`/${process.env.API_URI}/api/bookmarkCategoryOrder`,
|
||||
patchBookmarkCategoryOrder,
|
||||
updateBookmarkCategoryOrder,
|
||||
);
|
||||
|
||||
//////////////////////////////////////////////
|
||||
@@ -216,9 +214,9 @@ app.get(`/${process.env.API_URI}/api/providers`, getProviders);
|
||||
|
||||
app.get(`/${process.env.API_URI}/api/providers/default`, getDefaultProvider);
|
||||
|
||||
app.post(`/${process.env.API_URI}/api/providers`, postProvider);
|
||||
app.post(`/${process.env.API_URI}/api/providers`, createProvider);
|
||||
|
||||
app.patch(`/${process.env.API_URI}/api/providers`, patchProvider);
|
||||
app.patch(`/${process.env.API_URI}/api/providers`, updateProvider);
|
||||
|
||||
app.delete(`/${process.env.API_URI}/api/providers`, deleteProvider);
|
||||
|
||||
@@ -228,7 +226,7 @@ app.delete(`/${process.env.API_URI}/api/providers`, deleteProvider);
|
||||
|
||||
app.get(`/${process.env.API_URI}/api/themes`, getThemes);
|
||||
|
||||
app.post(`/${process.env.API_URI}/api/themes`, addTheme);
|
||||
app.post(`/${process.env.API_URI}/api/themes`, createTheme);
|
||||
|
||||
app.patch(`/${process.env.API_URI}/api/themes`, updateTheme);
|
||||
|
||||
@@ -236,7 +234,7 @@ app.delete(`/${process.env.API_URI}/api/themes`, deleteTheme);
|
||||
|
||||
app.get(`/${process.env.API_URI}/api/themePlaylists`, getThemePlaylists);
|
||||
|
||||
app.post(`/${process.env.API_URI}/api/themePlaylists`, addThemePlaylist);
|
||||
app.post(`/${process.env.API_URI}/api/themePlaylists`, createThemePlaylist);
|
||||
|
||||
app.patch(`/${process.env.API_URI}/api/themePlaylists`, updateThemePlaylist);
|
||||
|
||||
@@ -247,7 +245,7 @@ app.get(`/${process.env.API_URI}/api/backgrounds`, getBackgrounds);
|
||||
app.post(
|
||||
`/${process.env.API_URI}/api/backgrounds`,
|
||||
uploads.single("background"),
|
||||
uploadBackground,
|
||||
addBackground,
|
||||
);
|
||||
|
||||
app.patch(`/${process.env.API_URI}/api/backgrounds`, updateBackground);
|
||||
@@ -292,7 +290,7 @@ app.delete(
|
||||
|
||||
app.get(`/${process.env.API_URI}/api/searchHistory`, getSearchHistory);
|
||||
|
||||
app.post(`/${process.env.API_URI}/api/searchHistory`, addSearchHistoryItem);
|
||||
app.post(`/${process.env.API_URI}/api/searchHistory`, createSearchHistoryItem);
|
||||
|
||||
app.delete(
|
||||
`/${process.env.API_URI}/api/searchHistory`,
|
||||
|
||||
Reference in New Issue
Block a user