Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { onMount, tick } from "svelte";
import { loading } from "$lib/stores/loading.js";
import { loadAttachmentsFromUrls } from "$lib/utils/loadAttachmentsFromUrls";
import { requireAuthUser } from "$lib/utils/auth";

let { data } = $props();

Expand Down Expand Up @@ -52,7 +53,16 @@
});

if (!res.ok) {
const errorMessage = (await res.json()).message || ERROR_MESSAGES.default;
let errorMessage = ERROR_MESSAGES.default;
try {
const json = await res.json();
errorMessage = json.message || errorMessage;
} catch {
// Response wasn't JSON (e.g., HTML error page)
if (res.status === 401) {
errorMessage = "Authentication required";
}
}
error.set(errorMessage);
console.error("Error while creating conversation: ", errorMessage);
return;
Expand All @@ -78,8 +88,17 @@

onMount(async () => {
try {
// Check if auth is required before processing any query params
const hasQ = page.url.searchParams.has("q");
const hasPrompt = page.url.searchParams.has("prompt");
const hasAttachments = page.url.searchParams.has("attachments");

if ((hasQ || hasPrompt || hasAttachments) && requireAuthUser()) {
return; // Redirecting to login, will return to this URL after
}

// Handle attachments parameter first
if (page.url.searchParams.has("attachments")) {
if (hasAttachments) {
const result = await loadAttachmentsFromUrls(page.url.searchParams);
files = result.files;

Expand Down
12 changes: 11 additions & 1 deletion src/routes/models/[...model]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { pendingMessage } from "$lib/stores/pendingMessage";
import { sanitizeUrlParam } from "$lib/utils/urlParams";
import { loadAttachmentsFromUrls } from "$lib/utils/loadAttachmentsFromUrls";
import { requireAuthUser } from "$lib/utils/auth";

let { data } = $props();

Expand Down Expand Up @@ -64,8 +65,17 @@

onMount(async () => {
try {
// Check if auth is required before processing any query params
const hasQ = page.url.searchParams.has("q");
const hasPrompt = page.url.searchParams.has("prompt");
const hasAttachments = page.url.searchParams.has("attachments");

if ((hasQ || hasPrompt || hasAttachments) && requireAuthUser()) {
return; // Redirecting to login, will return to this URL after
}

// Handle attachments parameter first
if (page.url.searchParams.has("attachments")) {
if (hasAttachments) {
const result = await loadAttachmentsFromUrls(page.url.searchParams);
files = result.files;

Expand Down
Loading