1
0
Fork 0
mirror of https://git.sr.ht/~roxwize/mipilin synced 2025-01-30 18:53:36 +00:00

done for today...

Signed-off-by: roxwize <rae@roxwize.xyz>
This commit is contained in:
Rae 5e 2024-12-27 01:38:04 -05:00
parent d173e6ea73
commit 453a143bfa
Signed by: rae
GPG key ID: 5B1A0FAB9BAB81EE
5 changed files with 53 additions and 7 deletions

View file

@ -6,3 +6,6 @@
- [ ] You do realize using toLocaleString on the server only makes it use your locale right
- [ ] Make recent updates also account for new journal entries
- [ ] View all previous moods and journal entries
- [ ] Visibility indicator on journal entries
- [ ] Hide journal entries from feed that are hidden unless current user is a moderator
- [ ] Edit/delete journal entries?

View file

@ -20,7 +20,7 @@ import adminRoutes from "./routes/admin.js";
import loginRoutes from "./routes/login.js";
import userRoutes from "./routes/users.js";
import updateRoutes from "./routes/updates.js";
import { createInviteCode, getMoods, render, setNonce, UserStatus } from "./routes/util.js";
import { createInviteCode, getMoods, render, render404, setNonce, UserStatus } from "./routes/util.js";
const db = drizzle(process.env.DATABASE_URL!);
@ -109,6 +109,10 @@ object-src 'none'; base-uri 'none';"
await updateRoutes(app, db);
loginRoutes(app, db);
app.get("*", (req, res) => {
render404(db, res, req);
});
app.listen(1337, () => {
console.log("Listening on http://127.0.0.1:1337/");
});

View file

@ -1,6 +1,6 @@
import { NodePgDatabase } from "drizzle-orm/node-postgres";
import { Express } from "express";
import { createInviteCode, render, UserStatus } from "./util.js";
import { createInviteCode, render, render404, UserStatus } from "./util.js";
import { inviteCodes, users } from "../db/schema.js";
import { and, count, desc, eq, sql } from "drizzle-orm";
import dayjs from "dayjs";
@ -13,7 +13,7 @@ export default function (app: Express, db: NodePgDatabase) {
!req.session["loggedIn"] ||
!(req.session["status"] & UserStatus.MODERATOR)
) {
res.redirect("/");
render404(db, res, req);
return;
}

View file

@ -10,7 +10,7 @@ import {
} from "../db/schema.js";
import { and, count, desc, eq, sql } from "drizzle-orm";
import dayjs from "dayjs";
import { getMoods, render, render404 } from "./util.js";
import { getMoods, render, render404, UserStatus } from "./util.js";
export default async function (app: Express, db: NodePgDatabase) {
const { moods, moodsSorted } = await getMoods();
@ -155,19 +155,54 @@ export default async function (app: Express, db: NodePgDatabase) {
render(db, "journal", "your journal", res, req);
});
app.get("/journal/:id", async (req, res) => {
const entry = (
const entry: {
uname: string,
title: string,
content: string,
moodChange: number,
moodString?: string,
date: Date,
visibility: number
} = (
await db
.select({
uname: users.name,
title: journalEntries.title,
content: journalEntries.entry,
date: journalEntries.date
moodChange: journalEntries.moodChange,
date: journalEntries.date,
visibility: journalEntries.visibility
})
.from(journalEntries)
.where(eq(journalEntries.id, parseInt(req.params.id)))
.leftJoin(users, eq(journalEntries.user, users.id))
)[0];
if (!entry) {
//? put into util function?
//? also GOD
switch (entry.moodChange) {
case -2:
entry.moodString = "much worse"
break;
case -1:
entry.moodString = "worse";
break;
default:
case 0:
entry.moodString = "about the same";
break;
case 1:
entry.moodString = "better";
break;
case 2:
entry.moodString = "much better";
break;
}
if (
!entry ||
(entry.visibility === 0 && entry.uname !== req.session["user"] && !(req.session["status"] & UserStatus.MODERATOR))
) {
render404(db, res, req);
return;
}

View file

@ -9,4 +9,8 @@ block content
span(title=entry.date.toLocaleString()) #{entryTimestamp}
br
br
div
| Mood:
strong= entry.moodString
br
div!= entry.content