var express = require("express"); var router = express.Router(); var util = require("util"); var utils = require("../../../src/utils"); var crossCtl = require("../../../src/crossCtl"); var path = require("path"); const fs = require("fs"); // operation const FileType = require("file-type"); router.use(function (req, res, next) { // console.log("huk ck!!!, req.headers.referer=", req.headers.referer); // console.log("huk ck!!!, req.headers=", req.headers); // console.log("huk ck!!!, req.url=", req.url); var passcard = req.headers["user-agent"] != undefined ? req.headers["user-agent"] : ""; if ( req.isAuthenticated() || (passcard.startsWith("Dart/") && passcard.endsWith(" (dart:io)")) || passcard == "usm" ) { var ckRootPath = crossCtl.sConfig.contentKeeperPath ? path.join(crossCtl.sConfig.contentKeeperPath, req.url) : path.join( __dirname, "../../../", "modules", crossCtl.sConfig.type, "contents", req.url ); var targetPath = ckRootPath; // console.log("in ck, targetPath=", targetPath); let mimeType = utils.getMimeFromPath(targetPath); // console.log("in ck, mimeType=", mimeType); fs.access(targetPath, fs.constants.F_OK, function (error) { if (error) { next(); } else { req.workTag.res().status(200).type(mimeType).sendFile(targetPath); } }); } else { req.workTag.res().status(401).send("401 Unauthorized"); } }); module.exports = router;