feat: pdf generation
This commit is contained in:
@@ -12,7 +12,6 @@ import net.sf.jmimemagic.MagicParseException;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
@@ -95,7 +94,7 @@ public class Utils {
|
||||
if (!dirFile.mkdirs())
|
||||
throw new IOException("Fail to create directory " + dir);
|
||||
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(id +".");
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(id + ".");
|
||||
File[] files = dirFile.listFiles(filter);
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
@@ -134,22 +133,45 @@ public class Utils {
|
||||
return null;
|
||||
});
|
||||
|
||||
URI uri = new URI("https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava2.webp");
|
||||
Future<byte[]> future2 = CompletableFuture.supplyAsync(() -> {
|
||||
try (InputStream st = Utils.class.getClassLoader().getResourceAsStream("asset/blank-profile-picture.png")) {
|
||||
if (st == null)
|
||||
return null;
|
||||
return st.readAllBytes();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
return uniBase.chain(__ -> Uni.createFrom().future(future)
|
||||
.map(filePair -> {
|
||||
if (filePair == null)
|
||||
return Response.temporaryRedirect(uri).build();
|
||||
.chain(filePair -> {
|
||||
if (filePair == null) {
|
||||
return Uni.createFrom().future(future2).map(data -> {
|
||||
if (data == null)
|
||||
return Response.noContent().build();
|
||||
|
||||
String mimeType = URLConnection.guessContentTypeFromName(filePair.getKey().getName());
|
||||
String mimeType = "image/apng";
|
||||
Response.ResponseBuilder resp = Response.ok(data);
|
||||
resp.type(MediaType.APPLICATION_OCTET_STREAM);
|
||||
resp.header(HttpHeaders.CONTENT_LENGTH, data.length);
|
||||
resp.header(HttpHeaders.CONTENT_TYPE, mimeType);
|
||||
resp.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"inline; " + ((out_filename == null) ? "" : "filename=\"" + out_filename + "\""));
|
||||
return resp.build();
|
||||
});
|
||||
} else {
|
||||
return Uni.createFrom().item(() -> {
|
||||
String mimeType = URLConnection.guessContentTypeFromName(filePair.getKey().getName());
|
||||
|
||||
Response.ResponseBuilder resp = Response.ok(filePair.getValue());
|
||||
resp.type(MediaType.APPLICATION_OCTET_STREAM);
|
||||
resp.header(HttpHeaders.CONTENT_LENGTH, filePair.getValue().length);
|
||||
resp.header(HttpHeaders.CONTENT_TYPE, mimeType);
|
||||
resp.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"inline; " + ((out_filename == null) ? "" : "filename=\"" + out_filename + "\""));
|
||||
return resp.build();
|
||||
Response.ResponseBuilder resp = Response.ok(filePair.getValue());
|
||||
resp.type(MediaType.APPLICATION_OCTET_STREAM);
|
||||
resp.header(HttpHeaders.CONTENT_LENGTH, filePair.getValue().length);
|
||||
resp.header(HttpHeaders.CONTENT_TYPE, mimeType);
|
||||
resp.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"inline; " + ((out_filename == null) ? "" : "filename=\"" + out_filename + "\""));
|
||||
return resp.build();
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user