Initial Commot
This commit is contained in:
100
SETUP.md
Normal file
100
SETUP.md
Normal file
@@ -0,0 +1,100 @@
|
||||
# Spring Boot Banner Generator — Setup & Usage
|
||||
|
||||
## Running the App
|
||||
|
||||
```bash
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
The app starts on `http://localhost:8080`.
|
||||
|
||||
---
|
||||
|
||||
## Web UI
|
||||
|
||||
Open your browser and go to:
|
||||
|
||||
```
|
||||
http://localhost:8080/banner
|
||||
```
|
||||
|
||||
Upload an image, choose light or dark mode, and the colored HTML banner is rendered in the page.
|
||||
|
||||
---
|
||||
|
||||
## REST API
|
||||
|
||||
### Generate a Banner
|
||||
|
||||
**Endpoint:** `POST /api/banner`
|
||||
**Content-Type:** `multipart/form-data`
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|---------|---------|----------|------------------------------------|
|
||||
| `image` | file | yes | Image to convert (PNG, JPG, etc.) |
|
||||
| `dark` | boolean | no | Use dark color scheme (default: false) |
|
||||
|
||||
**Curl example:**
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/banner \
|
||||
-F "image=@./logo.png" \
|
||||
-F "dark=false"
|
||||
```
|
||||
|
||||
**Response (JSON):**
|
||||
|
||||
```json
|
||||
{
|
||||
"ansi": "${AnsiColor.RED}@@@@...",
|
||||
"html": "<span style='color:#ff0000'>@</span>..."
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Which Output to Use
|
||||
|
||||
### `ansi` — Colored terminal banner for Spring Boot apps
|
||||
|
||||
The `ansi` field contains Spring Boot's `${AnsiColor.X}` syntax. Paste it into `src/main/resources/banner.txt` in **any Spring Boot project** and it will print in color when the app starts.
|
||||
|
||||
**Extract and save directly:**
|
||||
|
||||
```bash
|
||||
curl -s -X POST http://localhost:8080/api/banner \
|
||||
-F "image=@./logo.png" \
|
||||
-F "dark=false" \
|
||||
| python -c "import sys,json; print(json.load(sys.stdin)['ansi'])" \
|
||||
> /path/to/your-spring-app/src/main/resources/banner.txt
|
||||
```
|
||||
|
||||
Then start your Spring Boot app — the banner prints in color in the terminal.
|
||||
|
||||
### `html` — Colored banner for web pages
|
||||
|
||||
The `html` field contains inline `<span style='color:#rrggbb'>` tags. Drop it inside a `<pre>` tag in any HTML page:
|
||||
|
||||
```html
|
||||
<pre style="font-family: monospace; background: #000;">
|
||||
<!-- paste html field value here -->
|
||||
</pre>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Swagger UI
|
||||
|
||||
Interactive API docs are available at:
|
||||
|
||||
```
|
||||
http://localhost:8080/swagger-ui.html
|
||||
```
|
||||
|
||||
Use it to explore and test the `/api/banner` endpoint directly from the browser — upload a file, toggle dark mode, and see the live JSON response.
|
||||
|
||||
The raw OpenAPI spec (JSON) is at:
|
||||
|
||||
```
|
||||
http://localhost:8080/v2/api-docs
|
||||
```
|
||||
27
pom.xml
27
pom.xml
@@ -22,6 +22,7 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<lombok.version>1.18.30</lombok.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -37,6 +38,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.30</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -58,6 +60,21 @@
|
||||
<version>1.0.0.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>20.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -77,6 +94,16 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<jvmArguments>--add-opens=java.base/java.lang=ALL-UNNAMED</jvmArguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<argLine>--add-opens=java.base/java.lang=ALL-UNNAMED</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package be.ordina.cloudfoundry.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public Docket api() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("be.ordina.cloudfoundry.controller"))
|
||||
.paths(PathSelectors.ant("/api/**"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package be.ordina.cloudfoundry.controller;
|
||||
|
||||
import be.ordina.cloudfoundry.banner.Banner;
|
||||
import be.ordina.cloudfoundry.banner.BannerGenerator;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/banner")
|
||||
@Api(value = "Banner Generator", description = "Generate Spring Boot ASCII banners from images")
|
||||
public class BannerRestController {
|
||||
|
||||
@Autowired
|
||||
private BannerGenerator bannerGenerator;
|
||||
|
||||
@ApiOperation(value = "Generate a banner from an image", response = Map.class)
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Map<String, String>> generateBanner(
|
||||
@ApiParam(value = "Image file to convert to ASCII banner", required = true)
|
||||
@RequestParam("image") MultipartFile image,
|
||||
@ApiParam(value = "Use dark color scheme", defaultValue = "false")
|
||||
@RequestParam(value = "dark", defaultValue = "false") boolean dark) {
|
||||
|
||||
log.info("REST request for image [{}]", image.getOriginalFilename());
|
||||
Banner banner = bannerGenerator.generateBanner(image, dark);
|
||||
|
||||
Map<String, String> response = new LinkedHashMap<>();
|
||||
response.put("ansi", banner.getAnsi());
|
||||
response.put("html", banner.getHtml());
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user