mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Generating SnapshotPostRequest data correctly.
This commit is contained in:
parent
20c48cbd92
commit
375916678d
8 changed files with 27 additions and 10 deletions
|
@ -20,6 +20,11 @@ public class SnapshotPushPostbackHandler extends AbstractHandler {
|
||||||
// response.setContentType("text/html;charset=utf-8");
|
// response.setContentType("text/html;charset=utf-8");
|
||||||
// response.setStatus(HttpServletResponse.SC_OK);
|
// response.setStatus(HttpServletResponse.SC_OK);
|
||||||
baseRequest.setHandled(false);
|
baseRequest.setHandled(false);
|
||||||
|
if (request.getMethod().equals("POST") && request.getPathInfo().endsWith("postback")) {
|
||||||
|
System.out.println(request.getHeaderNames());
|
||||||
|
}
|
||||||
|
|
||||||
|
// System.out.println(request.getRemoteAddr());
|
||||||
// System.out.println("method: " + request.getMethod());
|
// System.out.println("method: " + request.getMethod());
|
||||||
// System.out.println("pathInfo: " + request.getPathInfo());
|
// System.out.println("pathInfo: " + request.getPathInfo());
|
||||||
// System.out.println("contextPath: " + request.getContextPath());
|
// System.out.println("contextPath: " + request.getContextPath());
|
||||||
|
|
|
@ -10,6 +10,7 @@ public interface CandidateSnapshot {
|
||||||
|
|
||||||
public JsonElement getJsonRepresentation();
|
public JsonElement getJsonRepresentation();
|
||||||
public int getPreviousVersionID();
|
public int getPreviousVersionID();
|
||||||
|
public String getProjectURL();
|
||||||
public void approveWithVersionID(int versionID);
|
public void approveWithVersionID(int versionID);
|
||||||
public String getProjectName();
|
public String getProjectName();
|
||||||
public WLDirectoryNode getDirectoryNode();
|
public WLDirectoryNode getDirectoryNode();
|
||||||
|
|
|
@ -15,7 +15,7 @@ public interface WriteLatexDataSource {
|
||||||
/* Called by request thread. */
|
/* Called by request thread. */
|
||||||
public boolean repositoryExists(String projectName) throws FailedConnectionException;
|
public boolean repositoryExists(String projectName) throws FailedConnectionException;
|
||||||
public List<WritableRepositoryContents> getWritableRepositories(String projectName) throws FailedConnectionException, InvalidProjectException;
|
public List<WritableRepositoryContents> getWritableRepositories(String projectName) throws FailedConnectionException, InvalidProjectException;
|
||||||
public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents) throws SnapshotPostException, IOException, FailedConnectionException;
|
public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents, String remoteAddr) throws SnapshotPostException, IOException, FailedConnectionException;
|
||||||
public void expectPostback(String projectName);
|
public void expectPostback(String projectName);
|
||||||
|
|
||||||
/* Called by postback thread. */
|
/* Called by postback thread. */
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class WLReceivePackFactory implements ReceivePackFactory<HttpServletReque
|
||||||
@Override
|
@Override
|
||||||
public ReceivePack create(HttpServletRequest httpServletRequest, Repository repository) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
|
public ReceivePack create(HttpServletRequest httpServletRequest, Repository repository) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
|
||||||
ReceivePack receivePack = new ReceivePack(repository);
|
ReceivePack receivePack = new ReceivePack(repository);
|
||||||
receivePack.setPreReceiveHook(new WriteLatexPutHook(writeLatexDataSource));
|
receivePack.setPreReceiveHook(new WriteLatexPutHook(writeLatexDataSource, httpServletRequest.getRemoteAddr()));
|
||||||
return receivePack;
|
return receivePack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,11 @@ import java.util.Collection;
|
||||||
public class WriteLatexPutHook implements PreReceiveHook {
|
public class WriteLatexPutHook implements PreReceiveHook {
|
||||||
|
|
||||||
private final WriteLatexDataSource writeLatexDataSource;
|
private final WriteLatexDataSource writeLatexDataSource;
|
||||||
|
private final String remoteAddr;
|
||||||
|
|
||||||
public WriteLatexPutHook(WriteLatexDataSource writeLatexDataSource) {
|
public WriteLatexPutHook(WriteLatexDataSource writeLatexDataSource, String remoteAddr) {
|
||||||
this.writeLatexDataSource = writeLatexDataSource;
|
this.writeLatexDataSource = writeLatexDataSource;
|
||||||
|
this.remoteAddr = remoteAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,7 +57,8 @@ public class WriteLatexPutHook implements PreReceiveHook {
|
||||||
checkForcedPush(receiveCommand);
|
checkForcedPush(receiveCommand);
|
||||||
writeLatexDataSource.putDirectoryContentsToProjectWithName(repository.getWorkTree().getName(),
|
writeLatexDataSource.putDirectoryContentsToProjectWithName(repository.getWorkTree().getName(),
|
||||||
getPushedDirectoryContents(repository,
|
getPushedDirectoryContents(repository,
|
||||||
receiveCommand));
|
receiveCommand),
|
||||||
|
remoteAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForcedPush(ReceiveCommand receiveCommand) throws ForcedPushException {
|
private void checkForcedPush(ReceiveCommand receiveCommand) throws ForcedPushException {
|
||||||
|
|
|
@ -16,12 +16,14 @@ public class WLDirectoryNodeSnapshot implements CandidateSnapshot {
|
||||||
|
|
||||||
private final int previousVersionID;
|
private final int previousVersionID;
|
||||||
private final String projectName;
|
private final String projectName;
|
||||||
|
private final String projectURL;
|
||||||
private final WLDirectoryNode directoryNode;
|
private final WLDirectoryNode directoryNode;
|
||||||
private final CandidateSnapshotCallback callback;
|
private final CandidateSnapshotCallback callback;
|
||||||
|
|
||||||
public WLDirectoryNodeSnapshot(WLProject project, WLDirectoryNode directoryNode, CandidateSnapshotCallback callback) {
|
public WLDirectoryNodeSnapshot(WLProject project, WLDirectoryNode directoryNode, String remoteAddr, CandidateSnapshotCallback callback) {
|
||||||
previousVersionID = project.getLatestSnapshot().getVersionID();
|
previousVersionID = project.getLatestSnapshot().getVersionID();
|
||||||
projectName = project.getName();
|
projectName = project.getName();
|
||||||
|
projectURL = "http://" + remoteAddr + "/" + projectName;
|
||||||
this.directoryNode = directoryNode;
|
this.directoryNode = directoryNode;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
System.out.println(getJsonRepresentation());
|
System.out.println(getJsonRepresentation());
|
||||||
|
@ -32,7 +34,7 @@ public class WLDirectoryNodeSnapshot implements CandidateSnapshot {
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.addProperty("latestVerId", previousVersionID);
|
jsonObject.addProperty("latestVerId", previousVersionID);
|
||||||
jsonObject.add("files", getFilesAsJson());
|
jsonObject.add("files", getFilesAsJson());
|
||||||
jsonObject.addProperty("postbackUrl", "wsomewhere");
|
jsonObject.addProperty("postbackUrl", projectURL + "/postback");
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ public class WLDirectoryNodeSnapshot implements CandidateSnapshot {
|
||||||
JsonObject file = new JsonObject();
|
JsonObject file = new JsonObject();
|
||||||
file.addProperty("name", fileNode.getFilePath());
|
file.addProperty("name", fileNode.getFilePath());
|
||||||
if (fileNode.isChanged()) {
|
if (fileNode.isChanged()) {
|
||||||
file.addProperty("url", "url");
|
file.addProperty("url", projectURL + "/" + fileNode.getFilePath());
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +60,11 @@ public class WLDirectoryNodeSnapshot implements CandidateSnapshot {
|
||||||
return previousVersionID;
|
return previousVersionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProjectURL() {
|
||||||
|
return projectURL;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void approveWithVersionID(int versionID) {
|
public void approveWithVersionID(int versionID) {
|
||||||
callback.approveSnapshot(versionID, this);
|
callback.approveSnapshot(versionID, this);
|
||||||
|
|
|
@ -43,8 +43,8 @@ public class WriteLatexAPI implements WriteLatexDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents) throws SnapshotPostException, IOException, FailedConnectionException {
|
public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents, String remoteAddr) throws SnapshotPostException, IOException, FailedConnectionException {
|
||||||
CandidateSnapshot candidate = dataModel.createCandidateSnapshotFromProjectWithContents(projectName, directoryContents);
|
CandidateSnapshot candidate = dataModel.createCandidateSnapshotFromProjectWithContents(projectName, directoryContents, remoteAddr);
|
||||||
new SnapshotPushRequest(candidate);
|
new SnapshotPushRequest(candidate);
|
||||||
throw new SnapshotPostException() {
|
throw new SnapshotPostException() {
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,11 @@ public class WLDataModel implements CandidateSnapshotCallback {
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CandidateSnapshot createCandidateSnapshotFromProjectWithContents(String projectName, RawDirectoryContents directoryContents) throws SnapshotPostException, IOException, FailedConnectionException {
|
public CandidateSnapshot createCandidateSnapshotFromProjectWithContents(String projectName, RawDirectoryContents directoryContents, String remoteAddr) throws SnapshotPostException, IOException, FailedConnectionException {
|
||||||
return new WLDirectoryNodeSnapshot(getProjectWithName(projectName),
|
return new WLDirectoryNodeSnapshot(getProjectWithName(projectName),
|
||||||
fileStore.createNextDirectoryNodeInProjectFromContents(getProjectWithName(projectName),
|
fileStore.createNextDirectoryNodeInProjectFromContents(getProjectWithName(projectName),
|
||||||
directoryContents),
|
directoryContents),
|
||||||
|
remoteAddr,
|
||||||
this);
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue