Initial commit - modstagram-next

This commit is contained in:
root
2026-07-05 13:59:41 +03:30
commit 11e73da693
859 changed files with 117640 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { BASE_URL } from "@/components/main/BaseUrl";
export async function fetchBillboards(
page: number,
limit: number,
filters: {
province?: string;
city?: string;
category?: string;
sort?: string;
search?: string;
},
token: string
) {
const validFilters = Object.entries(filters || {})
.filter(([_, value]) => value !== undefined && value !== "")
.reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {} as Record<string, string>);
const queryParams = new URLSearchParams({
page: page.toString(),
limit: limit.toString(),
...validFilters,
timestamp: Date.now().toString(), // اضافه کردن timestamp برای جلوگیری از کش
}).toString();
const apiUrl = `${BASE_URL}/advertising/web?${queryParams}`;
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 90_000);
let response: Response;
try {
response = await fetch(apiUrl, {
cache: "no-store",
signal: controller.signal,
headers: {
Authorization: token ? `Bearer ${token}` : "",
},
});
} finally {
clearTimeout(timeoutId);
}
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
}