Compare commits

...

1 Commits

Author SHA1 Message Date
80daaa29dc quick fix 2026-02-02 15:24:28 -05:00
11 changed files with 143 additions and 132 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -160,10 +160,10 @@ function AppLayout(props: { children: any }) {
<LeftBar /> <LeftBar />
<div <div
id="center-body" id="center-body"
class="bg-base relative h-screen w-screen overflow-x-hidden md:ml-62.5 md:w-[calc(100vw-500px)]" class="bg-base relative h-screen w-screen overflow-x-hidden md:ml-62.5 md:w-[calc(100vw-500px)] 2xl:ml-72 2xl:w-[calc(100vw-576px)]"
> >
<noscript> <noscript>
<div class="bg-yellow text-crust border-text fixed top-0 z-150 border-b-2 p-4 text-center font-semibold md:w-[calc(100vw-500px)]"> <div class="bg-yellow text-crust border-text fixed top-0 z-150 border-b-2 p-4 text-center font-semibold md:w-[calc(100vw-500px)] xl:ml-72 xl:w-[calc(100vw-576px)]">
JavaScript is disabled. Features will be limited. JavaScript is disabled. Features will be limited.
</div> </div>
</noscript> </noscript>

View File

@@ -366,7 +366,7 @@ export function LeftBar() {
const getMainNavStyles = () => { const getMainNavStyles = () => {
const baseStyles = { const baseStyles = {
"transition-timing-function": "cubic-bezier(0.4, 0, 0.2, 1)", "transition-timing-function": "cubic-bezier(0.4, 0, 0.2, 1)",
width: "250px", width: windowWidth() < 1536 ? "250px" : "288px",
"padding-top": "env(safe-area-inset-top)", "padding-top": "env(safe-area-inset-top)",
"padding-bottom": "env(safe-area-inset-bottom)" "padding-bottom": "env(safe-area-inset-bottom)"
}; };

View File

@@ -39,10 +39,10 @@ export function Btop(props: BtopProps) {
onMount(() => { onMount(() => {
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
setIsMobile(window.innerWidth < BREAKPOINTS.MOBILE); setIsMobile(window.innerWidth < BREAKPOINTS.MOBILE_MAX_WIDTH);
const handleResize = () => { const handleResize = () => {
setIsMobile(window.innerWidth < BREAKPOINTS.MOBILE); setIsMobile(window.innerWidth < BREAKPOINTS.MOBILE_MAX_WIDTH);
}; };
window.addEventListener("resize", handleResize); window.addEventListener("resize", handleResize);
onCleanup(() => window.removeEventListener("resize", handleResize)); onCleanup(() => window.removeEventListener("resize", handleResize));

View File

@@ -1,8 +1,6 @@
import { Accessor, createContext, useContext } from "solid-js"; import { Accessor, createContext, useContext } from "solid-js";
import { createSignal } from "solid-js"; import { createSignal } from "solid-js";
export const STATIC_BAR_SIZE = 250;
const BarsContext = createContext<{ const BarsContext = createContext<{
leftBarVisible: Accessor<boolean>; leftBarVisible: Accessor<boolean>;
setLeftBarVisible: (visible: boolean) => void; setLeftBarVisible: (visible: boolean) => void;

8
src/env/server.ts vendored
View File

@@ -5,8 +5,8 @@ const serverEnvSchema = z.object({
JWT_SECRET_KEY: z.string().min(1), JWT_SECRET_KEY: z.string().min(1),
AWS_REGION: z.string().min(1), AWS_REGION: z.string().min(1),
AWS_S3_BUCKET_NAME: z.string().min(1), AWS_S3_BUCKET_NAME: z.string().min(1),
_AWS_ACCESS_KEY: z.string().min(1), MY_AWS_ACCESS_KEY: z.string().min(1),
_AWS_SECRET_KEY: z.string().min(1), MY_AWS_SECRET_KEY: z.string().min(1),
GOOGLE_CLIENT_SECRET: z.string().min(1), GOOGLE_CLIENT_SECRET: z.string().min(1),
GITHUB_CLIENT_SECRET: z.string().min(1), GITHUB_CLIENT_SECRET: z.string().min(1),
EMAIL_SERVER: z.string().min(1), EMAIL_SERVER: z.string().min(1),
@@ -113,8 +113,8 @@ export const getMissingEnvVars = (): string[] => {
"JWT_SECRET_KEY", "JWT_SECRET_KEY",
"AWS_REGION", "AWS_REGION",
"AWS_S3_BUCKET_NAME", "AWS_S3_BUCKET_NAME",
"_AWS_ACCESS_KEY", "MY_AWS_ACCESS_KEY",
"_AWS_SECRET_KEY", "MY_AWS_SECRET_KEY",
"GOOGLE_CLIENT_SECRET", "GOOGLE_CLIENT_SECRET",
"GITHUB_CLIENT_SECRET", "GITHUB_CLIENT_SECRET",
"EMAIL_SERVER", "EMAIL_SERVER",

View File

@@ -13,8 +13,8 @@ export async function GET(event: APIEvent) {
const key = "api/Gaze/appcast.xml"; const key = "api/Gaze/appcast.xml";
const credentials = { const credentials = {
accessKeyId: env._AWS_ACCESS_KEY, accessKeyId: env.MY_AWS_ACCESS_KEY,
secretAccessKey: env._AWS_SECRET_KEY secretAccessKey: env.MY_AWS_SECRET_KEY
}; };
try { try {

View File

@@ -5,104 +5,107 @@ import { env } from "~/env/server";
/** /**
* Serves Gaze DMG files and delta updates from S3 * Serves Gaze DMG files and delta updates from S3
* This endpoint is used by Sparkle updater to download updates * This endpoint is used by Sparkle updater to download updates
* *
* Handles: * Handles:
* - Full DMG files: /api/downloads/Gaze-0.2.2.dmg * - Full DMG files: /api/downloads/Gaze-0.2.2.dmg
* - Delta updates: /api/downloads/Gaze3-2.delta * - Delta updates: /api/downloads/Gaze3-2.delta
* *
* URL: https://freno.me/api/downloads/[filename] * URL: https://freno.me/api/downloads/[filename]
*/ */
export async function GET(event: APIEvent) { export async function GET(event: APIEvent) {
const filename = event.params.filename; const filename = event.params.filename;
if (!filename) { if (!filename) {
return new Response("Filename required", { return new Response("Filename required", {
status: 400, status: 400,
headers: { headers: {
"Content-Type": "text/plain" "Content-Type": "text/plain"
} }
}); });
} }
// Validate filename format (only allow Gaze files) // Validate filename format (only allow Gaze files)
if (!filename.startsWith("Gaze") || (!filename.endsWith(".dmg") && !filename.endsWith(".delta"))) { if (
return new Response("Invalid file format", { !filename.startsWith("Gaze") ||
status: 400, (!filename.endsWith(".dmg") && !filename.endsWith(".delta"))
headers: { ) {
"Content-Type": "text/plain" return new Response("Invalid file format", {
} status: 400,
}); headers: {
} "Content-Type": "text/plain"
}
const bucket = env.VITE_DOWNLOAD_BUCKET_STRING; });
const key = `downloads/${filename}`; }
const credentials = { const bucket = env.VITE_DOWNLOAD_BUCKET_STRING;
accessKeyId: env._AWS_ACCESS_KEY, const key = `downloads/${filename}`;
secretAccessKey: env._AWS_SECRET_KEY
}; const credentials = {
accessKeyId: env.MY_AWS_ACCESS_KEY,
try { secretAccessKey: env.MY_AWS_SECRET_KEY
const client = new S3Client({ };
region: env.AWS_REGION,
credentials: credentials try {
}); const client = new S3Client({
region: env.AWS_REGION,
const command = new GetObjectCommand({ credentials: credentials
Bucket: bucket, });
Key: key
}); const command = new GetObjectCommand({
Bucket: bucket,
const response = await client.send(command); Key: key
});
if (!response.Body) {
console.error(`File not found in S3: ${key}`); const response = await client.send(command);
return new Response("File not found", {
status: 404, if (!response.Body) {
headers: { console.error(`File not found in S3: ${key}`);
"Content-Type": "text/plain" return new Response("File not found", {
} status: 404,
}); headers: {
"Content-Type": "text/plain"
} }
});
// Get content type based on file extension
const contentType = filename.endsWith(".dmg")
? "application/x-apple-diskimage"
: "application/octet-stream";
// Stream the file content from S3
const body = await response.Body.transformToByteArray();
console.log(`✓ Serving ${filename} (${body.length} bytes)`);
return new Response(body, {
status: 200,
headers: {
"Content-Type": contentType,
"Content-Length": body.length.toString(),
"Content-Disposition": `attachment; filename="${filename}"`,
"Cache-Control": "public, max-age=86400", // Cache for 24 hours
"Access-Control-Allow-Origin": "*"
}
});
} catch (error) {
console.error(`Failed to fetch ${filename} from S3:`, error);
// Check if it's a not found error
if (error instanceof Error && error.name === "NoSuchKey") {
return new Response("File not found in storage", {
status: 404,
headers: {
"Content-Type": "text/plain"
}
});
}
return new Response("Internal Server Error", {
status: 500,
headers: {
"Content-Type": "text/plain"
}
});
} }
// Get content type based on file extension
const contentType = filename.endsWith(".dmg")
? "application/x-apple-diskimage"
: "application/octet-stream";
// Stream the file content from S3
const body = await response.Body.transformToByteArray();
console.log(`✓ Serving ${filename} (${body.length} bytes)`);
return new Response(body, {
status: 200,
headers: {
"Content-Type": contentType,
"Content-Length": body.length.toString(),
"Content-Disposition": `attachment; filename="${filename}"`,
"Cache-Control": "public, max-age=86400", // Cache for 24 hours
"Access-Control-Allow-Origin": "*"
}
});
} catch (error) {
console.error(`Failed to fetch ${filename} from S3:`, error);
// Check if it's a not found error
if (error instanceof Error && error.name === "NoSuchKey") {
return new Response("File not found in storage", {
status: 404,
headers: {
"Content-Type": "text/plain"
}
});
}
return new Response("Internal Server Error", {
status: 500,
headers: {
"Content-Type": "text/plain"
}
});
}
} }

View File

@@ -27,8 +27,8 @@ vi.mock("@aws-sdk/s3-request-presigner", () => ({
// Mock environment variables // Mock environment variables
process.env.AWS_REGION = "us-east-1"; process.env.AWS_REGION = "us-east-1";
process.env._AWS_ACCESS_KEY = "test-access-key"; process.env.MY_AWS_ACCESS_KEY = "test-access-key";
process.env._AWS_SECRET_KEY = "test-secret-key"; process.env.MY_AWS_SECRET_KEY = "test-secret-key";
process.env.VITE_DOWNLOAD_BUCKET_STRING = "test-bucket"; process.env.VITE_DOWNLOAD_BUCKET_STRING = "test-bucket";
describe("downloads router", () => { describe("downloads router", () => {

View File

@@ -1,6 +1,10 @@
import { createTRPCRouter, publicProcedure } from "../utils"; import { createTRPCRouter, publicProcedure } from "../utils";
import { z } from "zod"; import { z } from "zod";
import { S3Client, GetObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3"; import {
S3Client,
GetObjectCommand,
ListObjectsV2Command
} from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { env } from "~/env/server"; import { env } from "~/env/server";
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
@@ -14,7 +18,10 @@ const assets: Record<string, string> = {
/** /**
* Get the latest Gaze DMG from S3 by finding the most recent file in downloads/ folder * Get the latest Gaze DMG from S3 by finding the most recent file in downloads/ folder
*/ */
async function getLatestGazeDMG(client: S3Client, bucket: string): Promise<string> { async function getLatestGazeDMG(
client: S3Client,
bucket: string
): Promise<string> {
try { try {
const listCommand = new ListObjectsV2Command({ const listCommand = new ListObjectsV2Command({
Bucket: bucket, Bucket: bucket,
@@ -23,19 +30,19 @@ async function getLatestGazeDMG(client: S3Client, bucket: string): Promise<strin
}); });
const response = await client.send(listCommand); const response = await client.send(listCommand);
if (!response.Contents || response.Contents.length === 0) { if (!response.Contents || response.Contents.length === 0) {
throw new Error("No Gaze DMG files found in S3"); throw new Error("No Gaze DMG files found in S3");
} }
// Filter for .dmg files only and sort by LastModified (newest first) // Filter for .dmg files only and sort by LastModified (newest first)
const dmgFiles = response.Contents const dmgFiles = response.Contents.filter((obj) =>
.filter((obj) => obj.Key?.endsWith(".dmg")) obj.Key?.endsWith(".dmg")
.sort((a, b) => { ).sort((a, b) => {
const dateA = a.LastModified?.getTime() || 0; const dateA = a.LastModified?.getTime() || 0;
const dateB = b.LastModified?.getTime() || 0; const dateB = b.LastModified?.getTime() || 0;
return dateB - dateA; // Descending order (newest first) return dateB - dateA; // Descending order (newest first)
}); });
if (dmgFiles.length === 0) { if (dmgFiles.length === 0) {
throw new Error("No .dmg files found in downloads/Gaze-* prefix"); throw new Error("No .dmg files found in downloads/Gaze-* prefix");
@@ -55,10 +62,10 @@ export const downloadsRouter = createTRPCRouter({
.input(z.object({ asset_name: z.string() })) .input(z.object({ asset_name: z.string() }))
.query(async ({ input }) => { .query(async ({ input }) => {
const bucket = env.VITE_DOWNLOAD_BUCKET_STRING; const bucket = env.VITE_DOWNLOAD_BUCKET_STRING;
const credentials = { const credentials = {
accessKeyId: env._AWS_ACCESS_KEY, accessKeyId: env.MY_AWS_ACCESS_KEY,
secretAccessKey: env._AWS_SECRET_KEY secretAccessKey: env.MY_AWS_SECRET_KEY
}; };
const client = new S3Client({ const client = new S3Client({
@@ -75,7 +82,7 @@ export const downloadsRouter = createTRPCRouter({
} else { } else {
// Use static mapping for other assets // Use static mapping for other assets
fileKey = assets[input.asset_name]; fileKey = assets[input.asset_name];
if (!fileKey) { if (!fileKey) {
throw new TRPCError({ throw new TRPCError({
code: "NOT_FOUND", code: "NOT_FOUND",
@@ -98,7 +105,10 @@ export const downloadsRouter = createTRPCRouter({
console.error(error); console.error(error);
throw new TRPCError({ throw new TRPCError({
code: "INTERNAL_SERVER_ERROR", code: "INTERNAL_SERVER_ERROR",
message: error instanceof Error ? error.message : "Failed to generate download URL" message:
error instanceof Error
? error.message
: "Failed to generate download URL"
}); });
} }
}) })

View File

@@ -46,8 +46,8 @@ export const miscRouter = createTRPCRouter({
} }
const credentials = { const credentials = {
accessKeyId: env._AWS_ACCESS_KEY, accessKeyId: env.MY_AWS_ACCESS_KEY,
secretAccessKey: env._AWS_SECRET_KEY secretAccessKey: env.MY_AWS_SECRET_KEY
}; };
try { try {
@@ -80,8 +80,8 @@ export const miscRouter = createTRPCRouter({
) )
.mutation(async ({ input }) => { .mutation(async ({ input }) => {
const credentials = { const credentials = {
accessKeyId: env._AWS_ACCESS_KEY, accessKeyId: env.MY_AWS_ACCESS_KEY,
secretAccessKey: env._AWS_SECRET_KEY secretAccessKey: env.MY_AWS_SECRET_KEY
}; };
try { try {
@@ -135,8 +135,8 @@ export const miscRouter = createTRPCRouter({
.query(async ({ input }) => { .query(async ({ input }) => {
try { try {
const credentials = { const credentials = {
accessKeyId: env._AWS_ACCESS_KEY, accessKeyId: env.MY_AWS_ACCESS_KEY,
secretAccessKey: env._AWS_SECRET_KEY secretAccessKey: env.MY_AWS_SECRET_KEY
}; };
const client = new S3Client({ const client = new S3Client({
@@ -195,8 +195,8 @@ export const miscRouter = createTRPCRouter({
.mutation(async ({ input }) => { .mutation(async ({ input }) => {
try { try {
const credentials = { const credentials = {
accessKeyId: env._AWS_ACCESS_KEY, accessKeyId: env.MY_AWS_ACCESS_KEY,
secretAccessKey: env._AWS_SECRET_KEY secretAccessKey: env.MY_AWS_SECRET_KEY
}; };
const s3params = { const s3params = {
@@ -234,8 +234,8 @@ export const miscRouter = createTRPCRouter({
.mutation(async ({ input }) => { .mutation(async ({ input }) => {
try { try {
const credentials = { const credentials = {
accessKeyId: env._AWS_ACCESS_KEY, accessKeyId: env.MY_AWS_ACCESS_KEY,
secretAccessKey: env._AWS_SECRET_KEY secretAccessKey: env.MY_AWS_SECRET_KEY
}; };
const s3params = { const s3params = {