wip: affiliation
This commit is contained in:
@@ -39,8 +39,47 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Uni<String> moveMedia(long idSrc, long idDest, String media, String dirSrc, String dirDst) {
|
||||
System.out.println("moveMedia: " + idSrc + " -> " + idDest + " " + media + " " + dirSrc + " " + dirDst);
|
||||
return Uni.createFrom().nullItem().map(__ -> {
|
||||
File dirFile = new File(media, dirSrc);
|
||||
if (!dirFile.exists())
|
||||
return "Not found";
|
||||
|
||||
File dirDestFile = new File(media, dirDst);
|
||||
if (!dirDestFile.exists())
|
||||
if (!dirDestFile.mkdirs())
|
||||
return "Fail to create directory " + dirDestFile;
|
||||
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(String.valueOf(idSrc));
|
||||
File[] files = dirFile.listFiles(filter);
|
||||
if (files == null || files.length == 0)
|
||||
return "Not found";
|
||||
|
||||
FilenameFilter filter2 = (directory, filename) -> filename.startsWith(String.valueOf(idDest));
|
||||
File[] files2 = dirDestFile.listFiles(filter2);
|
||||
if (files2 != null) {
|
||||
for (File file : files2) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
for (File file : files) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.renameTo(new File(dirDestFile,
|
||||
file.getName().replaceFirst(String.valueOf(idSrc), String.valueOf(idDest))));
|
||||
}
|
||||
|
||||
return "Ok";
|
||||
});
|
||||
}
|
||||
|
||||
public static Future<String> replacePhoto(long id, byte[] input, String media, String dir) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
if (input == null || input.length == 0)
|
||||
return "OK";
|
||||
|
||||
try (InputStream is = new BufferedInputStream(new ByteArrayInputStream(input))) {
|
||||
String mimeType;
|
||||
try {
|
||||
@@ -76,7 +115,12 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static Uni<Response> getMediaFile(long id, String media, String dirname,
|
||||
Uni<?> uniBase) throws URISyntaxException {
|
||||
Uni<?> uniBase) throws URISyntaxException {
|
||||
return getMediaFile(id, media, dirname, null, uniBase);
|
||||
}
|
||||
|
||||
public static Uni<Response> getMediaFile(long id, String media, String dirname, String out_filename,
|
||||
Uni<?> uniBase) throws URISyntaxException {
|
||||
Future<Pair<File, byte[]>> future = CompletableFuture.supplyAsync(() -> {
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(String.valueOf(id));
|
||||
File[] files = new File(media, dirname).listFiles(filter);
|
||||
@@ -104,8 +148,10 @@ public class Utils {
|
||||
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; ");
|
||||
resp.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"inline; " + ((out_filename == null) ? "" : "filename=\"" + out_filename + "\""));
|
||||
|
||||
System.out.println("getMediaFile: " + mimeType);
|
||||
return resp.build();
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user