refs #299,#36,#40,#37,#33 closed
This commit is contained in:
@@ -2,7 +2,6 @@ package workers;
|
||||
|
||||
import GUI.SOMGUI;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import model.SOMConfig;
|
||||
import model.SOMEvent;
|
||||
import model.SOMImage;
|
||||
@@ -143,14 +142,23 @@ public class FilesWorker {
|
||||
List<File> dirs = new ArrayList<File>();
|
||||
List<File> pics = new ArrayList<File>();
|
||||
|
||||
//relative ones
|
||||
// int directoriesUploaded = 0;
|
||||
// int picturesUploaded = 0;
|
||||
|
||||
// Check for internet connection
|
||||
if (internet()) {
|
||||
|
||||
// Count Files and Dirs
|
||||
|
||||
// DIRS
|
||||
String[] splits = SOMConfig.getEventPicDir().split("/");
|
||||
String currentdir = "";
|
||||
|
||||
for (String split : splits) {
|
||||
currentdir = currentdir + "/" + split;
|
||||
dirs.add(new File(currentdir));
|
||||
|
||||
System.out.println("DIR added:" + currentdir);
|
||||
}
|
||||
|
||||
// FILES
|
||||
for (int i = 0; i < images.size(); i++) {
|
||||
|
||||
// get the current file
|
||||
@@ -158,18 +166,9 @@ public class FilesWorker {
|
||||
|
||||
System.out.println(file);
|
||||
|
||||
// get dirs
|
||||
if (file.isDirectory()
|
||||
&& !file.toString().contains("prv")
|
||||
&& !file.toString().contains("tmb")
|
||||
&& !file.toString().contains("tmp")
|
||||
&& !file.toString().contains("fnl")) {
|
||||
dirs.add(file);
|
||||
|
||||
}
|
||||
// get pics
|
||||
else if (file.isFile()
|
||||
&& file.toPath().toString().contains("src")) {
|
||||
if (file.isFile()
|
||||
&& file.toString().contains("src")) {
|
||||
pics.add(file);
|
||||
}
|
||||
}
|
||||
@@ -177,31 +176,25 @@ public class FilesWorker {
|
||||
// REPORT TO CONSOLE
|
||||
System.out.println(dirs.size() + " Directories");
|
||||
System.out.println(pics.size() + " Pics");
|
||||
|
||||
int uploadeddirs = 0;
|
||||
int uploadedfiles = 0;
|
||||
|
||||
// GET THE UI
|
||||
SOMGUI.changetoupload();
|
||||
|
||||
|
||||
FXMLLoader fxmlLoader = new FXMLLoader();
|
||||
try {
|
||||
fxmlLoader.setLocation(
|
||||
FilesWorker.class.getClassLoader().getResource("fxml/upload.fxml")
|
||||
);
|
||||
|
||||
fxmlLoader.load();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
// UPLOAD DIRECTORIES
|
||||
List<File> limitdirs = new ArrayList<File>();
|
||||
// TODO Limit Uploads
|
||||
for (File dir : dirs
|
||||
) {
|
||||
|
||||
i++;
|
||||
for (File dir : dirs) {
|
||||
|
||||
System.out.println("Queueing Dir " + dir.toString());
|
||||
uploadeddirs++;
|
||||
|
||||
System.out.println("Queueing Directories " + dir.toString());
|
||||
limitdirs.add(dir);
|
||||
if (limitdirs.size() >= 3 || limitdirs.size() == i) {
|
||||
if (limitdirs.size() >= SOMConfig.PARALLEL_UPLOADS
|
||||
// Upload even if limit is not reached
|
||||
|| (dirs.size() - uploadeddirs) < SOMConfig.PARALLEL_UPLOADS) {
|
||||
|
||||
System.out.println("Launch Dir upload");
|
||||
uploadDir(limitdirs);
|
||||
@@ -210,23 +203,28 @@ public class FilesWorker {
|
||||
limitdirs.clear();
|
||||
}
|
||||
}
|
||||
// uploadDir(dirs);
|
||||
|
||||
// UPLOAD FILES
|
||||
List<File> limitpics = new ArrayList<File>();
|
||||
for (File pic : pics
|
||||
) {
|
||||
i++;
|
||||
System.out.println("Queueing Dir " + pic.toString());
|
||||
limitpics.add(pic);
|
||||
if (limitpics.size() >= 3 || limitdirs.size() == i) {
|
||||
|
||||
System.out.println("Launch Pic upload");
|
||||
uploadedfiles++;
|
||||
|
||||
System.out.println("Queueing File " + pic.toString());
|
||||
limitpics.add(pic);
|
||||
|
||||
if (limitpics.size() >= SOMConfig.PARALLEL_UPLOADS
|
||||
// Upload even if limit is not reached
|
||||
|| (pics.size() - uploadedfiles) < SOMConfig.PARALLEL_UPLOADS) {
|
||||
|
||||
System.out.println("Launch File upload");
|
||||
uploadFile(limitpics);
|
||||
|
||||
System.out.println("Clear Queue");
|
||||
System.out.println("Clear File Queue");
|
||||
limitpics.clear();
|
||||
}
|
||||
}
|
||||
// uploadFile(pics);
|
||||
|
||||
SOMGUI.changetopicture();
|
||||
}
|
||||
@@ -245,9 +243,16 @@ public class FilesWorker {
|
||||
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
|
||||
System.out.println("launch Upload Process: " + i);
|
||||
System.out.println("LAUNCH Upload Process: " + i);
|
||||
|
||||
final File file = files.get(i);
|
||||
final String target = "https://cloud.selfomat.de/remote.php/webdav/" + SOMConfig.getEventPicDir() + "/" + file.getName();
|
||||
|
||||
System.out.println(file.toString());
|
||||
System.out.println("----------->");
|
||||
System.out.println(target);
|
||||
System.out.println("");
|
||||
System.out.println("");
|
||||
|
||||
final int pictureCounter = i + 1;
|
||||
Task<Boolean> task = new Task<Boolean>() {
|
||||
@@ -257,20 +262,17 @@ public class FilesWorker {
|
||||
// build the upload process
|
||||
// TODO remove -k option (this option skips certificate verification)
|
||||
ProcessBuilder builder = new ProcessBuilder(
|
||||
"curl",
|
||||
"-T",
|
||||
"bash",
|
||||
"SELFOMAT/sh/upload.sh",
|
||||
file.toString(),
|
||||
"-u",
|
||||
"upload:geheim",
|
||||
"https://cloud.selfom.at/remote.php/webdav/" + file.toString().replace("/src", ""),
|
||||
"-k");
|
||||
target,
|
||||
SOMConfig.CLOUD_CREDENTIALS
|
||||
);
|
||||
|
||||
// make the process traceable
|
||||
builder.redirectErrorStream(true);
|
||||
|
||||
|
||||
Process process = builder.start();
|
||||
// launch upload process
|
||||
Process process = builder.start();
|
||||
|
||||
// wait for the process to end
|
||||
if (process.waitFor() == 0) {
|
||||
@@ -327,7 +329,8 @@ public class FilesWorker {
|
||||
"upload:geheim",
|
||||
"-X",
|
||||
"MKCOL",
|
||||
"https://cloud.selfom.at/remote.php/webdav/" + dir.toString().replace("/src", ""),
|
||||
"https://cloud.selfom.at/remote.php/webdav/" + SOMConfig.getEventPicDir(),
|
||||
// dir.toString().replace("/src", ""),
|
||||
"-k");
|
||||
|
||||
// make the process traceable
|
||||
|
||||
Reference in New Issue
Block a user