mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-20 06:55:08 +00:00
Sanitize user attached images. Constrain chat input width on home page
Set max combined images size to 20mb to allow multiple photos to be shared
This commit is contained in:
parent
6c393800cc
commit
b3fff43542
3 changed files with 9 additions and 6 deletions
|
@ -343,10 +343,13 @@ const ChatMessage = forwardRef<HTMLDivElement, ChatMessageProps>((props, ref) =>
|
||||||
|
|
||||||
if (props.chatMessage.images && props.chatMessage.images.length > 0) {
|
if (props.chatMessage.images && props.chatMessage.images.length > 0) {
|
||||||
const imagesInMd = props.chatMessage.images
|
const imagesInMd = props.chatMessage.images
|
||||||
.map(
|
.map((image, index) => {
|
||||||
(image, index) =>
|
const decodedImage = image.startsWith("data%3Aimage")
|
||||||
`<div class="${styles.imageWrapper}"><img src="${image.startsWith("data%3Aimage") ? decodeURIComponent(image) : image}" alt="uploaded image ${index + 1}" /></div>`,
|
? decodeURIComponent(image)
|
||||||
)
|
: image;
|
||||||
|
const sanitizedImage = DOMPurify.sanitize(decodedImage);
|
||||||
|
return `<div class="${styles.imageWrapper}"><img src="${sanitizedImage}" alt="uploaded image ${index + 1}" /></div>`;
|
||||||
|
})
|
||||||
.join("");
|
.join("");
|
||||||
message = `<div class="${styles.imagesContainer}">${imagesInMd}</div>${message}`;
|
message = `<div class="${styles.imagesContainer}">${imagesInMd}</div>${message}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,7 @@ function ChatBodyData(props: ChatBodyDataProps) {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className={`mx-auto ${props.isMobileWidth ? "w-full" : "w-fit"}`}>
|
<div className={`mx-auto ${props.isMobileWidth ? "w-full" : "w-fit max-w-screen-md"}`}>
|
||||||
{!props.isMobileWidth && (
|
{!props.isMobileWidth && (
|
||||||
<div
|
<div
|
||||||
className={`w-full ${styles.inputBox} shadow-lg bg-background align-middle items-center justify-center px-3 py-1 dark:bg-neutral-700 border-stone-100 dark:border-none dark:shadow-none rounded-2xl`}
|
className={`w-full ${styles.inputBox} shadow-lg bg-background align-middle items-center justify-center px-3 py-1 dark:bg-neutral-700 border-stone-100 dark:border-none dark:shadow-none rounded-2xl`}
|
||||||
|
|
|
@ -538,7 +538,7 @@ async def chat(
|
||||||
rate_limiter_per_day=Depends(
|
rate_limiter_per_day=Depends(
|
||||||
ApiUserRateLimiter(requests=600, subscribed_requests=6000, window=60 * 60 * 24, slug="chat_day")
|
ApiUserRateLimiter(requests=600, subscribed_requests=6000, window=60 * 60 * 24, slug="chat_day")
|
||||||
),
|
),
|
||||||
image_rate_limiter=Depends(ApiImageRateLimiter(max_images=10, max_combined_size_mb=10)),
|
image_rate_limiter=Depends(ApiImageRateLimiter(max_images=10, max_combined_size_mb=20)),
|
||||||
):
|
):
|
||||||
# Access the parameters from the body
|
# Access the parameters from the body
|
||||||
q = body.q
|
q = body.q
|
||||||
|
|
Loading…
Add table
Reference in a new issue