add cookie on web

This commit is contained in:
Nyagami
2024-01-14 22:03:37 +07:00
parent 73bb7e9509
commit 8e3909c1d2
4 changed files with 69 additions and 26 deletions
+22 -4
View File
@@ -8,12 +8,16 @@ import * as pluginApi from "./test_web/api/plugins";
import localizedFormat from "dayjs/plugin/localizedFormat";
interface GlobalState {
UserAgent?: string,
Cookie?: string,
}
let globalState: GlobalState = {
}
export const getUserAgent = () => {
return globalState.UserAgent;
export const getHeaders = () => {
return {
'User-Agent': globalState.UserAgent,
'Cookie': globalState.Cookie,
};
};
const app = express();
@@ -22,15 +26,29 @@ const host = "localhost";
const dirname = path.join(__dirname, "..");
app.use((req, res, next) => {
globalState.UserAgent = req.headers["user-agent"];
console.log('---------');
console.log('default headers: ', globalState);
console.log('---------');
console.log();
next();
});
app.use(bodyParser.json());
app.use("/static", express.static(path.join(dirname, "test_web", "static")));
app.use("/icons", express.static(path.join(dirname, "icons")));
app.get("/all_plugins", (req, res) => {
globalState.UserAgent = req.headers["user-agent"];
console.log(globalState);
const allPlugins = pluginApi.all_plugins();
res.json(allPlugins);
});
app.post("/add_cookie", async (req, res) => {
globalState.Cookie = req.body['cookie'];
console.log('---------');
console.log('default headers: ', globalState);
console.log('---------');
console.log();
res.json({});
});
app.post("/filters", async (req, res) => {
const filters = await pluginApi.getFilter(req.body['pluginRequirePath']);
res.json(filters || []);