|
|
@@ -3,6 +3,7 @@ const { fetchJson, fetchNothing } = require('@overleaf/fetch-utils')
|
|
|
const settings = require('@overleaf/settings')
|
|
|
const OError = require('@overleaf/o-error')
|
|
|
const UserGetter = require('../User/UserGetter')
|
|
|
+const { Project } = require('../../models/Project')
|
|
|
|
|
|
async function initializeProject(projectId) {
|
|
|
const body = await fetchJson(`${settings.apis.project_history.url}/project`, {
|
|
|
@@ -107,6 +108,34 @@ async function _deleteProjectInFullProjectHistory(historyId) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Warning: Don't use this method for large projects. It will eagerly load all
|
|
|
+ * the history data and apply all operations.
|
|
|
+ * @param {string} projectId
|
|
|
+ * @returns Promise<object>
|
|
|
+ */
|
|
|
+async function getCurrentContent(projectId) {
|
|
|
+ const project = await Project.findById(projectId).exec()
|
|
|
+ const historyId = project?.overleaf?.history?.id
|
|
|
+ if (!historyId) {
|
|
|
+ throw new OError('project does not have a history id', { projectId })
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return await fetchJson(
|
|
|
+ `${settings.apis.v1_history.url}/projects/${historyId}/latest/content`,
|
|
|
+ {
|
|
|
+ method: 'GET',
|
|
|
+ basicAuth: {
|
|
|
+ user: settings.apis.v1_history.user,
|
|
|
+ password: settings.apis.v1_history.pass,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ )
|
|
|
+ } catch (err) {
|
|
|
+ throw OError.tag(err, 'failed to load project history', { historyId })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
async function injectUserDetails(data) {
|
|
|
// data can be either:
|
|
|
// {
|
|
|
@@ -192,6 +221,7 @@ module.exports = {
|
|
|
deleteProject: callbackify(deleteProject),
|
|
|
deleteProjectHistory: callbackify(deleteProjectHistory),
|
|
|
injectUserDetails: callbackify(injectUserDetails),
|
|
|
+ getCurrentContent: callbackify(getCurrentContent),
|
|
|
promises: {
|
|
|
initializeProject,
|
|
|
flushProject,
|
|
|
@@ -199,5 +229,6 @@ module.exports = {
|
|
|
deleteProject,
|
|
|
injectUserDetails,
|
|
|
deleteProjectHistory,
|
|
|
+ getCurrentContent,
|
|
|
},
|
|
|
}
|