first commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
const API_BASE = 'https://api.meshkee.com/api/v1';
|
||||
export const SITE_DOMAIN = 'sanazgoodarzi.ir';
|
||||
export const CUSTOMER_URL = `https://customer.${SITE_DOMAIN}`;
|
||||
export const BUSINESS_URL = `https://business.${SITE_DOMAIN}`;
|
||||
|
||||
async function request(path, options = {}) {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}${path}`, {
|
||||
...options,
|
||||
headers: { Accept: 'application/json', ...options.headers },
|
||||
cache: options.cache ?? 'no-store',
|
||||
signal: options.signal ?? AbortSignal.timeout(8000),
|
||||
});
|
||||
if (!response.ok) return null;
|
||||
return await response.json();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function apiUrl(path) { return `${API_BASE}${path}`; }
|
||||
export async function getBranding() {
|
||||
return (await request(`/tenants/${SITE_DOMAIN}/website/favicon`, { cache: 'force-cache' })) ?? {};
|
||||
}
|
||||
export async function getBusinessInfo() {
|
||||
return (await request(`/tenants/${SITE_DOMAIN}/website/business-info`, { cache: 'force-cache' })) ?? {};
|
||||
}
|
||||
export async function getBlogs() {
|
||||
const data = await request(`/tenants/${SITE_DOMAIN}/blogs?page=1&pageSize=100`);
|
||||
return Array.isArray(data?.items) ? data.items : [];
|
||||
}
|
||||
export async function getBlog(slug) {
|
||||
const data = await request(`/tenants/${SITE_DOMAIN}/blogs/${encodeURIComponent(slug)}`);
|
||||
return data?.blog ?? null;
|
||||
}
|
||||
export async function getBlogById(id) {
|
||||
const data = await request(`/tenants/${SITE_DOMAIN}/blogs/by-id/${encodeURIComponent(id)}`);
|
||||
return data?.blog ?? null;
|
||||
}
|
||||
export async function getPortfolios() {
|
||||
const data = await request(`/tenants/${SITE_DOMAIN}/portfolios?page=1&pageSize=100`);
|
||||
return Array.isArray(data?.items) ? data.items : [];
|
||||
}
|
||||
export async function getPortfolio(slug) {
|
||||
const data = await request(`/tenants/${SITE_DOMAIN}/portfolios/${encodeURIComponent(slug)}`);
|
||||
return data?.portfolio ?? null;
|
||||
}
|
||||
export async function getPortfolioById(id) {
|
||||
const data = await request(`/tenants/${SITE_DOMAIN}/portfolios/by-id/${encodeURIComponent(id)}`);
|
||||
return data?.portfolio ?? null;
|
||||
}
|
||||
|
||||
export function titleOf(item, fallback = '') {
|
||||
return item?.titleFa || item?.title || item?.titleEn || fallback;
|
||||
}
|
||||
export function imageUrlOf(item) {
|
||||
return item?.titleImageUrl || item?.imageUrl || item?.coverImageUrl || item?.thumbnailUrl || '';
|
||||
}
|
||||
export function galleryOf(item) {
|
||||
const values = Array.isArray(item?.gallery) ? item.gallery : [];
|
||||
return values.map((entry, index) => ({
|
||||
id: entry?.id ?? index,
|
||||
url: typeof entry === 'string' ? entry : entry?.url || entry?.imageUrl || entry?.fileUrl,
|
||||
alt: typeof entry === 'string' ? titleOf(item) : entry?.alt || entry?.titleFa || titleOf(item),
|
||||
})).filter((entry) => entry.url);
|
||||
}
|
||||
|
||||
export function plainText(value = '') {
|
||||
return value.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
export function faSlug(value = '') {
|
||||
return plainText(value).normalize('NFKC').replace(/[^\p{L}\p{N}\s-]/gu, '').trim().replace(/[\s_-]+/g, '-').replace(/^-+|-+$/g, '') || 'بدون-عنوان';
|
||||
}
|
||||
Reference in New Issue
Block a user