mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-28 17:29:36 +02:00
api
This commit is contained in:
parent
22b2cb3679
commit
20238ccdce
1 changed files with 11 additions and 5 deletions
|
@ -432,7 +432,7 @@ export const actions: Actions = {
|
||||||
const previous = formData.get('previous') as string;
|
const previous = formData.get('previous') as string;
|
||||||
const page = formData.get('page') as string;
|
const page = formData.get('page') as string;
|
||||||
|
|
||||||
if (!event.locals.user || !event.cookies.get('auth')) {
|
if (!event.locals.user) {
|
||||||
return {
|
return {
|
||||||
status: 401,
|
status: 401,
|
||||||
body: { message: 'Unauthorized' }
|
body: { message: 'Unauthorized' }
|
||||||
|
@ -446,8 +446,16 @@ export const actions: Actions = {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start with the current URL if next and previous are not provided
|
// Start with the provided URL or default to the filtered adventures endpoint
|
||||||
let url: string = next || previous || event.url.toString();
|
let url: string = next || previous || `${serverEndpoint}/api/adventures/filtered`;
|
||||||
|
|
||||||
|
// Extract the path and query parameters after '/api'
|
||||||
|
const apiIndex = url.indexOf('/api');
|
||||||
|
if (apiIndex !== -1) {
|
||||||
|
url = `${serverEndpoint}${url.slice(apiIndex)}`;
|
||||||
|
} else {
|
||||||
|
url = `${serverEndpoint}/api/adventures/filtered`;
|
||||||
|
}
|
||||||
|
|
||||||
// Replace or add the page number in the URL
|
// Replace or add the page number in the URL
|
||||||
if (url.includes('page=')) {
|
if (url.includes('page=')) {
|
||||||
|
@ -458,8 +466,6 @@ export const actions: Actions = {
|
||||||
url += `page=${page}`;
|
url += `page=${page}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('CHANGE PAGE' + url);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue