mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #24776 from overleaf/em-project-history-unused-endpoints
Remove unused endpoints in project-history GitOrigin-RevId: 2940c1c1973177e3200cb78884b307f708fd88c3
This commit is contained in:
@@ -238,22 +238,6 @@ export function getFileMetadataSnapshot(req, res, next) {
|
||||
)
|
||||
}
|
||||
|
||||
export function getMostRecentChunk(req, res, next) {
|
||||
const { project_id: projectId } = req.params
|
||||
WebApiManager.getHistoryId(projectId, (error, historyId) => {
|
||||
if (error) return next(OError.tag(error))
|
||||
|
||||
HistoryStoreManager.getMostRecentChunk(
|
||||
projectId,
|
||||
historyId,
|
||||
(err, data) => {
|
||||
if (err) return next(OError.tag(err))
|
||||
res.json(data)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export function getLatestSnapshot(req, res, next) {
|
||||
const { project_id: projectId } = req.params
|
||||
WebApiManager.getHistoryId(projectId, (error, historyId) => {
|
||||
@@ -272,25 +256,6 @@ export function getLatestSnapshot(req, res, next) {
|
||||
})
|
||||
}
|
||||
|
||||
export function getChangesSince(req, res, next) {
|
||||
const { project_id: projectId } = req.params
|
||||
const { since } = req.query
|
||||
WebApiManager.getHistoryId(projectId, (error, historyId) => {
|
||||
if (error) return next(OError.tag(error))
|
||||
SnapshotManager.getChangesSince(
|
||||
projectId,
|
||||
historyId,
|
||||
since,
|
||||
(error, changes) => {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
res.json(changes.map(c => c.toRaw()))
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export function getChangesInChunkSince(req, res, next) {
|
||||
const { project_id: projectId } = req.params
|
||||
const { since } = req.query
|
||||
|
||||
@@ -22,10 +22,6 @@ export function initialize(app) {
|
||||
app.delete('/project/:project_id', HttpController.deleteProject)
|
||||
|
||||
app.get('/project/:project_id/snapshot', HttpController.getLatestSnapshot)
|
||||
app.get(
|
||||
'/project/:project_id/latest/history',
|
||||
HttpController.getMostRecentChunk
|
||||
)
|
||||
|
||||
app.get(
|
||||
'/project/:project_id/diff',
|
||||
@@ -61,16 +57,6 @@ export function initialize(app) {
|
||||
HttpController.getUpdates
|
||||
)
|
||||
|
||||
app.get(
|
||||
'/project/:project_id/changes',
|
||||
validate({
|
||||
query: {
|
||||
since: Joi.number().integer().min(0),
|
||||
},
|
||||
}),
|
||||
HttpController.getChangesSince
|
||||
)
|
||||
|
||||
app.get(
|
||||
'/project/:project_id/changes-in-chunk',
|
||||
validate({
|
||||
|
||||
@@ -341,44 +341,6 @@ function getLatestSnapshotFromChunk(data) {
|
||||
}
|
||||
}
|
||||
|
||||
async function getChangesSince(projectId, historyId, sinceVersion) {
|
||||
const allChanges = []
|
||||
let nextVersion
|
||||
while (true) {
|
||||
let data
|
||||
if (nextVersion) {
|
||||
data = await HistoryStoreManager.promises.getChunkAtVersion(
|
||||
projectId,
|
||||
historyId,
|
||||
nextVersion
|
||||
)
|
||||
} else {
|
||||
data = await HistoryStoreManager.promises.getMostRecentChunk(
|
||||
projectId,
|
||||
historyId
|
||||
)
|
||||
}
|
||||
if (data == null || data.chunk == null) {
|
||||
throw new OError('undefined chunk')
|
||||
}
|
||||
const chunk = Core.Chunk.fromRaw(data.chunk)
|
||||
if (sinceVersion > chunk.getEndVersion()) {
|
||||
throw new OError('requested version past the end')
|
||||
}
|
||||
const changes = chunk.getChanges()
|
||||
if (chunk.getStartVersion() > sinceVersion) {
|
||||
allChanges.unshift(...changes)
|
||||
nextVersion = chunk.getStartVersion()
|
||||
} else {
|
||||
allChanges.unshift(
|
||||
...changes.slice(sinceVersion - chunk.getStartVersion())
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
return allChanges
|
||||
}
|
||||
|
||||
async function getChangesInChunkSince(projectId, historyId, sinceVersion) {
|
||||
const latestChunk = Core.Chunk.fromRaw(
|
||||
(
|
||||
@@ -426,7 +388,6 @@ async function _loadFilesLimit(snapshot, kind, blobStore) {
|
||||
|
||||
// EXPORTS
|
||||
|
||||
const getChangesSinceCb = callbackify(getChangesSince)
|
||||
const getChangesInChunkSinceCb = callbackify(getChangesInChunkSince)
|
||||
const getFileSnapshotStreamCb = callbackify(getFileSnapshotStream)
|
||||
const getProjectSnapshotCb = callbackify(getProjectSnapshot)
|
||||
@@ -441,7 +402,6 @@ const getPathsAtVersionCb = callbackify(getPathsAtVersion)
|
||||
|
||||
export {
|
||||
getLatestSnapshotFromChunk,
|
||||
getChangesSinceCb as getChangesSince,
|
||||
getChangesInChunkSinceCb as getChangesInChunkSince,
|
||||
getFileSnapshotStreamCb as getFileSnapshotStream,
|
||||
getProjectSnapshotCb as getProjectSnapshot,
|
||||
@@ -454,7 +414,6 @@ export {
|
||||
}
|
||||
|
||||
export const promises = {
|
||||
getChangesSince,
|
||||
getChangesInChunkSince,
|
||||
getFileSnapshotStream,
|
||||
getProjectSnapshot,
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
import { expect } from 'chai'
|
||||
import mongodb from 'mongodb-legacy'
|
||||
import nock from 'nock'
|
||||
import Core from 'overleaf-editor-core'
|
||||
import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
|
||||
import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
|
||||
import latestChunk from '../fixtures/chunks/7-8.json' with { type: 'json' }
|
||||
import previousChunk from '../fixtures/chunks/4-6.json' with { type: 'json' }
|
||||
import firstChunk from '../fixtures/chunks/0-3.json' with { type: 'json' }
|
||||
const { ObjectId } = mongodb
|
||||
|
||||
const MockHistoryStore = () => nock('http://127.0.0.1:3100')
|
||||
const MockWeb = () => nock('http://127.0.0.1:3000')
|
||||
|
||||
const fixture = path => new URL(`../fixtures/${path}`, import.meta.url)
|
||||
|
||||
describe('GetChangesSince', function () {
|
||||
let projectId, historyId
|
||||
beforeEach(function (done) {
|
||||
projectId = new ObjectId().toString()
|
||||
historyId = new ObjectId().toString()
|
||||
ProjectHistoryApp.ensureRunning(error => {
|
||||
if (error) throw error
|
||||
|
||||
MockHistoryStore().post('/api/projects').reply(200, {
|
||||
projectId: historyId,
|
||||
})
|
||||
|
||||
ProjectHistoryClient.initializeProject(historyId, (error, olProject) => {
|
||||
if (error) throw error
|
||||
MockWeb()
|
||||
.get(`/project/${projectId}/details`)
|
||||
.reply(200, {
|
||||
name: 'Test Project',
|
||||
overleaf: { history: { id: olProject.id } },
|
||||
})
|
||||
|
||||
MockHistoryStore()
|
||||
.get(`/api/projects/${historyId}/latest/history`)
|
||||
.replyWithFile(200, fixture('chunks/7-8.json'))
|
||||
MockHistoryStore()
|
||||
.get(`/api/projects/${historyId}/versions/6/history`)
|
||||
.replyWithFile(200, fixture('chunks/4-6.json'))
|
||||
MockHistoryStore()
|
||||
.get(`/api/projects/${historyId}/versions/3/history`)
|
||||
.replyWithFile(200, fixture('chunks/0-3.json'))
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
nock.cleanAll()
|
||||
})
|
||||
|
||||
function expectChangesSince(version, changes, done) {
|
||||
ProjectHistoryClient.getChangesSince(
|
||||
projectId,
|
||||
version,
|
||||
{},
|
||||
(error, got) => {
|
||||
if (error) throw error
|
||||
expect(got.map(c => Core.Change.fromRaw(c))).to.deep.equal(
|
||||
changes.map(c => Core.Change.fromRaw(c))
|
||||
)
|
||||
done()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
it('should return zero changes since the latest version', function (done) {
|
||||
expectChangesSince(8, [], done)
|
||||
})
|
||||
|
||||
it('should return one change when behind one version', function (done) {
|
||||
expectChangesSince(7, [latestChunk.chunk.history.changes[1]], done)
|
||||
})
|
||||
|
||||
it('should return changes when at the chunk boundary', function (done) {
|
||||
expect(latestChunk.chunk.startVersion).to.equal(6)
|
||||
expectChangesSince(6, latestChunk.chunk.history.changes, done)
|
||||
})
|
||||
|
||||
it('should return changes spanning multiple chunks', function (done) {
|
||||
expectChangesSince(
|
||||
1,
|
||||
[
|
||||
...firstChunk.chunk.history.changes.slice(1),
|
||||
...previousChunk.chunk.history.changes,
|
||||
...latestChunk.chunk.history.changes,
|
||||
],
|
||||
done
|
||||
)
|
||||
})
|
||||
|
||||
it('should return all changes when going back to the beginning', function (done) {
|
||||
expectChangesSince(
|
||||
0,
|
||||
[
|
||||
...firstChunk.chunk.history.changes,
|
||||
...previousChunk.chunk.history.changes,
|
||||
...latestChunk.chunk.history.changes,
|
||||
],
|
||||
done
|
||||
)
|
||||
})
|
||||
|
||||
it('should return an error when past the end version', function (done) {
|
||||
ProjectHistoryClient.getChangesSince(
|
||||
projectId,
|
||||
9,
|
||||
{ allowErrors: true },
|
||||
(error, body, statusCode) => {
|
||||
if (error) throw error
|
||||
expect(statusCode).to.equal(500)
|
||||
expect(body).to.deep.equal({ message: 'an internal error occurred' })
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -108,25 +108,6 @@ export function getFileTreeDiff(projectId, from, to, callback) {
|
||||
)
|
||||
}
|
||||
|
||||
export function getChangesSince(projectId, since, options, callback) {
|
||||
request.get(
|
||||
{
|
||||
url: `http://127.0.0.1:3054/project/${projectId}/changes`,
|
||||
qs: {
|
||||
since,
|
||||
},
|
||||
json: true,
|
||||
},
|
||||
(error, res, body) => {
|
||||
if (error) return callback(error)
|
||||
if (!options.allowErrors) {
|
||||
expect(res.statusCode).to.equal(200)
|
||||
}
|
||||
callback(null, body, res.statusCode)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export function getChangesInChunkSince(projectId, since, options, callback) {
|
||||
request.get(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user