mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 16:03:37 -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.setStatus(HttpServletResponse.SC_OK);
|
||||
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("pathInfo: " + request.getPathInfo());
|
||||
// System.out.println("contextPath: " + request.getContextPath());
|
||||
|
|
|
@ -10,6 +10,7 @@ public interface CandidateSnapshot {
|
|||
|
||||
public JsonElement getJsonRepresentation();
|
||||
public int getPreviousVersionID();
|
||||
public String getProjectURL();
|
||||
public void approveWithVersionID(int versionID);
|
||||
public String getProjectName();
|
||||
public WLDirectoryNode getDirectoryNode();
|
||||
|
|
|
@ -15,7 +15,7 @@ public interface WriteLatexDataSource {
|
|||
/* Called by request thread. */
|
||||
public boolean repositoryExists(String projectName) throws FailedConnectionException;
|
||||
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);
|
||||
|
||||
/* Called by postback thread. */
|
||||
|
|
|
@ -25,7 +25,7 @@ public class WLReceivePackFactory implements ReceivePackFactory<HttpServletReque
|
|||
@Override
|
||||
public ReceivePack create(HttpServletRequest httpServletRequest, Repository repository) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
|
||||
ReceivePack receivePack = new ReceivePack(repository);
|
||||
receivePack.setPreReceiveHook(new WriteLatexPutHook(writeLatexDataSource));
|
||||
receivePack.setPreReceiveHook(new WriteLatexPutHook(writeLatexDataSource, httpServletRequest.getRemoteAddr()));
|
||||
return receivePack;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,9 +22,11 @@ import java.util.Collection;
|
|||
public class WriteLatexPutHook implements PreReceiveHook {
|
||||
|
||||
private final WriteLatexDataSource writeLatexDataSource;
|
||||
private final String remoteAddr;
|
||||
|
||||
public WriteLatexPutHook(WriteLatexDataSource writeLatexDataSource) {
|
||||
public WriteLatexPutHook(WriteLatexDataSource writeLatexDataSource, String remoteAddr) {
|
||||
this.writeLatexDataSource = writeLatexDataSource;
|
||||
this.remoteAddr = remoteAddr;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,7 +57,8 @@ public class WriteLatexPutHook implements PreReceiveHook {
|
|||
checkForcedPush(receiveCommand);
|
||||
writeLatexDataSource.putDirectoryContentsToProjectWithName(repository.getWorkTree().getName(),
|
||||
getPushedDirectoryContents(repository,
|
||||
receiveCommand));
|
||||
receiveCommand),
|
||||
remoteAddr);
|
||||
}
|
||||
|
||||
private void checkForcedPush(ReceiveCommand receiveCommand) throws ForcedPushException {
|
||||
|
|
|
@ -16,12 +16,14 @@ public class WLDirectoryNodeSnapshot implements CandidateSnapshot {
|
|||
|
||||
private final int previousVersionID;
|
||||
private final String projectName;
|
||||
private final String projectURL;
|
||||
private final WLDirectoryNode directoryNode;
|
||||
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();
|
||||
projectName = project.getName();
|
||||
projectURL = "http://" + remoteAddr + "/" + projectName;
|
||||
this.directoryNode = directoryNode;
|
||||
this.callback = callback;
|
||||
System.out.println(getJsonRepresentation());
|
||||
|
@ -32,7 +34,7 @@ public class WLDirectoryNodeSnapshot implements CandidateSnapshot {
|
|||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("latestVerId", previousVersionID);
|
||||
jsonObject.add("files", getFilesAsJson());
|
||||
jsonObject.addProperty("postbackUrl", "wsomewhere");
|
||||
jsonObject.addProperty("postbackUrl", projectURL + "/postback");
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
@ -48,7 +50,7 @@ public class WLDirectoryNodeSnapshot implements CandidateSnapshot {
|
|||
JsonObject file = new JsonObject();
|
||||
file.addProperty("name", fileNode.getFilePath());
|
||||
if (fileNode.isChanged()) {
|
||||
file.addProperty("url", "url");
|
||||
file.addProperty("url", projectURL + "/" + fileNode.getFilePath());
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
@ -58,6 +60,11 @@ public class WLDirectoryNodeSnapshot implements CandidateSnapshot {
|
|||
return previousVersionID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProjectURL() {
|
||||
return projectURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void approveWithVersionID(int versionID) {
|
||||
callback.approveSnapshot(versionID, this);
|
||||
|
|
|
@ -43,8 +43,8 @@ public class WriteLatexAPI implements WriteLatexDataSource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents) throws SnapshotPostException, IOException, FailedConnectionException {
|
||||
CandidateSnapshot candidate = dataModel.createCandidateSnapshotFromProjectWithContents(projectName, directoryContents);
|
||||
public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents, String remoteAddr) throws SnapshotPostException, IOException, FailedConnectionException {
|
||||
CandidateSnapshot candidate = dataModel.createCandidateSnapshotFromProjectWithContents(projectName, directoryContents, remoteAddr);
|
||||
new SnapshotPushRequest(candidate);
|
||||
throw new SnapshotPostException() {
|
||||
|
||||
|
|
|
@ -43,10 +43,11 @@ public class WLDataModel implements CandidateSnapshotCallback {
|
|||
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),
|
||||
fileStore.createNextDirectoryNodeInProjectFromContents(getProjectWithName(projectName),
|
||||
directoryContents),
|
||||
remoteAddr,
|
||||
this);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue