package com.perforce.spark; import java.io.File; import java.util.Date; import java.util.List; import java.util.Map; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import spark.Request; import spark.Response; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.server.IOptionsServer; public class AssetHelper { public static void upload(Request request, Response response) throws Exception { // Create local tmp directory Date date = new Date(); String epoch = Long.toString(date.getTime()); File tmp = new File("upload", epoch); if (!tmp.exists() && !tmp.mkdirs()) { throw new RuntimeException("Failed to create directory " + tmp.getAbsolutePath()); } DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setRepository(tmp); ServletFileUpload up = new ServletFileUpload(factory); List<FileItem> items = up.parseRequest(request.raw()); for (FileItem item : items) { String fileName = item.getName(); item.write(new File(tmp, fileName)); } response.redirect("/deploy/pending/" + tmp); } public static Map<String, Object> submit(Request request, Response response) { IOptionsServer p4; Map<String, Object> attributes; attributes = NavBar.attributes("browse", request); // get p4 session try { p4 = ConnectionSession.get(request, response); } catch (P4JavaException e) { response.redirect("/"); String msg = e.getMessage(); msg = (msg == null) ? "Unknown Connection Error" : msg; attributes.put("error_show", "inherit"); attributes.put("error_message", msg); return attributes; } return attributes; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#12 | 14726 | Paul Allen | Limit deploy control path, and remove AssetHelper | ||
#11 | 14725 | Paul Allen | Generic deploy/upload | ||
#10 | 14723 | Paul Allen | Tidy up deploy/upload | ||
#9 | 14228 | Paul Allen |
Moved View over to the new model. Retactor connection to package. |
||
#8 | 14181 | Paul Allen | Lots of updates and refactoring. | ||
#7 | 14013 | Paul Allen | Basic proxy | ||
#6 | 13969 | Paul Allen | Depot list/create for Assets | ||
#5 | 13863 | Paul Allen | Minor fix to session vs cookie for login check. | ||
#4 | 13862 | Paul Allen | Submit uploads to Perforce | ||
#3 | 13857 | Paul Allen | Post Multipart form: fields and files. | ||
#2 | 13836 | Paul Allen | Use Dropzone for drag and drop. | ||
#1 | 13798 | Paul Allen | Basic file upload and login/logout cookie tidyup |