package org.breizhcamp.video.uploader.services;

import org.breizhcamp.video.uploader.dto.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * Handle directory and files operations
 */
@Service
public class FileSrv {

	@Value("${videos.dir:./videos}")
	private Path videosDir;

	@Autowired
	private EventSrv eventSrv;

	private DateTimeFormatter dayFormat = DateTimeFormatter.ofPattern("dd");
	private DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("HH-mm");

	public Path getVideosDir() {
		return videosDir.toAbsolutePath();
	}

	/**
	 * Create one directory for each event in videosDir.
	 */
	public void createDirs() throws IOException {
		Files.createDirectories(videosDir);
		List<Event> events = eventSrv.list();

		for (Event event : events) {
			Path dir = videosDir.resolve(buildDirName(event));
			if (!Files.exists(dir)) {
				Files.createDirectory(dir);
			}
		}
	}


	/**
	 * @return the directory name for a specific event
	 */
	private String buildDirName(Event event) {
		return dayFormat.format(event.getEventStart()) + "." + event.getVenue() + "." + timeFormat.format(event.getEventStart())
				+ " - " + event.getName() + " - " + event.getId();
	}
}

@@ -1269,24 +1269,93 @@
 nt event) %7B%0A
+%09%09String name = event.getName().replaceAll(%22%5B%5C%5C%5C%5C/:*?%5C%22%3C%3E%7C%5D%22, %22-%22);%0A%0A
 %09%09return day
@@ -1479,31 +1479,20 @@
 %22 - %22 + 
-event.getN
+n
 ame
-()
  + %22 - %22

Remove invalid directory char for sessions directories