v3: correctly using SITE_NAME across the app, added notifications on comments
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 44s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 44s
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
import { Context, Next, send } from "@oak/oak";
|
||||
import { OG_SITE_NAME } from "../config.ts";
|
||||
|
||||
async function serveIndexHtml(
|
||||
context: Context<Record<string, object>>,
|
||||
root: string,
|
||||
) {
|
||||
const filePath = `${root}/index.html`;
|
||||
const raw = await Deno.readTextFile(filePath);
|
||||
const html = raw.replaceAll("__SITE_NAME__", OG_SITE_NAME);
|
||||
context.response.type = "text/html";
|
||||
context.response.body = html;
|
||||
}
|
||||
|
||||
export function routeStaticFilesFrom(staticPaths: string[]) {
|
||||
return async (context: Context<Record<string, object>>, next: Next) => {
|
||||
const pathname = context.request.url.pathname;
|
||||
|
||||
// Serve index.html with runtime placeholder replacement
|
||||
if (pathname === "/" || pathname === "/index.html") {
|
||||
await serveIndexHtml(context, staticPaths[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const path of staticPaths) {
|
||||
try {
|
||||
await send(context, context.request.url.pathname, {
|
||||
root: path,
|
||||
index: "index.html",
|
||||
});
|
||||
await send(context, pathname, { root: path });
|
||||
return;
|
||||
} catch {
|
||||
continue;
|
||||
@@ -15,7 +32,7 @@ export function routeStaticFilesFrom(staticPaths: string[]) {
|
||||
}
|
||||
|
||||
// SPA fallback: serve index.html so client-side routes work on direct navigation
|
||||
await send(context, "/index.html", { root: staticPaths[0] });
|
||||
await serveIndexHtml(context, staticPaths[0]);
|
||||
await next();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -617,7 +617,8 @@ export type NotificationType =
|
||||
| "user_dump_posted"
|
||||
| "playlist_dump_added"
|
||||
| "dump_upvoted"
|
||||
| "user_mentioned";
|
||||
| "user_mentioned"
|
||||
| "dump_commented";
|
||||
|
||||
export interface PlaylistFollowedData {
|
||||
followerId: string;
|
||||
@@ -661,13 +662,22 @@ export interface UserMentionedData {
|
||||
dumpId?: string;
|
||||
}
|
||||
|
||||
export interface DumpCommentedData {
|
||||
commenterId: string;
|
||||
commenterUsername: string;
|
||||
commentId: string;
|
||||
dumpId: string;
|
||||
dumpTitle: string;
|
||||
}
|
||||
|
||||
export type NotificationData =
|
||||
| PlaylistFollowedData
|
||||
| UserFollowedData
|
||||
| UserDumpPostedData
|
||||
| PlaylistDumpAddedData
|
||||
| DumpUpvotedData
|
||||
| UserMentionedData;
|
||||
| UserMentionedData
|
||||
| DumpCommentedData;
|
||||
|
||||
export interface Notification {
|
||||
id: string;
|
||||
|
||||
@@ -5,7 +5,10 @@ import {
|
||||
} from "../model/interfaces.ts";
|
||||
import { type SQLOutputValue } from "node:sqlite";
|
||||
import { commentRowToApi, db, isCommentRow } from "../model/db.ts";
|
||||
import { notifyMentions } from "./notification-service.ts";
|
||||
import {
|
||||
notifyDumpOwnerNewComment,
|
||||
notifyMentions,
|
||||
} from "./notification-service.ts";
|
||||
import { linkAttachments } from "./attachment-service.ts";
|
||||
|
||||
const SELECT_COLS =
|
||||
@@ -66,6 +69,7 @@ export function createComment(
|
||||
const dumpRow = db.prepare(`SELECT title FROM dumps WHERE id = ?;`).get(
|
||||
dumpId,
|
||||
) as { title: string } | undefined;
|
||||
notifyDumpOwnerNewComment(userId, id, dumpId);
|
||||
notifyMentions(userId, body, "comment", id, dumpRow?.title ?? "", dumpId);
|
||||
linkAttachments(body, id);
|
||||
return comment;
|
||||
|
||||
@@ -276,6 +276,36 @@ export function notifyMentions(
|
||||
}
|
||||
}
|
||||
|
||||
export function notifyDumpOwnerNewComment(
|
||||
commenterId: string,
|
||||
commentId: string,
|
||||
dumpId: string,
|
||||
): void {
|
||||
const commenterRow = db.prepare(
|
||||
`SELECT username FROM users WHERE id = ?;`,
|
||||
).get(commenterId) as { username: string } | undefined;
|
||||
|
||||
const dumpRow = db.prepare(
|
||||
`SELECT title, user_id FROM dumps WHERE id = ?;`,
|
||||
).get(dumpId) as { title: string; user_id: string } | undefined;
|
||||
|
||||
if (!commenterRow || !dumpRow) return;
|
||||
if (commenterId === dumpRow.user_id) return; // no self-notification
|
||||
|
||||
createNotification(
|
||||
dumpRow.user_id,
|
||||
"dump_commented",
|
||||
{
|
||||
commenterId,
|
||||
commenterUsername: commenterRow.username,
|
||||
commentId,
|
||||
dumpId,
|
||||
dumpTitle: dumpRow.title,
|
||||
},
|
||||
`comment:${commentId}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function notifyPlaylistFollowersNewDump(
|
||||
playlistId: string,
|
||||
playlistTitle: string,
|
||||
|
||||
Reference in New Issue
Block a user