-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
913: Document Viewer improvements #916
Changes from 3 commits
b890320
cfc022c
ddf60dd
a1ffa64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Response } from 'express'; | ||
|
||
import { sendErrorResponse } from '@src/controller/handleError'; | ||
import { isValidLevel, LEVEL_NAMES } from '@src/models/level'; | ||
|
||
export function validateLevel(response: Response, level?: LEVEL_NAMES) { | ||
if (level === undefined) { | ||
sendErrorResponse(response, 400, 'Level not provided'); | ||
return null; | ||
} | ||
|
||
if (!isValidLevel(level)) { | ||
sendErrorResponse(response, 400, 'Invalid level'); | ||
return null; | ||
} | ||
|
||
return level; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,19 +58,16 @@ function getSandboxDocumentMetas() { | |
return [...getDocumentMetas('common'), ...getDocumentMetas('sandbox')]; | ||
} | ||
|
||
function getDocumentMetas(folder: string) { | ||
function getDocumentMetas(folder: string): DocumentMeta[] { | ||
const filepath = `resources/documents/${folder}`; | ||
const documentMetas: DocumentMeta[] = []; | ||
|
||
fs.readdirSync(filepath).forEach((file) => { | ||
return fs.readdirSync(filepath).map((file) => { | ||
const fileType = file.split('.').pop() ?? ''; | ||
documentMetas.push({ | ||
filename: file, | ||
filetype: fileType === 'csv' ? 'text/csv' : fileType, | ||
return { | ||
fileName: file, | ||
fileType: fileType === 'csv' ? 'text/csv' : fileType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo fixes! This was causing redundant HEAD requests in the UI. |
||
folder, | ||
}); | ||
}; | ||
}); | ||
return documentMetas; | ||
} | ||
|
||
// store vectorised documents for each level as array | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Request } from 'express'; | ||
|
||
import { ChatModel } from '@src/models/chat'; | ||
import { ChatMessage } from '@src/models/chatMessage'; | ||
import { Defence } from '@src/models/defence'; | ||
import { DocumentMeta } from '@src/models/document'; | ||
import { EmailInfo } from '@src/models/email'; | ||
import { LEVEL_NAMES } from '@src/models/level'; | ||
|
||
export type ProgressResetRequest = Request< | ||
never, | ||
{ | ||
emails: EmailInfo[]; | ||
chatHistory: ChatMessage[]; | ||
defences?: Defence[]; | ||
chatModel?: ChatModel; | ||
availableDocs?: DocumentMeta[]; | ||
}, | ||
never, | ||
{ | ||
level?: LEVEL_NAMES; | ||
} | ||
>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import express from 'express'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
import { handleGetDocuments } from '@src/controller/documentController'; | ||
import { handleHealthCheck } from '@src/controller/healthController'; | ||
|
||
import { importMetaUrl } from './importMetaUtils'; | ||
|
@@ -11,8 +10,13 @@ export default express | |
.use( | ||
'/documents', | ||
express.static( | ||
fileURLToPath(new URL('../../resources/documents', importMetaUrl())) | ||
fileURLToPath(new URL('../../resources/documents', importMetaUrl())), | ||
{ | ||
cacheControl: true, | ||
maxAge: 604800000, // 7 days as millis | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documents rarely change, so we can tell the browser to cache them. |
||
immutable: true, | ||
index: false, | ||
} | ||
) | ||
) | ||
.get('/documents', handleGetDocuments) | ||
.get('/health', handleHealthCheck); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this pattern