parent
cddcc28b74
commit
a39479c0bd
@ -1,40 +1,18 @@
|
||||
package com.olexyn.ensync;
|
||||
|
||||
import com.olexyn.ensync.artifacts.DataRoot;
|
||||
import com.olexyn.ensync.artifacts.SyncBundle;
|
||||
import com.olexyn.ensync.lock.LockUtil;
|
||||
import com.olexyn.ensync.util.IgnoreUtil;
|
||||
import com.olexyn.min.log.LogU;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||
public class MainApp {
|
||||
|
||||
final public static Flow FLOW = new Flow();
|
||||
|
||||
final private static Tools TOOLS = new Tools();
|
||||
|
||||
public static void main(String[] args) throws JSONException {
|
||||
LogU.remake(null, "com.olexyn.ensync.", "[%1$tF %1$tT] [%2$-7s] [%3$-14s] %4$-180s [%5$s]\n");
|
||||
|
||||
var configPath = Path.of(System.getProperty("user.dir") + "/src/main/resources/config.json");
|
||||
String configString = Tools.fileToString(LockUtil.lockFile(configPath).getFc());
|
||||
JSONObject dataRoot = new JSONObject(configString).getJSONObject("dataRoot");
|
||||
for (String bundleKey : dataRoot.keySet()) {
|
||||
SyncBundle syncBundle = new SyncBundle(bundleKey);
|
||||
dataRoot.getJSONArray(bundleKey).toList()
|
||||
.forEach(
|
||||
directoryPath -> syncBundle.addDirectory(Path.of(directoryPath.toString()))
|
||||
);
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MainApp.class, args);
|
||||
}
|
||||
|
||||
DataRoot.get().put(bundleKey, syncBundle);
|
||||
}
|
||||
|
||||
var ignorePath = Path.of(System.getProperty("user.dir") + "/src/main/resources/syncignore");
|
||||
IgnoreUtil.IGNORE = Tools.fileToLines(LockUtil.lockFile(ignorePath).getFc());
|
||||
FLOW.start();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
package com.olexyn.ensync.web;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class Controller {
|
||||
|
||||
private final EnsyncService ensyncService;
|
||||
|
||||
|
||||
@Autowired
|
||||
public Controller(
|
||||
EnsyncService ensyncService
|
||||
){
|
||||
this.ensyncService = ensyncService;
|
||||
}
|
||||
|
||||
@PostMapping("/ensync")
|
||||
public ResponseEntity<String> triageUnsubscribable() {
|
||||
try {
|
||||
ensyncService.ensync();
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.olexyn.ensync.web;
|
||||
|
||||
import com.olexyn.ensync.Flow;
|
||||
import com.olexyn.ensync.Tools;
|
||||
import com.olexyn.ensync.artifacts.DataRoot;
|
||||
import com.olexyn.ensync.artifacts.SyncBundle;
|
||||
import com.olexyn.ensync.lock.LockUtil;
|
||||
import com.olexyn.ensync.util.IgnoreUtil;
|
||||
import com.olexyn.min.log.LogU;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Service
|
||||
public class EnsyncService {
|
||||
|
||||
final public static Flow FLOW = new Flow();
|
||||
|
||||
public void ensync() throws JSONException {
|
||||
LogU.remake(null, "com.olexyn.ensync.", "[%1$tF %1$tT] [%2$-7s] [%3$-14s] %4$-180s [%5$s]\n");
|
||||
|
||||
var configPath = Path.of(System.getProperty("user.dir") + "/src/main/resources/config.json");
|
||||
String configString = Tools.fileToString(LockUtil.lockFile(configPath).getFc());
|
||||
JSONObject dataRoot = new JSONObject(configString).getJSONObject("dataRoot");
|
||||
for (String bundleKey : dataRoot.keySet()) {
|
||||
SyncBundle syncBundle = new SyncBundle(bundleKey);
|
||||
dataRoot.getJSONArray(bundleKey).toList()
|
||||
.forEach(
|
||||
directoryPath -> syncBundle.addDirectory(Path.of(directoryPath.toString()))
|
||||
);
|
||||
|
||||
DataRoot.get().put(bundleKey, syncBundle);
|
||||
}
|
||||
|
||||
var ignorePath = Path.of(System.getProperty("user.dir") + "/src/main/resources/syncignore");
|
||||
IgnoreUtil.IGNORE = Tools.fileToLines(LockUtil.lockFile(ignorePath).getFc());
|
||||
FLOW.start();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue