This commit is contained in:
string 2025-06-09 10:18:59 +05:30
parent 5e70585afc
commit 03bf7b7658
4 changed files with 73 additions and 2 deletions

View File

@ -72,6 +72,8 @@ public class HtmlGeneratorController {
@PostMapping("/generate")
public ResponseEntity<?> generateHtml(@RequestBody Map<String, Object> jsonInput) {
try {
System.out.println(" generate html for json.." + jsonInput);
StringBuilder html = new StringBuilder();
for (Map.Entry<String, Object> entry : jsonInput.entrySet()) {

View File

@ -25,8 +25,25 @@ public class HtmlBuilder5 {
// Standard tag name (from 'element' key)
String tag = getString(node, "element", "div");
// Standard tag name (from 'element' key)
// CUSTOM: Render <img> using keywords and Unsplash image
if ("img".equals(tag) && node.containsKey("keywords")) {
String keywords = getString(node, "keywords", "");
String imageUrl = getImageFromKeyword(keywords);
html.append("<img");
// Set attributes like class, alt, etc.
appendAttribute(html, node, "class");
html.append(" src=\"").append(imageUrl).append("\"");
html.append(" />");
return html.toString(); // Done
}
// Start tag
html.append("<").append(tag);
// String clazz = getString(node, "class", "");
// if (!clazz.isEmpty()) {
// html.append(" class=\"").append(clazz).append("\"");
@ -215,4 +232,16 @@ public class HtmlBuilder5 {
return html.toString();
}
private static String getImageFromKeyword(String keywords) {
// Convert space-separated keywords to Unsplash format
String query = keywords.trim().replace(" ", ",");
// Return Unsplash proxy image URL (free to use)
// "https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=crop&w=800&q=80"
// return "https://source.unsplash.com/800x400/?" + query;
return "https://images.unsplash.com/" + query + "?auto=format&fit=crop&w=800&q=80";
}
}

View File

@ -3,7 +3,6 @@ package com.realnet.vpspack.Controllers;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -29,6 +28,13 @@ import com.realnet.fnd.response.EntityResponse;
import com.realnet.vpspack.Entity.SiteBuilder;
import com.realnet.vpspack.Entity.SiteBuilderDto;
import com.realnet.vpspack.Services.SiteBuilderService;
import org.eclipse.jgit.api.Git;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.apache.commons.io.FileUtils;
import java.io.File;
@RequestMapping(value = "/SiteTree")
@CrossOrigin("*")
@ -111,6 +117,35 @@ public class SiteBuilderController {
}
private static final String BASE_CLONE_PATH = "C:/cloned-repos"; // Change as needed
@PostMapping("/clone")
public ResponseEntity<String> cloneRepo(@RequestParam String gitUrl, @RequestParam String branch) {
try {
String repoName = gitUrl.substring(gitUrl.lastIndexOf("/") + 1).replace(".git", "");
File localPath = new File(BASE_CLONE_PATH + File.separator + repoName);
// Clean if already exists
if (localPath.exists()) {
FileUtils.deleteDirectory(localPath);
}
// Clone the specific branch
Git.cloneRepository()
.setURI(gitUrl)
.setBranch(branch)
.setDirectory(localPath)
.call();
return ResponseEntity.ok("Repository cloned successfully to: " + localPath.getAbsolutePath());
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("Failed to clone repository: " + e.getMessage());
}
}
// it created all file of pages
@PostMapping("/SiteTree/createFile")
public ResponseEntity<?> createHtmlFiles(@RequestParam Integer siteId, @RequestParam String siteBuilderName,
@ -124,6 +159,11 @@ public class SiteBuilderController {
String filepath = projectPath + File.separator + "Files" + File.separator + siteBuilderName;
if (filename.equalsIgnoreCase("home")) {
filename = "index";
}
ResponseEntity<?> file = fileHelper.readFile(filepath, filename);
return file;
}

View File

@ -162,7 +162,7 @@ public class SiteBuilderService {
if (get.getStatusCodeValue() < 209) {
System.out.println(" deplpoyed also...");
String deployedUrl = PortConstant.DOMAIN + "/" + serverPortNo;
String deployedUrl = PortConstant.DOMAIN + ":" + serverPortNo;
SiteBuilder siteBuilder = getdetailsbyId(siteId);
siteBuilder.setDeployedUrl(deployedUrl);