mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Merge pull request #22512 from overleaf/bg-fixed-linked-files
use history-v1 for fetching linked files GitOrigin-RevId: 32c4a35ea8c1f745e0242237c57285b3edbbb984
This commit is contained in:
@@ -154,6 +154,34 @@ const FileStoreHandler = {
|
||||
})
|
||||
},
|
||||
|
||||
getFileStreamNew(project, file, query, callback) {
|
||||
const projectId = project._id
|
||||
const historyId = project.overleaf?.history?.id
|
||||
const fileId = file._id
|
||||
const hash = file.hash
|
||||
if (historyId && hash) {
|
||||
// new behaviour - request from history
|
||||
const range = _extractRange(query?.range)
|
||||
HistoryManager.requestBlobWithFallback(
|
||||
projectId,
|
||||
hash,
|
||||
fileId,
|
||||
'GET',
|
||||
range,
|
||||
function (err, result) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
const { stream } = result
|
||||
callback(null, stream)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
// original behaviour
|
||||
FileStoreHandler.getFileStream(projectId, fileId, query, callback)
|
||||
}
|
||||
},
|
||||
|
||||
getFileStream(projectId, fileId, query, callback) {
|
||||
let queryString = '?from=getFileStream'
|
||||
if (query != null && query.format != null) {
|
||||
@@ -299,6 +327,12 @@ const FileStoreHandler = {
|
||||
},
|
||||
}
|
||||
|
||||
function _extractRange(range) {
|
||||
if (typeof range === 'string' && /\d+-\d+/.test(range)) {
|
||||
return `bytes=${range}`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FileStoreHandler
|
||||
module.exports.promises = promisifyAll(FileStoreHandler, {
|
||||
multiResult: {
|
||||
|
||||
@@ -23,7 +23,7 @@ const LinkedFilesHandler = {
|
||||
},
|
||||
|
||||
async getSourceProject(data) {
|
||||
const projection = { _id: 1, name: 1 }
|
||||
const projection = { _id: 1, name: 1, overleaf: 1 } // include the historyId for future use
|
||||
if (data.v1_source_doc_id != null) {
|
||||
const project = await Project.findOne(
|
||||
{ 'overleaf.id': data.v1_source_doc_id },
|
||||
|
||||
@@ -134,9 +134,9 @@ module.exports = ProjectFileAgent = {
|
||||
}
|
||||
) // Created
|
||||
} else if (type === 'file') {
|
||||
return FileStoreHandler.getFileStream(
|
||||
sourceProject._id,
|
||||
entity._id,
|
||||
return FileStoreHandler.getFileStreamNew(
|
||||
sourceProject,
|
||||
entity,
|
||||
null,
|
||||
function (err, fileStream) {
|
||||
if (err != null) {
|
||||
|
||||
Reference in New Issue
Block a user