mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 19:43:44 -05:00
ee85d948e2
GitOrigin-RevId: ef2ef77e26df59d1af3df6dc664e284d3c70102d
76 lines
1.9 KiB
JavaScript
Executable file
76 lines
1.9 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
|
|
/**
|
|
* This script takes a dump file, obtained via the /project/:project_id/dump
|
|
* endpoint and feeds it to the update translator to how updates are transfomed
|
|
* into changes sent to v1 history.
|
|
*/
|
|
import fs from 'fs'
|
|
import * as UpdateTranslator from '../app/js/UpdateTranslator.js'
|
|
import * as SyncManager from '../app/js/SyncManager.js'
|
|
import * as HistoryStoreManager from '../app/js/HistoryStoreManager.js'
|
|
|
|
const { filename } = parseArgs()
|
|
const { projectId, updates, chunk } = parseDumpFile(filename)
|
|
|
|
function expandResyncProjectStructure(chunk, update) {
|
|
HistoryStoreManager._mocks.getMostRecentChunk = function (
|
|
projectId,
|
|
projectHistoryId,
|
|
callback
|
|
) {
|
|
callback(null, chunk)
|
|
}
|
|
|
|
SyncManager.expandSyncUpdates(
|
|
projectId,
|
|
99999, // dummy history id
|
|
[update],
|
|
cb => cb(), // extend lock
|
|
(err, result) => {
|
|
console.log('err', err, 'result', JSON.stringify(result, null, 2))
|
|
process.exit()
|
|
}
|
|
)
|
|
}
|
|
|
|
function expandUpdates(updates) {
|
|
const wrappedUpdates = updates.map(update => ({ update }))
|
|
UpdateTranslator.convertToChanges(
|
|
projectId,
|
|
wrappedUpdates,
|
|
(err, changes) => {
|
|
if (err != null) {
|
|
error(err)
|
|
}
|
|
console.log(JSON.stringify(changes, null, 2))
|
|
}
|
|
)
|
|
}
|
|
|
|
if (updates[0].resyncProjectStructure) {
|
|
expandResyncProjectStructure(chunk, updates[0])
|
|
} else {
|
|
expandUpdates(updates)
|
|
}
|
|
|
|
function parseArgs() {
|
|
const args = process.argv.slice(2)
|
|
if (args.length !== 1) {
|
|
console.log('Usage: debug_translate_updates.js DUMP_FILE')
|
|
process.exit(1)
|
|
}
|
|
const filename = args[0]
|
|
return { filename }
|
|
}
|
|
|
|
function parseDumpFile(filename) {
|
|
const json = fs.readFileSync(filename)
|
|
const { project_id: projectId, updates, chunk } = JSON.parse(json)
|
|
return { projectId, updates, chunk }
|
|
}
|
|
|
|
function error(err) {
|
|
console.error(err)
|
|
process.exit(1)
|
|
}
|