Merge pull request #18756 from overleaf/csh-issue-18573-remove-filestore-public-code

Remove public files code from filestore

GitOrigin-RevId: 05aedc8bc1068dc6cfb17c9f9402fddce273b4a9
This commit is contained in:
Christopher Hoskin 2024-08-02 12:17:07 +01:00 committed by Copybot
parent 0f2aaa6c0c
commit fa8161d4ce
9 changed files with 16 additions and 76 deletions

View file

@ -50,6 +50,12 @@ lint:
lint_fix: lint_fix:
$(RUN_LINTING) lint:fix $(RUN_LINTING) lint:fix
lint_styles:
$(RUN_LINTING) lint:styles
lint_styles_fix:
$(RUN_LINTING) lint:styles:fix
typecheck: typecheck:
$(RUN_LINTING) types:check $(RUN_LINTING) types:check

View file

@ -86,6 +86,12 @@ app.delete(
fileController.deleteProject fileController.deleteProject
) )
app.get(
'/project/:project_id/size',
keyBuilder.userProjectKeyMiddleware,
fileController.directorySize
)
app.head( app.head(
'/template/:template_id/v/:version/:format', '/template/:template_id/v/:version/:format',
keyBuilder.templateFileKeyMiddleware, keyBuilder.templateFileKeyMiddleware,
@ -107,39 +113,6 @@ app.post(
fileController.insertFile fileController.insertFile
) )
app.head(
'/project/:project_id/public/:public_file_id',
keyBuilder.publicFileKeyMiddleware,
fileController.getFileHead
)
app.get(
'/project/:project_id/public/:public_file_id',
keyBuilder.publicFileKeyMiddleware,
fileController.getFile
)
app.post(
'/project/:project_id/public/:public_file_id',
keyBuilder.publicFileKeyMiddleware,
fileController.insertFile
)
app.put(
'/project/:project_id/public/:public_file_id',
keyBuilder.publicFileKeyMiddleware,
bodyParser.json(),
fileController.copyFile
)
app.delete(
'/project/:project_id/public/:public_file_id',
keyBuilder.publicFileKeyMiddleware,
fileController.deleteFile
)
app.get(
'/project/:project_id/size',
keyBuilder.publicProjectKeyMiddleware,
fileController.directorySize
)
app.get( app.get(
'/bucket/:bucket/key/*', '/bucket/:bucket/key/*',
keyBuilder.bucketFileKeyMiddleware, keyBuilder.bucketFileKeyMiddleware,

View file

@ -5,8 +5,6 @@ module.exports = {
addCachingToKey, addCachingToKey,
userFileKeyMiddleware, userFileKeyMiddleware,
userProjectKeyMiddleware, userProjectKeyMiddleware,
publicFileKeyMiddleware,
publicProjectKeyMiddleware,
bucketFileKeyMiddleware, bucketFileKeyMiddleware,
templateFileKeyMiddleware, templateFileKeyMiddleware,
} }
@ -40,23 +38,12 @@ function userFileKeyMiddleware(req, res, next) {
function userProjectKeyMiddleware(req, res, next) { function userProjectKeyMiddleware(req, res, next) {
const { project_id: projectId } = req.params const { project_id: projectId } = req.params
req.project_id = projectId
req.key = `${projectId}/` req.key = `${projectId}/`
req.bucket = settings.filestore.stores.user_files req.bucket = settings.filestore.stores.user_files
next() next()
} }
function publicFileKeyMiddleware(req, res, next) {
if (settings.filestore.stores.public_files == null) {
return res.status(501).send('public files not available')
}
const { project_id: projectId, public_file_id: publicFileId } = req.params
req.key = `${projectId}/${publicFileId}`
req.bucket = settings.filestore.stores.public_files
next()
}
function bucketFileKeyMiddleware(req, res, next) { function bucketFileKeyMiddleware(req, res, next) {
req.bucket = req.params.bucket req.bucket = req.params.bucket
req.key = req.params[0] req.key = req.params[0]
@ -82,12 +69,3 @@ function templateFileKeyMiddleware(req, res, next) {
next() next()
} }
function publicProjectKeyMiddleware(req, res, next) {
const { project_id: projectId } = req.params
req.project_id = projectId
req.bucket = settings.filestore.stores.user_files
next()
}

View file

@ -2,7 +2,7 @@ filestore
--data-dirs=uploads,user_files,template_files --data-dirs=uploads,user_files,template_files
--dependencies=s3,gcs --dependencies=s3,gcs
--docker-repos=gcr.io/overleaf-ops,us-east1-docker.pkg.dev/overleaf-ops/ol-docker --docker-repos=gcr.io/overleaf-ops,us-east1-docker.pkg.dev/overleaf-ops/ol-docker
--env-add=ENABLE_CONVERSIONS="true",USE_PROM_METRICS="true",AWS_S3_USER_FILES_BUCKET_NAME=fake_user_files,AWS_S3_TEMPLATE_FILES_BUCKET_NAME=fake_template_files,AWS_S3_PUBLIC_FILES_BUCKET_NAME=fake_public_files,GCS_USER_FILES_BUCKET_NAME=fake_userfiles,GCS_TEMPLATE_FILES_BUCKET_NAME=fake_templatefiles,GCS_PUBLIC_FILES_BUCKET_NAME=fake_publicfiles --env-add=ENABLE_CONVERSIONS="true",USE_PROM_METRICS="true",AWS_S3_USER_FILES_BUCKET_NAME=fake_user_files,AWS_S3_TEMPLATE_FILES_BUCKET_NAME=fake_template_files,GCS_USER_FILES_BUCKET_NAME=fake_userfiles,GCS_TEMPLATE_FILES_BUCKET_NAME=fake_templatefiles
--env-pass-through= --env-pass-through=
--esmock-loader=False --esmock-loader=False
--node-version=18.20.2 --node-version=18.20.2

View file

@ -17,8 +17,6 @@ if (process.env.BACKEND == null) {
process.env.AWS_S3_USER_FILES_BUCKET_NAME process.env.AWS_S3_USER_FILES_BUCKET_NAME
process.env.TEMPLATE_FILES_BUCKET_NAME = process.env.TEMPLATE_FILES_BUCKET_NAME =
process.env.AWS_S3_TEMPLATE_FILES_BUCKET_NAME process.env.AWS_S3_TEMPLATE_FILES_BUCKET_NAME
process.env.PUBLIC_FILES_BUCKET_NAME =
process.env.AWS_S3_PUBLIC_FILES_BUCKET_NAME
} else { } else {
process.env.BACKEND = 'fs' process.env.BACKEND = 'fs'
process.env.USER_FILES_BUCKET_NAME = Path.join(__dirname, '../user_files') process.env.USER_FILES_BUCKET_NAME = Path.join(__dirname, '../user_files')
@ -26,10 +24,6 @@ if (process.env.BACKEND == null) {
__dirname, __dirname,
'../template_files' '../template_files'
) )
process.env.PUBLIC_FILES_BUCKET_NAME = Path.join(
__dirname,
'../public_files'
)
} }
} }
@ -79,7 +73,6 @@ const settings = {
stores: { stores: {
user_files: process.env.USER_FILES_BUCKET_NAME, user_files: process.env.USER_FILES_BUCKET_NAME,
template_files: process.env.TEMPLATE_FILES_BUCKET_NAME, template_files: process.env.TEMPLATE_FILES_BUCKET_NAME,
public_files: process.env.PUBLIC_FILES_BUCKET_NAME,
}, },
fallback: process.env.FALLBACK_BACKEND fallback: process.env.FALLBACK_BACKEND

View file

@ -35,10 +35,8 @@ services:
USE_PROM_METRICS: "true" USE_PROM_METRICS: "true"
AWS_S3_USER_FILES_BUCKET_NAME: fake_user_files AWS_S3_USER_FILES_BUCKET_NAME: fake_user_files
AWS_S3_TEMPLATE_FILES_BUCKET_NAME: fake_template_files AWS_S3_TEMPLATE_FILES_BUCKET_NAME: fake_template_files
AWS_S3_PUBLIC_FILES_BUCKET_NAME: fake_public_files
GCS_USER_FILES_BUCKET_NAME: fake_userfiles GCS_USER_FILES_BUCKET_NAME: fake_userfiles
GCS_TEMPLATE_FILES_BUCKET_NAME: fake_templatefiles GCS_TEMPLATE_FILES_BUCKET_NAME: fake_templatefiles
GCS_PUBLIC_FILES_BUCKET_NAME: fake_publicfiles
depends_on: depends_on:
s3: s3:
condition: service_healthy condition: service_healthy
@ -58,7 +56,7 @@ services:
s3: s3:
image: adobe/s3mock:2.4.14 image: adobe/s3mock:2.4.14
environment: environment:
- initialBuckets=fake_user_files,fake_template_files,fake_public_files,bucket - initialBuckets=fake_user_files,fake_template_files,bucket
healthcheck: healthcheck:
test: wget --quiet --output-document=/dev/null http://localhost:9090 test: wget --quiet --output-document=/dev/null http://localhost:9090
interval: 1s interval: 1s

View file

@ -51,10 +51,8 @@ services:
USE_PROM_METRICS: "true" USE_PROM_METRICS: "true"
AWS_S3_USER_FILES_BUCKET_NAME: fake_user_files AWS_S3_USER_FILES_BUCKET_NAME: fake_user_files
AWS_S3_TEMPLATE_FILES_BUCKET_NAME: fake_template_files AWS_S3_TEMPLATE_FILES_BUCKET_NAME: fake_template_files
AWS_S3_PUBLIC_FILES_BUCKET_NAME: fake_public_files
GCS_USER_FILES_BUCKET_NAME: fake_userfiles GCS_USER_FILES_BUCKET_NAME: fake_userfiles
GCS_TEMPLATE_FILES_BUCKET_NAME: fake_templatefiles GCS_TEMPLATE_FILES_BUCKET_NAME: fake_templatefiles
GCS_PUBLIC_FILES_BUCKET_NAME: fake_publicfiles
user: node user: node
depends_on: depends_on:
s3: s3:
@ -66,7 +64,7 @@ services:
s3: s3:
image: adobe/s3mock:2.4.14 image: adobe/s3mock:2.4.14
environment: environment:
- initialBuckets=fake_user_files,fake_template_files,fake_public_files,bucket - initialBuckets=fake_user_files,fake_template_files,bucket
healthcheck: healthcheck:
test: wget --quiet --output-document=/dev/null http://localhost:9090 test: wget --quiet --output-document=/dev/null http://localhost:9090
interval: 1s interval: 1s

View file

@ -88,10 +88,8 @@ describe('Filestore', function () {
const BUCKET_NAMES = [ const BUCKET_NAMES = [
process.env.GCS_USER_FILES_BUCKET_NAME, process.env.GCS_USER_FILES_BUCKET_NAME,
process.env.GCS_PUBLIC_FILES_BUCKET_NAME,
process.env.GCS_TEMPLATE_FILES_BUCKET_NAME, process.env.GCS_TEMPLATE_FILES_BUCKET_NAME,
`${process.env.GCS_USER_FILES_BUCKET_NAME}-deleted`, `${process.env.GCS_USER_FILES_BUCKET_NAME}-deleted`,
`${process.env.GCS_PUBLIC_FILES_BUCKET_NAME}-deleted`,
`${process.env.GCS_TEMPLATE_FILES_BUCKET_NAME}-deleted`, `${process.env.GCS_TEMPLATE_FILES_BUCKET_NAME}-deleted`,
] ]

View file

@ -24,7 +24,6 @@ function s3Stores() {
return { return {
user_files: process.env.AWS_S3_USER_FILES_BUCKET_NAME, user_files: process.env.AWS_S3_USER_FILES_BUCKET_NAME,
template_files: process.env.AWS_S3_TEMPLATE_FILES_BUCKET_NAME, template_files: process.env.AWS_S3_TEMPLATE_FILES_BUCKET_NAME,
public_files: process.env.AWS_S3_PUBLIC_FILES_BUCKET_NAME,
} }
} }
@ -44,14 +43,12 @@ function gcsStores() {
return { return {
user_files: process.env.GCS_USER_FILES_BUCKET_NAME, user_files: process.env.GCS_USER_FILES_BUCKET_NAME,
template_files: process.env.GCS_TEMPLATE_FILES_BUCKET_NAME, template_files: process.env.GCS_TEMPLATE_FILES_BUCKET_NAME,
public_files: process.env.GCS_PUBLIC_FILES_BUCKET_NAME,
} }
} }
function fsStores() { function fsStores() {
return { return {
user_files: Path.resolve(__dirname, '../../../user_files'), user_files: Path.resolve(__dirname, '../../../user_files'),
public_files: Path.resolve(__dirname, '../../../public_files'),
template_files: Path.resolve(__dirname, '../../../template_files'), template_files: Path.resolve(__dirname, '../../../template_files'),
} }
} }
@ -59,7 +56,6 @@ function fsStores() {
function fallbackStores(primaryConfig, fallbackConfig) { function fallbackStores(primaryConfig, fallbackConfig) {
return { return {
[primaryConfig.user_files]: fallbackConfig.user_files, [primaryConfig.user_files]: fallbackConfig.user_files,
[primaryConfig.public_files]: fallbackConfig.public_files,
[primaryConfig.template_files]: fallbackConfig.template_files, [primaryConfig.template_files]: fallbackConfig.template_files,
} }
} }