🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: fix file upload issue (#11122)
Arvin Xu1ae327ab539a
diff --git a/src/server/routers/lambda/__tests__/file.test.ts b/src/server/routers/lambda/__tests__/file.test.tsindex 9ae0f26c35e..0dd35b605ec 100644--- a/src/server/routers/lambda/__tests__/file.test.ts+++ b/src/server/routers/lambda/__tests__/file.test.ts@@ -245,7 +245,35 @@ describe('fileRouter', () => {);});- it('should handle getFileMetadata errors', async () => {+ it('should fallback to input size when getFileMetadata fails', async () => {+ mockFileModelCheckHash.mockResolvedValue({ isExist: false });+ mockFileModelCreate.mockResolvedValue({ id: 'new-file-id' });+ mockFileServiceGetFileMetadata.mockRejectedValue(new Error('File not found in S3'));++ const result = await caller.createFile({+ hash: 'test-hash',+ fileType: 'text',+ name: 'test.txt',+ size: 100,+ url: 'files/non-existent.txt',+ metadata: {},+ });++ expect(result).toEqual({+ id: 'new-file-id',+ url: 'https://lobehub.com/f/new-file-id',+ });++ // Verify create was called with input size as fallback+ expect(mockFileModelCreate).toHaveBeenCalledWith(+ expect.objectContaining({+ size: 100,+ }),+ true,+ );+ });++ it('should throw error when getFileMetadata fails and input size is less than 1', async () => {mockFileModelCheckHash.mockResolvedValue({ isExist: false });mockFileServiceGetFileMetadata.mockRejectedValue(new Error('File not found in S3'));@@ -254,11 +282,56 @@ describe('fileRouter', () => {hash: 'test-hash',fileType: 'text',name: 'test.txt',- size: 100,+ size: 0,url: 'files/non-existent.txt',metadata: {},}),- ).rejects.toThrow('File not found in S3');+ ).rejects.toThrow('File size must be at least 1 byte');+ });++ it('should use input size when getFileMetadata returns contentLength less than 1', async () => {+ mockFileModelCheckHash.mockResolvedValue({ isExist: false });+ mockFileModelCreate.mockResolvedValue({ id: 'new-file-id' });+ mockFileServiceGetFileMetadata.mockResolvedValue({+ contentLength: 0,+ contentType: 'text/plain',+ });++ await caller.createFile({+ hash: 'test-hash',+ fileType: 'text',+ name: 'test.txt',+ size: 100,+ url: 'files/test.txt',+ metadata: {},+ });++ // Verify create was called with input size since contentLength < 1+ expect(mockFileModelCreate).toHaveBeenCalledWith(+ expect.objectContaining({+ size: 100,+ }),+ true,+ );+ });++ it('should throw error when both getFileMetadata contentLength and input size are less than 1', async () => {+ mockFileModelCheckHash.mockResolvedValue({ isExist: false });+ mockFileServiceGetFileMetadata.mockResolvedValue({+ contentLength: 0,+ contentType: 'text/plain',+ });++ await expect(+ caller.createFile({+ hash: 'test-hash',+ fileType: 'text',+ name: 'test.txt',+ size: 0,+ url: 'files/test.txt',+ metadata: {},+ }),+ ).rejects.toThrow('File size must be at least 1 byte');});});diff --git a/src/server/routers/lambda/file.ts b/src/server/routers/lambda/file.tsindex 31ba6f2016f..c3022c887f6 100644--- a/src/server/routers/lambda/file.ts+++ b/src/server/routers/lambda/file.ts@@ -64,7 +64,19 @@ export const fileRouter = router({}}- const { contentLength: actualSize } = await ctx.fileService.getFileMetadata(input.url);+ let actualSize = input.size;+ try {+ const { contentLength } = await ctx.fileService.getFileMetadata(input.url);+ if (contentLength >= 1) {+ actualSize = contentLength;+ }+ } catch {+ // If metadata fetch fails, use original size from input+ }++ if (actualSize < 1) {+ throw new TRPCError({ code: 'BAD_REQUEST', message: 'File size must be at least 1 byte' });+ }const { id } = await ctx.fileModel.create({