realizing webupload with approval functionality
This commit is contained in:
@@ -4,8 +4,10 @@ import lib from "./inc/lib.mjs";
|
||||
import cuffeo from "cuffeo";
|
||||
import { promises as fs } from "fs";
|
||||
import flummpress from "flummpress";
|
||||
import { handleUpload } from "./upload_handler.mjs";
|
||||
|
||||
process.on('unhandledRejection', err => {
|
||||
if (err.code === 'ERR_HTTP_HEADERS_SENT') return;
|
||||
console.error(err);
|
||||
throw err;
|
||||
});
|
||||
@@ -19,7 +21,7 @@ process.on('unhandledRejection', err => {
|
||||
this.level = args.level || 0;
|
||||
this.name = args.name;
|
||||
this.active = args.hasOwnProperty("active") ? args.active : true;
|
||||
this.clients = args.clients || [ "irc", "tg", "slack" ];
|
||||
this.clients = args.clients || ["irc", "tg", "slack"];
|
||||
this.f = args.f;
|
||||
},
|
||||
bot: await new cuffeo(cfg.clients)
|
||||
@@ -27,7 +29,7 @@ process.on('unhandledRejection', err => {
|
||||
|
||||
console.time("loading");
|
||||
const modules = {
|
||||
events: (await fs.readdir("./src/inc/events")).filter(f => f.endsWith(".mjs")),
|
||||
events: (await fs.readdir("./src/inc/events")).filter(f => f.endsWith(".mjs")),
|
||||
trigger: (await fs.readdir("./src/inc/trigger")).filter(f => f.endsWith(".mjs"))
|
||||
};
|
||||
|
||||
@@ -41,7 +43,7 @@ process.on('unhandledRejection', err => {
|
||||
console.timeLog("loading", `${dir}/${mod}`);
|
||||
return res;
|
||||
}))).flat(2)
|
||||
})))).reduce((a, b) => ({...a, ...b}));
|
||||
})))).reduce((a, b) => ({ ...a, ...b }));
|
||||
|
||||
blah.events.forEach(event => {
|
||||
console.timeLog("loading", `registering event > ${event.name}`);
|
||||
@@ -61,15 +63,16 @@ process.on('unhandledRejection', err => {
|
||||
const router = app.router;
|
||||
const tpl = app.tpl;
|
||||
|
||||
|
||||
app.use(async (req, res) => {
|
||||
// sessionhandler
|
||||
req.session = false;
|
||||
if(req.url.pathname.match(/^\/(s|b|t|ca)\//))
|
||||
if (req.url.pathname.match(/^\/(s|b|t|ca)\//))
|
||||
return;
|
||||
req.theme = req.cookies.theme || 'amoled';
|
||||
req.fullscreen = req.cookies.fullscreen || 0;
|
||||
|
||||
if(req.cookies.session) {
|
||||
if (req.cookies.session) {
|
||||
const user = await db`
|
||||
select "user".id, "user".login, "user".user, "user".admin, "user_sessions".id as sess_id, "user_options".*
|
||||
from "user_sessions"
|
||||
@@ -78,8 +81,8 @@ process.on('unhandledRejection', err => {
|
||||
where "user_sessions".session = ${lib.md5(req.cookies.session)}
|
||||
limit 1
|
||||
`;
|
||||
|
||||
if(user.length === 0) {
|
||||
|
||||
if (user.length === 0) {
|
||||
return res.writeHead(307, { // delete session
|
||||
"Cache-Control": "no-cache, public",
|
||||
"Set-Cookie": "session=; Path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT",
|
||||
@@ -91,28 +94,26 @@ process.on('unhandledRejection', err => {
|
||||
|
||||
// log last action
|
||||
await db`
|
||||
update "user_sessions" set ${
|
||||
db({
|
||||
last_used: ~~(Date.now() / 1e3),
|
||||
last_action: req.url.pathname,
|
||||
browser: req.headers['user-agent']
|
||||
}, 'last_used', 'last_action', 'browser')
|
||||
update "user_sessions" set ${db({
|
||||
last_used: ~~(Date.now() / 1e3),
|
||||
last_action: req.url.pathname,
|
||||
browser: req.headers['user-agent']
|
||||
}, 'last_used', 'last_action', 'browser')
|
||||
}
|
||||
where id = ${+user[0].sess_id}
|
||||
`;
|
||||
|
||||
req.session.theme = req.cookies.theme;
|
||||
req.session.fullscreen = req.cookies.fullscreen;
|
||||
|
||||
|
||||
// update userprofile
|
||||
await db`
|
||||
insert into "user_options" ${
|
||||
db({
|
||||
user_id: +user[0].id,
|
||||
mode: user[0].mode ?? 0,
|
||||
theme: req.session.theme ?? 'amoled',
|
||||
fullscreen: req.session.fullscreen || 0
|
||||
}, 'user_id', 'mode', 'theme', 'fullscreen')
|
||||
insert into "user_options" ${db({
|
||||
user_id: +user[0].id,
|
||||
mode: user[0].mode ?? 0,
|
||||
theme: req.session.theme ?? 'amoled',
|
||||
fullscreen: req.session.fullscreen || 0
|
||||
}, 'user_id', 'mode', 'theme', 'fullscreen')
|
||||
}
|
||||
on conflict ("user_id") do update set
|
||||
mode = excluded.mode,
|
||||
@@ -123,6 +124,15 @@ process.on('unhandledRejection', err => {
|
||||
}
|
||||
});
|
||||
|
||||
// Bypass middleware for direct upload handling
|
||||
app.use(async (req, res) => {
|
||||
if (req.method === 'POST' && req.url.pathname === '/api/v2/upload') {
|
||||
await handleUpload(req, res);
|
||||
// Modify URL to prevent router matching and double execution
|
||||
req.url.pathname = '/handled_upload_bypass';
|
||||
}
|
||||
});
|
||||
|
||||
tpl.views = "views";
|
||||
tpl.debug = true;
|
||||
tpl.cache = false;
|
||||
|
||||
Reference in New Issue
Block a user