[filestore] remove user files endpoints (#28125)

* [filestore] remove user files endpoints

* [web] remove user files integration for filestore

GitOrigin-RevId: 565fa68a659c07420ee6141d0f276b4e4d2972e0
This commit is contained in:
Jakob Ackermann
2025-09-01 11:43:37 +02:00
committed by Copybot
parent 21d3879574
commit 319a542e8d
73 changed files with 1481 additions and 3587 deletions
@@ -844,9 +844,6 @@ const _ProjectController = {
isInvitedMember
),
capabilities,
projectHistoryBlobsEnabled: Features.hasFeature(
'project-history-blobs'
),
roMirrorOnClientNoLocalStorage:
Settings.adminOnlyLogin || project.name.startsWith('Debug: '),
languages: Settings.languages,
@@ -16,7 +16,6 @@ const CollaboratorsGetter = require('../Collaborators/CollaboratorsGetter')
const DocstoreManager = require('../Docstore/DocstoreManager')
const EditorRealTimeController = require('../Editor/EditorRealTimeController')
const HistoryManager = require('../History/HistoryManager')
const FilestoreHandler = require('../FileStore/FileStoreHandler')
const ChatApiHandler = require('../Chat/ChatApiHandler')
const { promiseMapWithLimit } = require('@overleaf/promise-utils')
const { READ_PREFERENCE_SECONDARY } = require('../../infrastructure/mongodb')
@@ -350,7 +349,6 @@ async function expireDeletedProject(projectId) {
deletedProject.project._id,
historyId
),
FilestoreHandler.promises.deleteProject(deletedProject.project._id),
ChatApiHandler.promises.destroyProject(deletedProject.project._id),
ProjectAuditLogEntry.deleteMany({ projectId }),
Modules.promises.hooks.fire('projectExpired', deletedProject.project._id),
@@ -7,7 +7,6 @@ const { Doc } = require('../../models/Doc')
const { File } = require('../../models/File')
const DocstoreManager = require('../Docstore/DocstoreManager')
const DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
const FileStoreHandler = require('../FileStore/FileStoreHandler')
const HistoryManager = require('../History/HistoryManager')
const ProjectCreationHandler = require('./ProjectCreationHandler')
const ProjectDeleter = require('./ProjectDeleter')
@@ -20,7 +19,6 @@ const SafePath = require('./SafePath')
const TpdsProjectFlusher = require('../ThirdPartyDataStore/TpdsProjectFlusher')
const _ = require('lodash')
const TagsHandler = require('../Tags/TagsHandler')
const Features = require('../../infrastructure/Features')
const ClsiCacheManager = require('../Compile/ClsiCacheManager')
module.exports = {
@@ -225,66 +223,29 @@ async function _copyFiles(sourceEntries, sourceProject, targetProject) {
async sourceEntry => {
const sourceFile = sourceEntry.file
const path = sourceEntry.path
const file = new File({ name: SafePath.clean(sourceFile.name) })
const file = new File({
name: SafePath.clean(sourceFile.name),
hash: sourceFile.hash,
})
if (sourceFile.linkedFileData != null) {
file.linkedFileData = sourceFile.linkedFileData
file.created = sourceFile.created
}
if (sourceFile.hash != null) {
file.hash = sourceFile.hash
}
let createdBlob = false
const usingFilestore = Features.hasFeature('filestore')
if (file.hash != null && Features.hasFeature('project-history-blobs')) {
try {
await HistoryManager.promises.copyBlob(
sourceHistoryId,
targetHistoryId,
file.hash
)
createdBlob = true
if (!usingFilestore) {
return { createdBlob, file, path, url: null }
}
} catch (err) {
if (!usingFilestore) {
throw OError.tag(err, 'unexpected error copying blob', {
sourceProjectId: sourceProject._id,
targetProjectId: targetProject._id,
sourceFile,
sourceHistoryId,
})
} else {
logger.error(
{
err,
sourceProjectId: sourceProject._id,
targetProjectId: targetProject._id,
sourceFile,
sourceHistoryId,
},
'unexpected error copying blob'
)
}
}
}
if (createdBlob && Features.hasFeature('project-history-blobs')) {
return { createdBlob, file, path, url: null }
}
if (!usingFilestore) {
// Note: This is also checked in app.mjs
throw new OError(
'bad config: need to enable either filestore or project-history-blobs'
try {
await HistoryManager.promises.copyBlob(
sourceHistoryId,
targetHistoryId,
file.hash
)
return { createdBlob: true, file, path }
} catch (err) {
throw OError.tag(err, 'unexpected error copying blob', {
sourceProjectId: sourceProject._id,
targetProjectId: targetProject._id,
sourceFile,
sourceHistoryId,
})
}
const url = await FileStoreHandler.promises.copyFile(
sourceProject._id,
sourceFile._id,
targetProject._id,
file._id
)
return { createdBlob, file, path, url }
}
)
return targetEntries
@@ -1,7 +1,6 @@
let ProjectEditorHandler
const _ = require('lodash')
const Path = require('path')
const Features = require('../../infrastructure/Features')
module.exports = ProjectEditorHandler = {
trackChangesAvailable: false,
@@ -98,18 +97,12 @@ module.exports = ProjectEditorHandler = {
},
buildFileModelView(file) {
const additionalFileProperties = {}
if (Features.hasFeature('project-history-blobs')) {
additionalFileProperties.hash = file.hash
}
return {
_id: file._id,
name: file.name,
linkedFileData: file.linkedFileData,
created: file.created,
...additionalFileProperties,
hash: file.hash,
}
},
@@ -333,7 +333,7 @@ const addFile = wrapWithLock({
if (!SafePath.isCleanFilename(fileName)) {
throw new Errors.InvalidNameError('invalid element name')
}
const { url, fileRef, createdBlob } =
const { fileRef, createdBlob } =
await ProjectEntityUpdateHandler._uploadFile(
projectId,
folderId,
@@ -347,7 +347,6 @@ const addFile = wrapWithLock({
folderId,
userId,
fileRef,
fileStoreUrl: url,
createdBlob,
source,
}
@@ -357,7 +356,6 @@ const addFile = wrapWithLock({
folderId,
userId,
fileRef,
fileStoreUrl,
createdBlob,
source,
}) {
@@ -374,7 +372,6 @@ const addFile = wrapWithLock({
createdBlob,
file: fileRef,
path: result && result.path && result.path.fileSystem,
url: fileStoreUrl,
},
]
await DocumentUpdaterHandler.promises.updateProjectStructure(
@@ -548,7 +545,7 @@ const upsertFile = wrapWithLock({
name: fileName,
linkedFileData,
}
const { url, fileRef, createdBlob } =
const { fileRef, createdBlob } =
await FileStoreHandler.promises.uploadFileFromDisk(
projectId,
fileArgs,
@@ -563,7 +560,6 @@ const upsertFile = wrapWithLock({
linkedFileData,
userId,
fileRef,
fileStoreUrl: url,
createdBlob,
source,
}
@@ -574,7 +570,6 @@ const upsertFile = wrapWithLock({
fileName,
userId,
fileRef,
fileStoreUrl,
createdBlob,
source,
}) {
@@ -639,7 +634,6 @@ const upsertFile = wrapWithLock({
createdBlob,
file: fileRef,
path: path.fileSystem,
url: fileStoreUrl,
},
],
newProject: project,
@@ -659,7 +653,6 @@ const upsertFile = wrapWithLock({
existingFile._id,
userId,
fileRef,
fileStoreUrl,
folderId,
source,
createdBlob
@@ -673,7 +666,6 @@ const upsertFile = wrapWithLock({
folderId,
userId,
fileRef,
fileStoreUrl,
createdBlob,
source,
})
@@ -733,15 +725,12 @@ const upsertFileWithPath = wrapWithLock({
name: fileName,
linkedFileData,
}
const {
url: fileStoreUrl,
fileRef,
createdBlob,
} = await FileStoreHandler.promises.uploadFileFromDisk(
projectId,
fileArgs,
fsPath
)
const { fileRef, createdBlob } =
await FileStoreHandler.promises.uploadFileFromDisk(
projectId,
fileArgs,
fsPath
)
return {
projectId,
@@ -751,7 +740,6 @@ const upsertFileWithPath = wrapWithLock({
linkedFileData,
userId,
fileRef,
fileStoreUrl,
createdBlob,
source,
}
@@ -764,7 +752,6 @@ const upsertFileWithPath = wrapWithLock({
linkedFileData,
userId,
fileRef,
fileStoreUrl,
createdBlob,
source,
}) {
@@ -787,7 +774,6 @@ const upsertFileWithPath = wrapWithLock({
linkedFileData,
userId,
fileRef,
fileStoreUrl,
createdBlob,
source,
})
@@ -1084,15 +1070,12 @@ const convertDocToFile = wrapWithLock({
}
await DocumentUpdaterHandler.promises.deleteDoc(projectId, docId, false)
const fsPath = await FileWriter.promises.writeLinesToDisk(projectId, lines)
const {
url: fileStoreUrl,
fileRef,
createdBlob,
} = await FileStoreHandler.promises.uploadFileFromDisk(
projectId,
{ name: doc.name, rev: rev + 1 },
fsPath
)
const { fileRef, createdBlob } =
await FileStoreHandler.promises.uploadFileFromDisk(
projectId,
{ name: doc.name, rev: rev + 1 },
fsPath
)
try {
await fs.promises.unlink(fsPath)
} catch (err) {
@@ -1103,7 +1086,6 @@ const convertDocToFile = wrapWithLock({
doc,
path: docPath,
fileRef,
fileStoreUrl,
userId,
source,
createdBlob,
@@ -1114,7 +1096,6 @@ const convertDocToFile = wrapWithLock({
doc,
path,
fileRef,
fileStoreUrl,
userId,
source,
createdBlob,
@@ -1133,7 +1114,7 @@ const convertDocToFile = wrapWithLock({
userId,
{
oldDocs: [{ doc, path }],
newFiles: [{ file: fileRef, path, url: fileStoreUrl, createdBlob }],
newFiles: [{ file: fileRef, path, createdBlob }],
newProject: project,
},
source
@@ -1380,7 +1361,6 @@ const ProjectEntityUpdateHandler = {
fileId,
userId,
newFileRef,
fileStoreUrl,
folderId,
source,
createdBlob
@@ -1409,7 +1389,6 @@ const ProjectEntityUpdateHandler = {
file: updatedFileRef,
createdBlob,
path: path.fileSystem,
url: fileStoreUrl,
},
]
const projectHistoryId = project.overleaf?.history?.id