Commit a7e94f8d authored by Lê Bảo Hồng Đức's avatar Lê Bảo Hồng Đức

[tag]0.1-vcci

parent 7813ebcf
Pipeline #50719 passed with stages
in 2 minutes and 45 seconds
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
const FEATURED_MEMBER_API_URL = const FEATURED_MEMBER_API_URL =
"https://vccihcm.vn/api/v1.0/organizations?filters=users.status_id+%3D%3D+36ca1cc5-7b6e-4f9f-b973-69c5207deb62&pageSize=9&sortField=created_at&sortOrder=ASC"; "https://vccihcm.vn/api/v1.0/organizations?filters=users.status_id+%3D%3D+36ca1cc5-7b6e-4f9f-b973-69c5207deb62&pageSize=12&sortField=created_at&sortOrder=ASC";
export async function GET() { export async function GET() {
try { try {
......
const DEFAULT_BACKEND_ORIGIN = "https://news.vccihcm.vn"; const DEFAULT_BACKEND_ORIGIN = "https://news.vccihcm.vn";
const DEFAULT_FRONTEND_ORIGIN = "https://news.vccihcm.vn"; const DEFAULT_FRONTEND_ORIGIN = "https://news.vccihcm.vn";
const LEGACY_MEDIA_HOSTS = new Set([
"vietprodev.duckdns.org",
"vcci-hcm.org.vn",
"vccihcm.vn",
]);
const normalizeOrigin = (value?: string | null) => value?.trim().replace(/\/+$/, "") || ""; const normalizeOrigin = (value?: string | null) => value?.trim().replace(/\/+$/, "") || "";
const extractUploadPath = (pathname: string) => {
const markers = ["/api/uploads/", "/uploads/", "/wp-content/uploads/"];
for (const marker of markers) {
const index = pathname.indexOf(marker);
if (index >= 0) {
const cleanPath = pathname.slice(index).replace(/^\/api\/uploads\//, "/uploads/");
return cleanPath;
}
}
return null;
};
const readOrigin = (key: "NEXT_PUBLIC_BACKEND_HOST" | "NEXT_PUBLIC_FRONTEND_HOST") => { const readOrigin = (key: "NEXT_PUBLIC_BACKEND_HOST" | "NEXT_PUBLIC_FRONTEND_HOST") => {
const envOrigin = normalizeOrigin( const envOrigin = normalizeOrigin(
key === "NEXT_PUBLIC_BACKEND_HOST" key === "NEXT_PUBLIC_BACKEND_HOST"
...@@ -61,6 +80,22 @@ export const resolveUploadUrl = (value?: string | null) => { ...@@ -61,6 +80,22 @@ export const resolveUploadUrl = (value?: string | null) => {
return trimmed; return trimmed;
} }
if (/^https?:\/\//i.test(trimmed)) {
try {
const url = new URL(trimmed);
if (LEGACY_MEDIA_HOSTS.has(url.hostname)) {
const uploadPath = extractUploadPath(url.pathname);
if (uploadPath) {
return backendOrigin ? `${backendOrigin}${uploadPath}` : uploadPath;
}
}
} catch {
return trimmed;
}
return trimmed;
}
if (trimmed.startsWith("/")) { if (trimmed.startsWith("/")) {
if (trimmed.startsWith("/uploads/") || trimmed.startsWith("/api/uploads/")) { if (trimmed.startsWith("/uploads/") || trimmed.startsWith("/api/uploads/")) {
const cleanPath = trimmed.replace(/^\/+/, "").replace(/^api\/uploads\//, "uploads/"); const cleanPath = trimmed.replace(/^\/+/, "").replace(/^api\/uploads\//, "uploads/");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment