removed excess comments
This commit is contained in:
@@ -7,7 +7,6 @@ import { CACHE_CONFIG } from "~/config";
|
||||
|
||||
const BLOG_CACHE_TTL = CACHE_CONFIG.BLOG_CACHE_TTL_MS;
|
||||
|
||||
// Shared cache function for all blog posts
|
||||
const getAllPostsData = async (privilegeLevel: string) => {
|
||||
return withCacheAndStale(
|
||||
`blog-posts-${privilegeLevel}`,
|
||||
@@ -15,7 +14,6 @@ const getAllPostsData = async (privilegeLevel: string) => {
|
||||
async () => {
|
||||
const conn = ConnectionFactory();
|
||||
|
||||
// Fetch all posts with aggregated data
|
||||
let postsQuery = `
|
||||
SELECT
|
||||
p.id,
|
||||
@@ -73,10 +71,8 @@ const getAllPostsData = async (privilegeLevel: string) => {
|
||||
|
||||
export const blogRouter = createTRPCRouter({
|
||||
getRecentPosts: publicProcedure.query(async ({ ctx }) => {
|
||||
// Always use public privilege level for recent posts (only show published)
|
||||
const allPostsData = await getAllPostsData("public");
|
||||
|
||||
// Return only the 3 most recent posts (already sorted DESC by date)
|
||||
return allPostsData.posts.slice(0, 3);
|
||||
}),
|
||||
|
||||
|
||||
@@ -442,7 +442,6 @@ export const databaseRouter = createTRPCRouter({
|
||||
try {
|
||||
const conn = ConnectionFactory();
|
||||
|
||||
// Check if post is being published for the first time
|
||||
let shouldSetPublishDate = false;
|
||||
if (input.published !== undefined && input.published !== null) {
|
||||
const currentPostQuery = await conn.execute({
|
||||
@@ -451,7 +450,6 @@ export const databaseRouter = createTRPCRouter({
|
||||
});
|
||||
const currentPost = currentPostQuery.rows[0] as any;
|
||||
|
||||
// Set publish date if transitioning from unpublished to published and date is null
|
||||
if (
|
||||
currentPost &&
|
||||
!currentPost.published &&
|
||||
@@ -500,14 +498,12 @@ export const databaseRouter = createTRPCRouter({
|
||||
first = false;
|
||||
}
|
||||
|
||||
// Set date if publishing for the first time
|
||||
if (shouldSetPublishDate) {
|
||||
query += first ? "date = ?" : ", date = ?";
|
||||
params.push(new Date().toISOString());
|
||||
first = false;
|
||||
}
|
||||
|
||||
// Always update last_edited_date
|
||||
query += first ? "last_edited_date = ?" : ", last_edited_date = ?";
|
||||
params.push(new Date().toISOString());
|
||||
first = false;
|
||||
@@ -581,10 +577,6 @@ export const databaseRouter = createTRPCRouter({
|
||||
}
|
||||
}),
|
||||
|
||||
// ============================================================
|
||||
// Post Likes Routes
|
||||
// ============================================================
|
||||
|
||||
addPostLike: publicProcedure
|
||||
.input(togglePostLikeMutationSchema)
|
||||
.mutation(async ({ input }) => {
|
||||
@@ -640,10 +632,6 @@ export const databaseRouter = createTRPCRouter({
|
||||
}
|
||||
}),
|
||||
|
||||
// ============================================================
|
||||
// User Routes
|
||||
// ============================================================
|
||||
|
||||
getUserById: publicProcedure
|
||||
.input(getUserByIdSchema)
|
||||
.query(async ({ input }) => {
|
||||
|
||||
@@ -226,7 +226,6 @@ export const gitActivityRouter = createTRPCRouter({
|
||||
});
|
||||
}),
|
||||
|
||||
// Get GitHub contribution activity (for heatmap)
|
||||
getGitHubActivity: publicProcedure.query(async () => {
|
||||
return withCacheAndStale(
|
||||
"github-activity",
|
||||
@@ -306,7 +305,6 @@ export const gitActivityRouter = createTRPCRouter({
|
||||
});
|
||||
}),
|
||||
|
||||
// Get Gitea contribution activity (for heatmap)
|
||||
getGiteaActivity: publicProcedure.query(async () => {
|
||||
return withCacheAndStale(
|
||||
"gitea-activity",
|
||||
|
||||
@@ -3,13 +3,10 @@ import { env } from "~/env/server";
|
||||
|
||||
export const infillRouter = createTRPCRouter({
|
||||
getConfig: publicProcedure.query(({ ctx }) => {
|
||||
// Only admins get the config
|
||||
if (ctx.privilegeLevel !== "admin") {
|
||||
return { endpoint: null, token: null };
|
||||
}
|
||||
|
||||
// Return endpoint and token (or null if not configured)
|
||||
// Now supports both desktop and mobile (fullscreen mode)
|
||||
return {
|
||||
endpoint: env.VITE_INFILL_ENDPOINT || null,
|
||||
token: env.INFILL_BEARER_TOKEN || null
|
||||
|
||||
@@ -7,21 +7,15 @@ import { lineagePvpRouter } from "./lineage/pvp";
|
||||
import { lineageMaintenanceRouter } from "./lineage/maintenance";
|
||||
|
||||
export const lineageRouter = createTRPCRouter({
|
||||
// Authentication
|
||||
auth: lineageAuthRouter,
|
||||
|
||||
// Database Management
|
||||
database: lineageDatabaseRouter,
|
||||
|
||||
// PvP
|
||||
pvp: lineagePvpRouter,
|
||||
|
||||
// JSON Service
|
||||
jsonService: lineageJsonServiceRouter,
|
||||
|
||||
// Misc (Analytics, Tokens, etc.)
|
||||
misc: lineageMiscRouter,
|
||||
|
||||
// Maintenance (Protected)
|
||||
maintenance: lineageMaintenanceRouter,
|
||||
});
|
||||
maintenance: lineageMaintenanceRouter
|
||||
});
|
||||
|
||||
@@ -427,7 +427,6 @@ export const lineageDatabaseRouter = createTRPCRouter({
|
||||
`Failed to delete database ${db_name} in cron job:`,
|
||||
error
|
||||
);
|
||||
// Continue with other deletions even if one fails
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -455,7 +454,6 @@ export const lineageDatabaseRouter = createTRPCRouter({
|
||||
`Failed to delete database ${db_name} in cron job:`,
|
||||
error
|
||||
);
|
||||
// Continue with other deletions even if one fails
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { createTRPCRouter, publicProcedure } from "../../utils";
|
||||
|
||||
// Attack data imports
|
||||
import playerAttacks from "~/lineage-json/attack-route/playerAttacks.json";
|
||||
import mageBooks from "~/lineage-json/attack-route/mageBooks.json";
|
||||
import mageSpells from "~/lineage-json/attack-route/mageSpells.json";
|
||||
@@ -12,21 +11,17 @@ import paladinBooks from "~/lineage-json/attack-route/paladinBooks.json";
|
||||
import paladinSpells from "~/lineage-json/attack-route/paladinSpells.json";
|
||||
import summons from "~/lineage-json/attack-route/summons.json";
|
||||
|
||||
// Conditions data imports
|
||||
import conditions from "~/lineage-json/conditions-route/conditions.json";
|
||||
import debilitations from "~/lineage-json/conditions-route/debilitations.json";
|
||||
import sanityDebuffs from "~/lineage-json/conditions-route/sanityDebuffs.json";
|
||||
|
||||
// Dungeon data imports
|
||||
import dungeons from "~/lineage-json/dungeon-route/dungeons.json";
|
||||
import specialEncounters from "~/lineage-json/dungeon-route/specialEncounters.json";
|
||||
|
||||
// Enemy data imports
|
||||
import bosses from "~/lineage-json/enemy-route/bosses.json";
|
||||
import enemies from "~/lineage-json/enemy-route/enemy.json";
|
||||
import enemyAttacks from "~/lineage-json/enemy-route/enemyAttacks.json";
|
||||
|
||||
// Item data imports
|
||||
import arrows from "~/lineage-json/item-route/arrows.json";
|
||||
import bows from "~/lineage-json/item-route/bows.json";
|
||||
import foci from "~/lineage-json/item-route/foci.json";
|
||||
@@ -69,7 +64,7 @@ export const lineageJsonServiceRouter = createTRPCRouter({
|
||||
rangerSpells,
|
||||
paladinBooks,
|
||||
paladinSpells,
|
||||
summons,
|
||||
summons
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -78,7 +73,7 @@ export const lineageJsonServiceRouter = createTRPCRouter({
|
||||
ok: true,
|
||||
conditions,
|
||||
debilitations,
|
||||
sanityDebuffs,
|
||||
sanityDebuffs
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -86,7 +81,7 @@ export const lineageJsonServiceRouter = createTRPCRouter({
|
||||
return {
|
||||
ok: true,
|
||||
dungeons,
|
||||
specialEncounters,
|
||||
specialEncounters
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -95,7 +90,7 @@ export const lineageJsonServiceRouter = createTRPCRouter({
|
||||
ok: true,
|
||||
bosses,
|
||||
enemies,
|
||||
enemyAttacks,
|
||||
enemyAttacks
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -120,7 +115,7 @@ export const lineageJsonServiceRouter = createTRPCRouter({
|
||||
prefix,
|
||||
potions,
|
||||
poison,
|
||||
staves,
|
||||
staves
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -134,7 +129,7 @@ export const lineageJsonServiceRouter = createTRPCRouter({
|
||||
otherOptions,
|
||||
healthOptions,
|
||||
sanityOptions,
|
||||
pvpRewards,
|
||||
pvpRewards
|
||||
};
|
||||
}),
|
||||
})
|
||||
});
|
||||
|
||||
@@ -28,10 +28,6 @@ const assets: Record<string, string> = {
|
||||
};
|
||||
|
||||
export const miscRouter = createTRPCRouter({
|
||||
// ============================================================
|
||||
// Downloads endpoint
|
||||
// ============================================================
|
||||
|
||||
getDownloadUrl: publicProcedure
|
||||
.input(z.object({ asset_name: z.string() }))
|
||||
.query(async ({ input }) => {
|
||||
@@ -73,10 +69,6 @@ export const miscRouter = createTRPCRouter({
|
||||
}
|
||||
}),
|
||||
|
||||
// ============================================================
|
||||
// S3 Operations
|
||||
// ============================================================
|
||||
|
||||
getPreSignedURL: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
@@ -99,10 +91,10 @@ export const miscRouter = createTRPCRouter({
|
||||
|
||||
const sanitizeForS3 = (str: string) => {
|
||||
return str
|
||||
.replace(/\s+/g, "-") // Replace spaces with hyphens
|
||||
.replace(/[^\w\-\.]/g, "") // Remove special characters except hyphens, dots, and word chars
|
||||
.replace(/\-+/g, "-") // Replace multiple hyphens with single hyphen
|
||||
.replace(/^-+|-+$/g, ""); // Remove leading/trailing hyphens
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/[^\w\-\.]/g, "")
|
||||
.replace(/\-+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
};
|
||||
|
||||
const sanitizedTitle = sanitizeForS3(input.title);
|
||||
@@ -210,10 +202,6 @@ export const miscRouter = createTRPCRouter({
|
||||
}
|
||||
}),
|
||||
|
||||
// ============================================================
|
||||
// Password Hashing
|
||||
// ============================================================
|
||||
|
||||
hashPassword: publicProcedure
|
||||
.input(z.object({ password: z.string().min(8) }))
|
||||
.mutation(async ({ input }) => {
|
||||
@@ -249,10 +237,6 @@ export const miscRouter = createTRPCRouter({
|
||||
}
|
||||
}),
|
||||
|
||||
// ============================================================
|
||||
// Contact Form
|
||||
// ============================================================
|
||||
|
||||
sendContactRequest: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
@@ -324,7 +308,6 @@ export const miscRouter = createTRPCRouter({
|
||||
|
||||
return { message: "email sent" };
|
||||
} catch (error) {
|
||||
// Provide specific error messages for different failure types
|
||||
if (error instanceof TimeoutError) {
|
||||
console.error("Contact form email timeout:", error.message);
|
||||
throw new TRPCError({
|
||||
@@ -359,10 +342,6 @@ export const miscRouter = createTRPCRouter({
|
||||
}
|
||||
}),
|
||||
|
||||
// ============================================================
|
||||
// Account Deletion Request
|
||||
// ============================================================
|
||||
|
||||
sendDeletionRequestEmail: publicProcedure
|
||||
.input(z.object({ email: z.string().email() }))
|
||||
.mutation(async ({ input }) => {
|
||||
@@ -384,7 +363,6 @@ export const miscRouter = createTRPCRouter({
|
||||
const apiKey = env.SENDINBLUE_KEY;
|
||||
const apiUrl = "https://api.sendinblue.com/v3/smtp/email";
|
||||
|
||||
// Email to admin
|
||||
const sendinblueMyData = {
|
||||
sender: {
|
||||
name: "freno.me",
|
||||
@@ -395,7 +373,6 @@ export const miscRouter = createTRPCRouter({
|
||||
subject: "Life and Lineage Acct Deletion"
|
||||
};
|
||||
|
||||
// Email to user
|
||||
const sendinblueUserData = {
|
||||
sender: {
|
||||
name: "freno.me",
|
||||
@@ -407,7 +384,6 @@ export const miscRouter = createTRPCRouter({
|
||||
};
|
||||
|
||||
try {
|
||||
// Send both emails with retry logic
|
||||
await Promise.all([
|
||||
fetchWithRetry(
|
||||
async () => {
|
||||
@@ -459,7 +435,6 @@ export const miscRouter = createTRPCRouter({
|
||||
|
||||
return { message: "request sent" };
|
||||
} catch (error) {
|
||||
// Provide specific error messages
|
||||
if (error instanceof TimeoutError) {
|
||||
console.error("Deletion request email timeout:", error.message);
|
||||
throw new TRPCError({
|
||||
|
||||
@@ -5,7 +5,6 @@ import { getUserID } from "~/server/auth";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import diff from "fast-diff";
|
||||
|
||||
// Helper to create diff patch between two HTML strings
|
||||
export function createDiffPatch(
|
||||
oldContent: string,
|
||||
newContent: string
|
||||
@@ -14,7 +13,6 @@ export function createDiffPatch(
|
||||
return JSON.stringify(changes);
|
||||
}
|
||||
|
||||
// Helper to apply diff patch to content
|
||||
export function applyDiffPatch(baseContent: string, patchJson: string): string {
|
||||
const changes = JSON.parse(patchJson);
|
||||
let result = "";
|
||||
@@ -34,12 +32,10 @@ export function applyDiffPatch(baseContent: string, patchJson: string): string {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Helper to reconstruct content from history chain
|
||||
async function reconstructContent(
|
||||
conn: ReturnType<typeof ConnectionFactory>,
|
||||
historyId: number
|
||||
): Promise<string> {
|
||||
// Get the full chain from root to this history entry
|
||||
const chain: Array<{
|
||||
id: number;
|
||||
parent_id: number | null;
|
||||
@@ -70,7 +66,6 @@ async function reconstructContent(
|
||||
currentId = row.parent_id;
|
||||
}
|
||||
|
||||
// Apply patches in order
|
||||
let content = "";
|
||||
for (const entry of chain) {
|
||||
content = applyDiffPatch(content, entry.content);
|
||||
@@ -80,7 +75,6 @@ async function reconstructContent(
|
||||
}
|
||||
|
||||
export const postHistoryRouter = createTRPCRouter({
|
||||
// Save a new history entry
|
||||
save: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
@@ -124,10 +118,8 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
});
|
||||
}
|
||||
|
||||
// Create diff patch
|
||||
const diffPatch = createDiffPatch(input.previousContent, input.content);
|
||||
|
||||
// Insert history entry
|
||||
const result = await conn.execute({
|
||||
sql: `
|
||||
INSERT INTO PostHistory (post_id, parent_id, content, is_saved)
|
||||
@@ -141,7 +133,6 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
]
|
||||
});
|
||||
|
||||
// Prune old history entries if we exceed 100
|
||||
const countResult = await conn.execute({
|
||||
sql: "SELECT COUNT(*) as count FROM PostHistory WHERE post_id = ?",
|
||||
args: [input.postId]
|
||||
@@ -149,7 +140,6 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
|
||||
const count = (countResult.rows[0] as { count: number }).count;
|
||||
if (count > 100) {
|
||||
// Get the oldest entries to delete (keep most recent 100)
|
||||
const toDelete = await conn.execute({
|
||||
sql: `
|
||||
SELECT id FROM PostHistory
|
||||
@@ -160,7 +150,6 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
args: [input.postId, count - 100]
|
||||
});
|
||||
|
||||
// Delete old entries
|
||||
for (const row of toDelete.rows) {
|
||||
const entry = row as { id: number };
|
||||
await conn.execute({
|
||||
@@ -176,7 +165,6 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
};
|
||||
}),
|
||||
|
||||
// Get history for a post with reconstructed content
|
||||
getHistory: publicProcedure
|
||||
.input(z.object({ postId: z.number() }))
|
||||
.query(async ({ input, ctx }) => {
|
||||
@@ -191,7 +179,6 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
|
||||
const conn = ConnectionFactory();
|
||||
|
||||
// Verify post exists and user is author
|
||||
const postCheck = await conn.execute({
|
||||
sql: "SELECT author_id FROM Post WHERE id = ?",
|
||||
args: [input.postId]
|
||||
@@ -212,7 +199,6 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
});
|
||||
}
|
||||
|
||||
// Get all history entries for this post
|
||||
const result = await conn.execute({
|
||||
sql: `
|
||||
SELECT id, parent_id, content, created_at, is_saved
|
||||
@@ -231,7 +217,6 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
is_saved: number;
|
||||
}>;
|
||||
|
||||
// Reconstruct content for each entry by applying diffs sequentially
|
||||
const historyWithContent: Array<{
|
||||
id: number;
|
||||
parent_id: number | null;
|
||||
@@ -255,7 +240,6 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
return historyWithContent;
|
||||
}),
|
||||
|
||||
// Restore content from a history entry
|
||||
restore: publicProcedure
|
||||
.input(z.object({ historyId: z.number() }))
|
||||
.query(async ({ input, ctx }) => {
|
||||
@@ -270,7 +254,6 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
|
||||
const conn = ConnectionFactory();
|
||||
|
||||
// Get history entry and verify ownership
|
||||
const historyResult = await conn.execute({
|
||||
sql: `
|
||||
SELECT ph.post_id
|
||||
@@ -288,12 +271,9 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
});
|
||||
}
|
||||
|
||||
const historyEntry = historyResult.rows[0] as { post_id: number };
|
||||
|
||||
// Verify user is post author
|
||||
const postCheck = await conn.execute({
|
||||
sql: "SELECT author_id FROM Post WHERE id = ?",
|
||||
args: [historyEntry.post_id]
|
||||
args: [historyResult.post_id]
|
||||
});
|
||||
|
||||
const post = postCheck.rows[0] as { author_id: string };
|
||||
@@ -304,7 +284,6 @@ export const postHistoryRouter = createTRPCRouter({
|
||||
});
|
||||
}
|
||||
|
||||
// Reconstruct content from history chain
|
||||
const content = await reconstructContent(conn, input.historyId);
|
||||
|
||||
return { content };
|
||||
|
||||
@@ -152,7 +152,6 @@ export const userRouter = createTRPCRouter({
|
||||
|
||||
const { oldPassword, newPassword, newPasswordConfirmation } = input;
|
||||
|
||||
// Schema already validates password match, but double check
|
||||
if (newPassword !== newPasswordConfirmation) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
@@ -226,7 +225,6 @@ export const userRouter = createTRPCRouter({
|
||||
|
||||
const { newPassword, newPasswordConfirmation } = input;
|
||||
|
||||
// Schema already validates password match, but double check
|
||||
if (newPassword !== newPasswordConfirmation) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
|
||||
@@ -26,7 +26,6 @@ async function createContextInner(event: APIEvent): Promise<Context> {
|
||||
privilegeLevel = payload.id === env.ADMIN_ID ? "admin" : "user";
|
||||
}
|
||||
} catch (err) {
|
||||
// Silently clear invalid token (401s are expected for non-authenticated users)
|
||||
setCookie(event.nativeEvent, "userIDToken", "", {
|
||||
maxAge: 0,
|
||||
expires: new Date("2016-10-05")
|
||||
@@ -57,7 +56,7 @@ const enforceUserIsAuthed = t.middleware(({ ctx, next }) => {
|
||||
return next({
|
||||
ctx: {
|
||||
...ctx,
|
||||
userId: ctx.userId // userId is non-null here
|
||||
userId: ctx.userId
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -72,11 +71,10 @@ const enforceUserIsAdmin = t.middleware(({ ctx, next }) => {
|
||||
return next({
|
||||
ctx: {
|
||||
...ctx,
|
||||
userId: ctx.userId! // userId is non-null for admins
|
||||
userId: ctx.userId!
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Protected procedures
|
||||
export const protectedProcedure = t.procedure.use(enforceUserIsAuthed);
|
||||
export const adminProcedure = t.procedure.use(enforceUserIsAdmin);
|
||||
|
||||
Reference in New Issue
Block a user