mirror of
https://git.sr.ht/~roxwize/mipilin
synced 2025-01-31 02:53:36 +00:00
done for today...
Signed-off-by: roxwize <rae@roxwize.xyz>
This commit is contained in:
parent
d173e6ea73
commit
453a143bfa
5 changed files with 53 additions and 7 deletions
3
TODO.md
3
TODO.md
|
@ -6,3 +6,6 @@
|
||||||
- [ ] You do realize using toLocaleString on the server only makes it use your locale right
|
- [ ] You do realize using toLocaleString on the server only makes it use your locale right
|
||||||
- [ ] Make recent updates also account for new journal entries
|
- [ ] Make recent updates also account for new journal entries
|
||||||
- [ ] View all previous moods and 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?
|
||||||
|
|
6
main.ts
6
main.ts
|
@ -20,7 +20,7 @@ import adminRoutes from "./routes/admin.js";
|
||||||
import loginRoutes from "./routes/login.js";
|
import loginRoutes from "./routes/login.js";
|
||||||
import userRoutes from "./routes/users.js";
|
import userRoutes from "./routes/users.js";
|
||||||
import updateRoutes from "./routes/updates.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!);
|
const db = drizzle(process.env.DATABASE_URL!);
|
||||||
|
|
||||||
|
@ -109,6 +109,10 @@ object-src 'none'; base-uri 'none';"
|
||||||
await updateRoutes(app, db);
|
await updateRoutes(app, db);
|
||||||
loginRoutes(app, db);
|
loginRoutes(app, db);
|
||||||
|
|
||||||
|
app.get("*", (req, res) => {
|
||||||
|
render404(db, res, req);
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(1337, () => {
|
app.listen(1337, () => {
|
||||||
console.log("Listening on http://127.0.0.1:1337/");
|
console.log("Listening on http://127.0.0.1:1337/");
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
||||||
import { Express } from "express";
|
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 { inviteCodes, users } from "../db/schema.js";
|
||||||
import { and, count, desc, eq, sql } from "drizzle-orm";
|
import { and, count, desc, eq, sql } from "drizzle-orm";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
@ -13,7 +13,7 @@ export default function (app: Express, db: NodePgDatabase) {
|
||||||
!req.session["loggedIn"] ||
|
!req.session["loggedIn"] ||
|
||||||
!(req.session["status"] & UserStatus.MODERATOR)
|
!(req.session["status"] & UserStatus.MODERATOR)
|
||||||
) {
|
) {
|
||||||
res.redirect("/");
|
render404(db, res, req);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
} from "../db/schema.js";
|
} from "../db/schema.js";
|
||||||
import { and, count, desc, eq, sql } from "drizzle-orm";
|
import { and, count, desc, eq, sql } from "drizzle-orm";
|
||||||
import dayjs from "dayjs";
|
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) {
|
export default async function (app: Express, db: NodePgDatabase) {
|
||||||
const { moods, moodsSorted } = await getMoods();
|
const { moods, moodsSorted } = await getMoods();
|
||||||
|
@ -155,19 +155,54 @@ export default async function (app: Express, db: NodePgDatabase) {
|
||||||
render(db, "journal", "your journal", res, req);
|
render(db, "journal", "your journal", res, req);
|
||||||
});
|
});
|
||||||
app.get("/journal/:id", async (req, res) => {
|
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
|
await db
|
||||||
.select({
|
.select({
|
||||||
uname: users.name,
|
uname: users.name,
|
||||||
title: journalEntries.title,
|
title: journalEntries.title,
|
||||||
content: journalEntries.entry,
|
content: journalEntries.entry,
|
||||||
date: journalEntries.date
|
moodChange: journalEntries.moodChange,
|
||||||
|
date: journalEntries.date,
|
||||||
|
visibility: journalEntries.visibility
|
||||||
})
|
})
|
||||||
.from(journalEntries)
|
.from(journalEntries)
|
||||||
.where(eq(journalEntries.id, parseInt(req.params.id)))
|
.where(eq(journalEntries.id, parseInt(req.params.id)))
|
||||||
.leftJoin(users, eq(journalEntries.user, users.id))
|
.leftJoin(users, eq(journalEntries.user, users.id))
|
||||||
)[0];
|
)[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);
|
render404(db, res, req);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,4 +9,8 @@ block content
|
||||||
span(title=entry.date.toLocaleString()) #{entryTimestamp}
|
span(title=entry.date.toLocaleString()) #{entryTimestamp}
|
||||||
br
|
br
|
||||||
br
|
br
|
||||||
|
div
|
||||||
|
| Mood:
|
||||||
|
strong= entry.moodString
|
||||||
|
br
|
||||||
div!= entry.content
|
div!= entry.content
|
||||||
|
|
Loading…
Reference in a new issue