This repository has been archived on 2025-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
Files
mylinks/server/actions/click.js

23 lines
850 B
JavaScript

const {getLinkByAccess, clickLink} = require("../controller/link");
const {getModule} = require("../controller/module");
const app = require('express').Router();
const sendNotFound = (res) => res.status(404).render(process.cwd() + "/server/templates/404");
app.get("/", async (req, res) => {
res.locals.accessId = req.baseUrl.substring(1, req.baseUrl.length) || "home";
const currentDomain = req.get('host')?.split(":")[0] || "localhost";
const link = await getLinkByAccess(res.locals.accessId, currentDomain);
if (!link) return sendNotFound(res);
const module = getModule(link.type);
if (!module) return sendNotFound(res);
await clickLink(link.accessId, link.domainName);
res.locals.meta = JSON.parse(link.meta);
module.onClick(link.id, link.accessId, JSON.parse(link.meta), res);
});
module.exports = app;