mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #28628 from overleaf/bg-cache-history-size-on-project
Implement project size checks on file uploads GitOrigin-RevId: 4dffe237e6992b859f07964cffa82ff1c13e91c9
This commit is contained in:
@@ -7,6 +7,7 @@ const ProjectDetailsHandler = require('../Project/ProjectDetailsHandler')
|
||||
const { File } = require('../../models/File')
|
||||
const OError = require('@overleaf/o-error')
|
||||
const { promisifyAll } = require('@overleaf/promise-utils')
|
||||
const Modules = require('../../infrastructure/Modules')
|
||||
|
||||
const FileStoreHandler = {
|
||||
RETRY_ATTEMPTS: 3,
|
||||
@@ -69,24 +70,47 @@ const FileStoreHandler = {
|
||||
)
|
||||
return callback(new Error('can not upload symlink'))
|
||||
}
|
||||
FileHashManager.computeHash(fsPath, function (err, hash) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
FileStoreHandler._uploadToHistory(
|
||||
historyId,
|
||||
hash,
|
||||
stat.size,
|
||||
fsPath,
|
||||
function (err) {
|
||||
const size = stat.size
|
||||
Modules.hooks.fire(
|
||||
'preUploadFile',
|
||||
{ projectId, historyId, fileArgs, fsPath, size },
|
||||
preUploadErr => {
|
||||
if (preUploadErr) {
|
||||
return callback(preUploadErr)
|
||||
}
|
||||
FileHashManager.computeHash(fsPath, function (err, hash) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
fileArgs = { ...fileArgs, hash }
|
||||
callback(err, new File(fileArgs), true)
|
||||
}
|
||||
)
|
||||
})
|
||||
FileStoreHandler._uploadToHistory(
|
||||
historyId,
|
||||
hash,
|
||||
stat.size,
|
||||
fsPath,
|
||||
function (err) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
const fileRef = new File({ ...fileArgs, hash })
|
||||
Modules.hooks.fire(
|
||||
'postUploadFile',
|
||||
{
|
||||
projectId,
|
||||
fileRef,
|
||||
size,
|
||||
},
|
||||
postUploadErr => {
|
||||
if (postUploadErr) {
|
||||
return callback(postUploadErr)
|
||||
}
|
||||
callback(err, fileRef, true, size)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
},
|
||||
}
|
||||
@@ -94,7 +118,7 @@ const FileStoreHandler = {
|
||||
module.exports = FileStoreHandler
|
||||
module.exports.promises = promisifyAll(FileStoreHandler, {
|
||||
multiResult: {
|
||||
uploadFileFromDisk: ['fileRef', 'createdBlob'],
|
||||
uploadFileFromDiskWithHistoryId: ['fileRef', 'createdBlob'],
|
||||
uploadFileFromDisk: ['fileRef', 'createdBlob', 'size'],
|
||||
uploadFileFromDiskWithHistoryId: ['fileRef', 'createdBlob', 'size'],
|
||||
},
|
||||
})
|
||||
|
||||
@@ -62,6 +62,7 @@ const db = {
|
||||
projectHistoryFailures: internalDb.collection('projectHistoryFailures'),
|
||||
projectHistoryGlobalBlobs: internalDb.collection('projectHistoryGlobalBlobs'),
|
||||
projectHistoryLabels: internalDb.collection('projectHistoryLabels'),
|
||||
projectHistorySizes: internalDb.collection('projectHistorySizes'),
|
||||
projectHistorySyncState: internalDb.collection('projectHistorySyncState'),
|
||||
projectInvites: internalDb.collection('projectInvites'),
|
||||
projects: internalDb.collection('projects'),
|
||||
|
||||
Reference in New Issue
Block a user