2020-07-21 14:36:50 +03:00
|
|
|
import * as Environment from "~/node_common/environment";
|
2020-07-22 10:41:29 +03:00
|
|
|
import * as Data from "~/node_common/data";
|
|
|
|
import * as Utilities from "~/node_common/utilities";
|
2020-08-14 12:17:19 +03:00
|
|
|
import * as ViewerManager from "~/node_common/managers/viewer";
|
2020-10-27 07:41:42 +03:00
|
|
|
import * as Websocket from "~/node_common/nodejs-websocket";
|
2021-06-11 22:25:58 +03:00
|
|
|
import * as Logging from "~/common/logging";
|
2020-10-27 07:41:42 +03:00
|
|
|
import * as Validations from "~/common/validations";
|
|
|
|
import * as Window from "~/common/window";
|
|
|
|
import * as Strings from "~/common/strings";
|
2021-05-06 03:08:14 +03:00
|
|
|
import * as NavigationData from "~/common/navigation-data";
|
2020-06-17 21:05:13 +03:00
|
|
|
|
2020-10-29 10:05:57 +03:00
|
|
|
import limit from "express-rate-limit";
|
2020-07-09 06:19:08 +03:00
|
|
|
import express from "express";
|
|
|
|
import next from "next";
|
|
|
|
import compression from "compression";
|
2020-08-18 01:07:31 +03:00
|
|
|
import cors from "cors";
|
2020-10-08 03:51:49 +03:00
|
|
|
import morgan from "morgan";
|
2021-04-22 18:00:25 +03:00
|
|
|
import path from "path";
|
2020-06-09 21:00:36 +03:00
|
|
|
|
2021-08-04 20:59:25 +03:00
|
|
|
import { FilecoinNumber } from "@glif/filecoin-number";
|
2021-01-28 09:17:01 +03:00
|
|
|
|
2020-07-21 21:01:12 +03:00
|
|
|
const app = next({
|
|
|
|
dev: !Environment.IS_PRODUCTION,
|
|
|
|
dir: __dirname,
|
|
|
|
quiet: false,
|
|
|
|
});
|
2020-07-22 22:17:08 +03:00
|
|
|
|
2020-10-29 10:05:57 +03:00
|
|
|
const createLimiter = limit({
|
|
|
|
windowMs: 10 * 60 * 1000, // 10 minutes
|
2021-09-13 22:33:06 +03:00
|
|
|
max: 10,
|
2020-11-17 07:17:09 +03:00
|
|
|
message: {
|
|
|
|
decorator: "SIGN_UP_RATE_LIMITED",
|
|
|
|
error: true,
|
|
|
|
message: "You have made too many requests.",
|
|
|
|
},
|
2020-10-29 10:05:57 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const loginLimiter = limit({
|
|
|
|
windowMs: 10 * 60 * 1000, // 10 minutes
|
2021-09-13 22:33:06 +03:00
|
|
|
max: 10,
|
2020-11-17 07:17:09 +03:00
|
|
|
message: {
|
|
|
|
decorator: "SIGN_IN_RATE_LIMITED",
|
|
|
|
error: true,
|
|
|
|
message: "You have made too many requests.",
|
|
|
|
},
|
2020-10-29 10:05:57 +03:00
|
|
|
});
|
|
|
|
|
2020-07-17 13:24:20 +03:00
|
|
|
const handler = app.getRequestHandler();
|
2020-06-09 21:00:36 +03:00
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
app.prepare().then(async () => {
|
2020-02-19 09:30:47 +03:00
|
|
|
const server = express();
|
2020-07-22 21:34:24 +03:00
|
|
|
|
2020-08-18 01:11:08 +03:00
|
|
|
server.use(cors());
|
2020-10-22 08:38:37 +03:00
|
|
|
server.use(morgan(":method :url :status :res[content-length] - :response-time ms"));
|
2020-08-18 01:07:31 +03:00
|
|
|
|
2020-10-23 23:28:08 +03:00
|
|
|
if (Environment.IS_PRODUCTION) {
|
|
|
|
server.use(compression());
|
|
|
|
}
|
|
|
|
|
2020-07-09 06:19:08 +03:00
|
|
|
server.use("/public", express.static("public"));
|
2021-04-22 18:00:25 +03:00
|
|
|
server.get("/service-worker.js", express.static(path.join(__dirname, ".next")));
|
2020-08-30 22:10:01 +03:00
|
|
|
server.get("/system", async (r, s) => s.redirect("/_/system"));
|
|
|
|
server.get("/experiences", async (r, s) => s.redirect("/_/system"));
|
|
|
|
server.get("/_/experiences", async (r, s) => s.redirect("/_/system"));
|
2020-10-22 08:38:37 +03:00
|
|
|
server.get("/system/:c", async (r, s) => s.redirect(`/_/system/${r.params.c}`));
|
|
|
|
server.get("/experiences/:m", async (r, s) => s.redirect(`/_/experiences/${r.params.m}`));
|
2020-10-09 13:43:56 +03:00
|
|
|
|
2021-08-04 20:59:25 +03:00
|
|
|
server.all("/api/users/create", createLimiter, async (r, s) => {
|
2020-10-29 10:05:57 +03:00
|
|
|
return handler(r, s, r.url);
|
|
|
|
});
|
|
|
|
|
2021-08-04 20:59:25 +03:00
|
|
|
server.all("/api/sign-in", loginLimiter, async (r, s) => {
|
2020-10-29 10:05:57 +03:00
|
|
|
return handler(r, s, r.url);
|
|
|
|
});
|
|
|
|
|
2021-08-04 20:59:25 +03:00
|
|
|
server.all("/api/:a", async (r, s) => {
|
2020-10-05 04:33:33 +03:00
|
|
|
return handler(r, s, r.url);
|
|
|
|
});
|
2020-10-09 13:43:56 +03:00
|
|
|
|
2021-08-04 20:59:25 +03:00
|
|
|
server.all("/api/:a/:b", async (r, s) => {
|
2020-10-05 04:33:33 +03:00
|
|
|
return handler(r, s, r.url);
|
|
|
|
});
|
2020-08-20 08:57:46 +03:00
|
|
|
|
2020-09-14 10:28:09 +03:00
|
|
|
server.get("/", async (req, res) => {
|
|
|
|
return app.render(req, res, "/", {});
|
|
|
|
});
|
|
|
|
|
2020-08-20 08:57:46 +03:00
|
|
|
server.get("/_", async (req, res) => {
|
2021-07-27 15:01:44 +03:00
|
|
|
return res.redirect("/_/data");
|
2021-05-06 03:08:14 +03:00
|
|
|
// let isMobile = Window.isMobileBrowser(req.headers["user-agent"]);
|
|
|
|
// let isMac = Window.isMac(req.headers["user-agent"]);
|
2020-10-05 00:30:28 +03:00
|
|
|
|
2021-06-08 04:19:00 +03:00
|
|
|
// const isBucketsAvailable = await Utilities.checkTextile();
|
2020-08-19 21:44:18 +03:00
|
|
|
|
2021-06-08 04:19:00 +03:00
|
|
|
// if (!isBucketsAvailable && Environment.IS_PRODUCTION) {
|
|
|
|
// return res.redirect("/maintenance");
|
|
|
|
// }
|
2020-08-19 21:44:18 +03:00
|
|
|
|
2021-06-08 04:19:00 +03:00
|
|
|
// const id = Utilities.getIdFromCookie(req);
|
2020-07-21 14:36:50 +03:00
|
|
|
|
2021-06-08 04:19:00 +03:00
|
|
|
// let viewer = null;
|
|
|
|
// if (id) {
|
|
|
|
// viewer = await Data.getUserById({
|
|
|
|
// id,
|
|
|
|
// });
|
|
|
|
// }
|
2020-07-21 14:36:50 +03:00
|
|
|
|
2021-06-08 04:19:00 +03:00
|
|
|
// if (viewer) {
|
|
|
|
// return res.redirect("/_/data");
|
|
|
|
// } else {
|
2021-05-27 11:20:34 +03:00
|
|
|
// return res.redirect("/_/activity");
|
2021-06-08 04:19:00 +03:00
|
|
|
// }
|
2021-05-06 03:08:14 +03:00
|
|
|
|
|
|
|
// let page = NavigationData.getById(null, viewer);
|
|
|
|
|
|
|
|
// return app.render(req, res, "/_", {
|
|
|
|
// viewer,
|
|
|
|
// isMobile,
|
|
|
|
// isMac,
|
|
|
|
// page,
|
|
|
|
// data: null,
|
|
|
|
// });
|
2020-02-19 09:30:47 +03:00
|
|
|
});
|
|
|
|
|
2021-11-18 00:44:41 +03:00
|
|
|
server.get("/_/view/:id", async (req, res) => {
|
2021-11-17 03:52:19 +03:00
|
|
|
let isMobile = Window.isMobileBrowser(req.headers["user-agent"]);
|
|
|
|
let isMac = Window.isMac(req.headers["user-agent"]);
|
|
|
|
|
|
|
|
const fileId = req.params.id;
|
|
|
|
|
|
|
|
const file = await Data.getFileById({ id: fileId });
|
|
|
|
|
|
|
|
const id = Utilities.getIdFromCookie(req);
|
|
|
|
|
|
|
|
let viewer = null;
|
|
|
|
if (id) {
|
|
|
|
viewer = await ViewerManager.getById({
|
|
|
|
id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id && id === file.ownerId) {
|
|
|
|
file.owner = viewer;
|
|
|
|
} else {
|
|
|
|
file.owner = await Data.getUserById({ id: file.ownerId, sanitize: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
return app.render(req, res, "/_/file", {
|
|
|
|
viewer,
|
|
|
|
isMobile,
|
|
|
|
isMac,
|
|
|
|
data: file,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
server.get("/_/:scene", async (req, res) => {
|
|
|
|
let isMobile = Window.isMobileBrowser(req.headers["user-agent"]);
|
|
|
|
let isMac = Window.isMac(req.headers["user-agent"]);
|
|
|
|
|
2020-08-26 03:44:45 +03:00
|
|
|
const id = Utilities.getIdFromCookie(req);
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
let viewer = null;
|
|
|
|
if (id) {
|
|
|
|
viewer = await ViewerManager.getById({
|
|
|
|
id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:33:46 +03:00
|
|
|
let { page, redirected } = NavigationData.getByHref(req.path, viewer);
|
2021-07-07 23:50:57 +03:00
|
|
|
if (redirected) {
|
|
|
|
return res.redirect(page.pathname);
|
2021-06-11 08:33:46 +03:00
|
|
|
}
|
2021-07-07 23:50:57 +03:00
|
|
|
// if (!redirected) {
|
|
|
|
page.params = req.query;
|
|
|
|
// }
|
2021-06-11 08:33:46 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
if (!page) {
|
|
|
|
return handler(req, res, req.url, {
|
|
|
|
isMobile,
|
|
|
|
});
|
|
|
|
}
|
2020-08-26 03:44:45 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
return app.render(req, res, "/_", {
|
|
|
|
isMobile,
|
|
|
|
isMac,
|
|
|
|
viewer,
|
|
|
|
page,
|
|
|
|
data: null,
|
2020-08-26 03:44:45 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-30 22:10:01 +03:00
|
|
|
server.all("/_/:a", async (r, s) => handler(r, s, r.url));
|
|
|
|
server.all("/_/:a/:b", async (r, s) => handler(r, s, r.url));
|
|
|
|
|
2021-01-17 23:57:34 +03:00
|
|
|
server.get("/[$]/slate/:id", async (req, res) => {
|
|
|
|
const slate = await Data.getSlateById({
|
|
|
|
id: req.params.id,
|
|
|
|
});
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
if (!slate || slate.error) {
|
|
|
|
return res.redirect("/_/404");
|
2021-01-17 23:57:34 +03:00
|
|
|
}
|
|
|
|
|
2021-03-07 23:53:54 +03:00
|
|
|
const creator = await Data.getUserById({
|
|
|
|
id: slate.ownerId,
|
|
|
|
});
|
2021-01-17 23:57:34 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
if (!creator || creator.error) {
|
|
|
|
return res.redirect("/_/404");
|
2021-01-17 23:57:34 +03:00
|
|
|
}
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
let search = Strings.getQueryStringFromParams(req.query);
|
2021-01-17 23:57:34 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
return res.redirect(`/${creator.username}/${slate.slatename}${search}`);
|
2021-01-17 23:57:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
server.get("/[$]/user/:id", async (req, res) => {
|
2021-03-07 23:53:54 +03:00
|
|
|
const creator = await Data.getUserById({
|
|
|
|
id: req.params.id,
|
|
|
|
});
|
2021-01-17 23:57:34 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
if (!creator || creator.error) {
|
|
|
|
return res.redirect("/_/404");
|
2021-01-17 23:57:34 +03:00
|
|
|
}
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
let search = Strings.getQueryStringFromParams(req.query);
|
2021-01-17 23:57:34 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
return res.redirect(`/${creator.username}${search}`);
|
2021-01-17 23:57:34 +03:00
|
|
|
});
|
|
|
|
|
2020-11-16 11:07:11 +03:00
|
|
|
server.get("/[$]/:id", async (req, res) => {
|
|
|
|
const slate = await Data.getSlateById({
|
|
|
|
id: req.params.id,
|
|
|
|
});
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
if (!slate || slate.error) {
|
|
|
|
return res.redirect("/_/404");
|
2020-11-16 11:07:11 +03:00
|
|
|
}
|
|
|
|
|
2021-03-07 23:53:54 +03:00
|
|
|
const creator = await Data.getUserById({
|
|
|
|
id: slate.ownerId,
|
|
|
|
});
|
2020-11-16 11:07:11 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
if (!creator || creator.error) {
|
|
|
|
return res.redirect("/_/404");
|
2020-11-16 11:07:11 +03:00
|
|
|
}
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
let search = Strings.getQueryStringFromParams(req.query);
|
2020-11-16 11:07:11 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
return res.redirect(`/${creator.username}/${slate.slatename}${search}`);
|
2020-11-16 11:07:11 +03:00
|
|
|
});
|
|
|
|
|
2020-08-07 02:06:54 +03:00
|
|
|
server.get("/:username", async (req, res) => {
|
2021-05-06 03:08:14 +03:00
|
|
|
const username = req.params.username.toLowerCase();
|
2021-03-07 23:53:54 +03:00
|
|
|
let isMobile = Window.isMobileBrowser(req.headers["user-agent"]);
|
|
|
|
let isMac = Window.isMac(req.headers["user-agent"]);
|
2020-10-05 00:30:28 +03:00
|
|
|
|
2020-08-07 02:28:54 +03:00
|
|
|
// TODO(jim): Temporary workaround
|
2021-05-06 03:08:14 +03:00
|
|
|
if (!Validations.userRoute(username)) {
|
2020-10-23 13:34:31 +03:00
|
|
|
return handler(req, res, req.url, {
|
2021-03-07 23:53:54 +03:00
|
|
|
isMobile,
|
2020-10-23 13:34:31 +03:00
|
|
|
});
|
2020-08-07 02:28:54 +03:00
|
|
|
}
|
|
|
|
|
2020-07-22 13:51:40 +03:00
|
|
|
const id = Utilities.getIdFromCookie(req);
|
2020-11-17 23:36:36 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
let user = await Data.getUserByUsername({
|
|
|
|
username,
|
2020-07-22 10:41:29 +03:00
|
|
|
});
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
if (!user) {
|
|
|
|
return res.redirect("/_/404");
|
2020-08-02 01:46:54 +03:00
|
|
|
}
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
if (user.error) {
|
|
|
|
return res.redirect("/_/404");
|
2020-08-02 01:46:54 +03:00
|
|
|
}
|
|
|
|
|
2021-12-09 00:22:57 +03:00
|
|
|
if (user.id === id) {
|
|
|
|
return res.redirect("/_/data");
|
|
|
|
}
|
|
|
|
|
2020-08-06 23:59:06 +03:00
|
|
|
const slates = await Data.getSlatesByUserId({
|
2021-05-06 03:08:14 +03:00
|
|
|
ownerId: user.id,
|
2020-08-06 23:59:06 +03:00
|
|
|
publicOnly: true,
|
|
|
|
});
|
2020-07-27 12:50:25 +03:00
|
|
|
|
2021-12-09 00:22:57 +03:00
|
|
|
if (slates && !slates.error) {
|
|
|
|
if (slates.length) {
|
|
|
|
return res.redirect(`/${username}/${slates[0].slatename}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
user.slates = slates;
|
|
|
|
}
|
|
|
|
|
|
|
|
let viewer = null;
|
|
|
|
if (id) {
|
2021-12-11 00:26:41 +03:00
|
|
|
viewer = await ViewerManager.getById({
|
2021-12-09 00:22:57 +03:00
|
|
|
id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let { page, redirected } = NavigationData.getByHref(req.path, viewer);
|
|
|
|
if (!redirected) {
|
|
|
|
page.params = req.query;
|
|
|
|
}
|
2021-01-09 07:13:00 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
return app.render(req, res, "/_", {
|
|
|
|
viewer,
|
2021-03-07 23:53:54 +03:00
|
|
|
isMobile,
|
|
|
|
isMac,
|
2021-05-06 03:08:14 +03:00
|
|
|
data: user,
|
|
|
|
page,
|
2020-07-22 10:41:29 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// server.get("/:username/cid::cid", async (req, res) => {
|
|
|
|
// const username = req.params.username.toLowerCase();
|
|
|
|
// const cid = req.params.cid.toLowerCase();
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// let isMobile = Window.isMobileBrowser(req.headers["user-agent"]);
|
|
|
|
// let isMac = Window.isMac(req.headers["user-agent"]);
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// // TODO(jim): Temporary workaround
|
|
|
|
// if (!Validations.userRoute(username)) {
|
|
|
|
// return handler(req, res, req.url);
|
|
|
|
// }
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// const id = Utilities.getIdFromCookie(req);
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// let user = await Data.getUserByUsername({
|
|
|
|
// username,
|
|
|
|
// includeFiles: true,
|
|
|
|
// sanitize: true,
|
|
|
|
// publicOnly: true,
|
|
|
|
// });
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// if (!user) {
|
|
|
|
// return res.redirect("/_/404");
|
|
|
|
// }
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// if (user.error) {
|
|
|
|
// return res.redirect("/_/404");
|
|
|
|
// }
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// const slates = await Data.getSlatesByUserId({
|
|
|
|
// ownerId: user.id,
|
|
|
|
// includeFiles: true,
|
|
|
|
// publicOnly: true,
|
|
|
|
// });
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// user.slates = slates;
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// let viewer = null;
|
|
|
|
// if (id) {
|
|
|
|
// viewer = await ViewerManager.getById({
|
|
|
|
// id,
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
// let page = NavigationData.getById("NAV_PROFILE", viewer);
|
|
|
|
// page = { ...page, cid };
|
|
|
|
|
|
|
|
// return app.render(req, res, "/_", {
|
|
|
|
// viewer,
|
|
|
|
// isMobile,
|
|
|
|
// isMac,
|
|
|
|
// page,
|
|
|
|
// data: user,
|
|
|
|
// });
|
|
|
|
// });
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2020-08-07 02:06:54 +03:00
|
|
|
server.get("/:username/:slatename", async (req, res) => {
|
2021-05-06 03:08:14 +03:00
|
|
|
const username = req.params.username.toLowerCase();
|
|
|
|
const slatename = req.params.slatename.toLowerCase();
|
|
|
|
|
2021-03-07 23:53:54 +03:00
|
|
|
let isMobile = Window.isMobileBrowser(req.headers["user-agent"]);
|
|
|
|
let isMac = Window.isMac(req.headers["user-agent"]);
|
2020-10-23 06:55:24 +03:00
|
|
|
|
2020-08-07 02:28:54 +03:00
|
|
|
// TODO(jim): Temporary workaround
|
2021-05-06 03:08:14 +03:00
|
|
|
if (!Validations.userRoute(username)) {
|
2020-10-23 13:34:31 +03:00
|
|
|
return handler(req, res, req.url, {
|
2021-03-07 23:53:54 +03:00
|
|
|
isMobile,
|
2020-10-23 13:34:31 +03:00
|
|
|
});
|
2020-08-07 02:28:54 +03:00
|
|
|
}
|
|
|
|
|
2020-11-17 05:10:43 +03:00
|
|
|
const id = Utilities.getIdFromCookie(req);
|
2021-05-06 03:08:14 +03:00
|
|
|
|
|
|
|
let viewer = null;
|
|
|
|
if (id) {
|
|
|
|
viewer = await ViewerManager.getById({
|
|
|
|
id,
|
|
|
|
});
|
2020-11-17 05:10:43 +03:00
|
|
|
}
|
|
|
|
|
2021-06-11 08:33:46 +03:00
|
|
|
let { page, redirected } = NavigationData.getByHref(req.path, viewer);
|
|
|
|
if (!redirected) {
|
|
|
|
page.params = req.query;
|
|
|
|
}
|
2021-05-06 03:08:14 +03:00
|
|
|
|
2020-07-27 12:50:25 +03:00
|
|
|
const slate = await Data.getSlateByName({
|
2021-05-06 03:08:14 +03:00
|
|
|
slatename,
|
|
|
|
username,
|
2021-03-07 23:53:54 +03:00
|
|
|
includeFiles: true,
|
2020-07-27 12:50:25 +03:00
|
|
|
});
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
if (!slate || slate.error || (!slate.isPublic && slate.ownerId !== id)) {
|
|
|
|
return res.redirect("/_/404");
|
2020-09-14 05:58:33 +03:00
|
|
|
}
|
|
|
|
|
2021-12-01 00:46:00 +03:00
|
|
|
const owner = await Data.getUserById({
|
2021-03-07 23:53:54 +03:00
|
|
|
id: slate.ownerId,
|
|
|
|
sanitize: true,
|
|
|
|
});
|
2020-09-14 05:58:33 +03:00
|
|
|
|
2021-12-01 00:46:00 +03:00
|
|
|
if (!owner) {
|
2021-05-06 03:08:14 +03:00
|
|
|
return res.redirect("/_/404");
|
2020-09-14 05:58:33 +03:00
|
|
|
}
|
|
|
|
|
2021-12-01 00:46:00 +03:00
|
|
|
if (owner.error) {
|
2021-05-06 03:08:14 +03:00
|
|
|
return res.redirect("/_/404");
|
2020-09-14 05:58:33 +03:00
|
|
|
}
|
|
|
|
|
2021-12-01 00:46:00 +03:00
|
|
|
let slates = await Data.getSlatesByUserId({
|
|
|
|
ownerId: owner.id,
|
|
|
|
publicOnly: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (slates && !slates.error) {
|
|
|
|
owner.slates = slates;
|
|
|
|
}
|
|
|
|
|
|
|
|
slate.owner = owner;
|
2020-09-14 05:58:33 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
return app.render(req, res, "/_", {
|
|
|
|
viewer,
|
2021-03-07 23:53:54 +03:00
|
|
|
isMobile,
|
|
|
|
isMac,
|
2021-05-06 03:08:14 +03:00
|
|
|
data: slate,
|
|
|
|
page,
|
2020-09-14 05:58:33 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// server.get("/:username/:slatename/cid::cid", async (req, res) => {
|
|
|
|
// const username = req.params.username.toLowerCase();
|
|
|
|
// const slatename = req.params.slatename.toLowerCase();
|
|
|
|
// const cid = req.params.cid.toLowerCase();
|
2021-03-01 07:17:41 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// let isMobile = Window.isMobileBrowser(req.headers["user-agent"]);
|
|
|
|
// let isMac = Window.isMac(req.headers["user-agent"]);
|
2020-09-14 05:58:33 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// // TODO(jim): Temporary workaround
|
|
|
|
// if (!Validations.userRoute(username)) {
|
|
|
|
// return handler(req, res, req.url);
|
|
|
|
// }
|
2020-11-17 23:36:36 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// const id = Utilities.getIdFromCookie(req);
|
2020-11-17 05:10:43 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// const slate = await Data.getSlateByName({
|
|
|
|
// slatename,
|
|
|
|
// username,
|
|
|
|
// includeFiles: true,
|
|
|
|
// });
|
2020-09-14 05:58:33 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// if (!slate) {
|
|
|
|
// return res.redirect("/_/404");
|
|
|
|
// }
|
2020-09-14 05:58:33 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// if (slate.error || !slate.isPublic && slate.ownerId !== id) {
|
|
|
|
// return res.redirect("/_/404");
|
|
|
|
// }
|
2020-09-14 05:58:33 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// const user = await Data.getUserById({
|
|
|
|
// id: slate.ownerId,
|
|
|
|
// sanitize: true,
|
|
|
|
// });
|
2020-08-06 23:59:06 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// if (!user) {
|
|
|
|
// return res.redirect("/_/404");
|
|
|
|
// }
|
2020-08-06 23:59:06 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// if (user.error) {
|
|
|
|
// return res.redirect("/_/404");
|
|
|
|
// }
|
2020-08-06 23:59:06 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// let viewer = null;
|
|
|
|
// if (id) {
|
|
|
|
// viewer = await ViewerManager.getById({
|
|
|
|
// id,
|
|
|
|
// });
|
|
|
|
// }
|
2020-08-06 23:59:06 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// slate.user = user;
|
2020-08-03 02:29:11 +03:00
|
|
|
|
2021-05-06 03:08:14 +03:00
|
|
|
// let page = NavigationData.getById("NAV_SLATE", viewer);
|
|
|
|
// page = { ...page, cid };
|
|
|
|
|
|
|
|
// return app.render(req, res, "/_", {
|
|
|
|
// viewer,
|
|
|
|
// isMobile,
|
|
|
|
// isMac,
|
|
|
|
// data: slate,
|
|
|
|
// page,
|
|
|
|
// });
|
|
|
|
// });
|
2020-07-27 12:50:25 +03:00
|
|
|
|
2020-08-30 22:10:01 +03:00
|
|
|
server.all("*", async (r, s) => handler(r, s, r.url));
|
2020-02-19 09:30:47 +03:00
|
|
|
|
2021-08-04 20:59:25 +03:00
|
|
|
server.listen(Environment.PORT, async (e) => {
|
2020-07-17 13:24:20 +03:00
|
|
|
if (e) throw e;
|
2021-01-10 02:30:52 +03:00
|
|
|
Websocket.create();
|
2020-06-09 21:00:36 +03:00
|
|
|
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.log(`started on http://localhost:${Environment.PORT}`);
|
2021-01-25 21:12:03 +03:00
|
|
|
|
2021-01-28 09:17:01 +03:00
|
|
|
const filecoinNumber = new FilecoinNumber("10000", "attoFil");
|
|
|
|
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.log(`Testing Values: ${filecoinNumber.toPicoFil()} PICO FIL`);
|
|
|
|
Logging.log(`Testing Values: ${filecoinNumber.toAttoFil()} ATTO FIL`);
|
|
|
|
Logging.log(`Testing Values: ${filecoinNumber.toFil()} FIL`);
|
2020-02-19 09:30:47 +03:00
|
|
|
});
|
|
|
|
});
|