Skip to content

Commit bdc3119

Browse files
committed
simplify
1 parent ac1c621 commit bdc3119

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

src/services/db/GitFileSystemService.ts

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export default class GitFileSystemService {
370370
// Validate that the filePath is a valid relative path to prevent directory
371371
// traversal attacks
372372
const repoBaseDirectory = `${efsVolPath}/${repoName}`
373-
const fullFilePath = path.resolve(repoBaseDirectory, filePath)
373+
const fullFilePath = path.join(repoBaseDirectory, filePath)
374374
const isSafe = isSafePath(fullFilePath, repoBaseDirectory)
375375

376376
if (!isSafe) {
@@ -994,39 +994,35 @@ export default class GitFileSystemService {
994994
encoding: "utf-8" | "base64" = "utf-8"
995995
): ResultAsync<GitFile, GitFileSystemError | NotFoundError> {
996996
const defaultEfsVolPath = EFS_VOL_PATH_STAGING
997-
return this.getFilePathStats(repoName, filePath, true)
998-
.andThen(() =>
999-
ResultAsync.combine([
1000-
ResultAsync.fromPromise(
1001-
fs.promises.readFile(
1002-
`${defaultEfsVolPath}/${repoName}/${filePath}`,
1003-
encoding
1004-
),
1005-
(error) => {
1006-
if (error instanceof Error && error.message.includes("ENOENT")) {
1007-
return new NotFoundError("File does not exist")
1008-
}
997+
return ResultAsync.combine([
998+
ResultAsync.fromPromise(
999+
fs.promises.readFile(
1000+
`${defaultEfsVolPath}/${repoName}/${filePath}`,
1001+
encoding
1002+
),
1003+
(error) => {
1004+
if (error instanceof Error && error.message.includes("ENOENT")) {
1005+
return new NotFoundError("File does not exist")
1006+
}
10091007

1010-
logger.error(`Error when reading ${filePath}: ${error}`)
1008+
logger.error(`Error when reading ${filePath}: ${error}`)
10111009

1012-
if (error instanceof Error) {
1013-
return new GitFileSystemError("Unable to read file")
1014-
}
1010+
if (error instanceof Error) {
1011+
return new GitFileSystemError("Unable to read file")
1012+
}
10151013

1016-
return new GitFileSystemError("An unknown error occurred")
1017-
}
1018-
),
1019-
this.getGitBlobHash(repoName, filePath, true),
1020-
])
1021-
)
1022-
.map((contentAndHash) => {
1023-
const [content, sha] = contentAndHash
1024-
const result: GitFile = {
1025-
content,
1026-
sha,
1014+
return new GitFileSystemError("An unknown error occurred")
10271015
}
1028-
return result
1029-
})
1016+
),
1017+
this.getGitBlobHash(repoName, filePath, true),
1018+
]).map((contentAndHash) => {
1019+
const [content, sha] = contentAndHash
1020+
const result: GitFile = {
1021+
content,
1022+
sha,
1023+
}
1024+
return result
1025+
})
10301026
}
10311027

10321028
getFileExtension(fileName: string): Result<string, MediaTypeError> {

0 commit comments

Comments
 (0)