package com.perforce.spark.view; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.servlet.http.HttpServletResponse; import spark.Request; import spark.Response; import com.perforce.p4java.server.IOptionsServer; import com.perforce.spark.ErrorModel; import com.perforce.spark.connection.ConnectionConfig; import com.perforce.spark.connection.ConnectionSession; import com.perforce.spark.depot.DepotFactory; import com.perforce.spark.depot.DepotModel; import com.perforce.spark.repository.RepoInterface; public class ViewControl extends ErrorModel { public static HttpServletResponse view(Request request, Response response) { // use the 'proxy' account to view or proxy files String user = ConnectionConfig.getProxyUser(); String ticket = ConnectionConfig.getProxyTicket(); request.session().attribute(ConnectionSession.USER, user); request.session().attribute(ConnectionSession.TICKET, ticket); // get raw file from Store or Proxy try { IOptionsServer p4 = ConnectionSession.get(request, response); String base = request.pathInfo(); DepotModel depot = DepotFactory.getByBase(p4, base); RepoInterface repo = depot.getRepo(); String path = toPath(request); HttpServletResponse raw = repo.fetch(p4, path, response); return raw; } catch (Exception e) { e.printStackTrace(); response.status(401); return response.raw(); } } /** * A relative Perforce not including the depot name. * * @param request * @return */ private static String toPath(Request request) { String base = request.pathInfo(); List<String> parts = new ArrayList<>(); parts.addAll(Arrays.asList(base.split("/"))); parts.remove(0); parts.remove(0); parts.remove(0); String path = String.join("/", parts); return path; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 15371 | Paul Allen | Query support for index. | ||
#7 | 15295 | Paul Allen | Remap 'orbit' -> 'jar' extension. | ||
#6 | 15233 | Paul Allen | Show repoID in search and return 404 (not 401) in view. | ||
#5 | 15221 | Paul Allen | Generate Gem index and submit after a deploy or proxy fetch event. | ||
#4 | 15094 | Paul Allen | Added support for Proxy and Group. | ||
#3 | 14863 | Paul Allen | Change File/Dir browse to support extended options | ||
#2 | 14228 | Paul Allen |
Moved View over to the new model. Retactor connection to package. |
||
#1 | 14226 | Paul Allen | Tidy up Browse elements over to micro MVC model |