Compare commits
1 Commits
hotfix/FA-
...
v1.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 89a2cf6db1 |
@@ -35,16 +35,8 @@ namespace FictionArchive.Service.FileService.Controllers
|
|||||||
BucketName = _s3Configuration.Bucket,
|
BucketName = _s3Configuration.Bucket,
|
||||||
Key = decodedPath
|
Key = decodedPath
|
||||||
});
|
});
|
||||||
|
|
||||||
Response.Headers.CacheControl = "public, max-age=604800"; // 7 days
|
return new FileStreamResult(s3Response.ResponseStream, s3Response.Headers.ContentType);
|
||||||
Response.Headers.LastModified = s3Response.LastModified?.ToString("R");
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(s3Response.ETag))
|
|
||||||
{
|
|
||||||
Response.Headers.ETag = s3Response.ETag;
|
|
||||||
}
|
|
||||||
|
|
||||||
return File(s3Response.ResponseStream, s3Response.Headers.ContentType);
|
|
||||||
}
|
}
|
||||||
catch (AmazonS3Exception e)
|
catch (AmazonS3Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -155,9 +155,10 @@
|
|||||||
<Card>
|
<Card>
|
||||||
<CardContent class="px-6 py-8 md:px-12">
|
<CardContent class="px-6 py-8 md:px-12">
|
||||||
<article
|
<article
|
||||||
class="prose prose-lg dark:prose-invert mx-auto max-w-none
|
class="prose prose-lg dark:prose-invert mx-auto max-w-none whitespace-pre-line
|
||||||
|
prose-p:text-foreground prose-p:mb-4 prose-p:leading-relaxed
|
||||||
prose-headings:text-foreground
|
prose-headings:text-foreground
|
||||||
[&>p]:text-foreground [&>p]:mb-6 [&>p]:leading-relaxed"
|
first:prose-p:mt-0 last:prose-p:mb-0"
|
||||||
>
|
>
|
||||||
{@html sanitizedBody}
|
{@html sanitizedBody}
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
@@ -1,42 +1,12 @@
|
|||||||
import DOMPurify from 'isomorphic-dompurify';
|
import DOMPurify from 'isomorphic-dompurify';
|
||||||
|
|
||||||
/**
|
|
||||||
* Splits plain text into paragraphs based on newlines.
|
|
||||||
* Double newlines create new paragraphs, single newlines become <br>.
|
|
||||||
* If the content already contains HTML block elements, returns as-is.
|
|
||||||
*/
|
|
||||||
function wrapInParagraphs(text: string): string {
|
|
||||||
// Check if content already has block-level HTML elements
|
|
||||||
const hasBlockElements = /<(p|div|h[1-6]|ul|ol|blockquote|pre|table|hr)[>\s]/i.test(text);
|
|
||||||
if (hasBlockElements) {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split on double newlines (paragraph breaks)
|
|
||||||
const paragraphs = text.split(/\n\s*\n/);
|
|
||||||
|
|
||||||
return paragraphs
|
|
||||||
.map((para) => {
|
|
||||||
const trimmed = para.trim();
|
|
||||||
if (!trimmed) return '';
|
|
||||||
// Convert single newlines to <br> within paragraphs
|
|
||||||
const withBreaks = trimmed.replace(/\n/g, '<br>');
|
|
||||||
return `<p>${withBreaks}</p>`;
|
|
||||||
})
|
|
||||||
.filter(Boolean)
|
|
||||||
.join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitizes chapter HTML content with extended allowed tags.
|
* Sanitizes chapter HTML content with extended allowed tags.
|
||||||
* More permissive than the description sanitizer to support
|
* More permissive than the description sanitizer to support
|
||||||
* formatted novel content including headings, lists, and images.
|
* formatted novel content including headings, lists, and images.
|
||||||
* Also wraps plain text in paragraph tags for better browser translate support.
|
|
||||||
*/
|
*/
|
||||||
export function sanitizeChapterHtml(html: string): string {
|
export function sanitizeChapterHtml(html: string): string {
|
||||||
// First wrap in paragraphs if needed, then sanitize
|
return DOMPurify.sanitize(html, {
|
||||||
const wrapped = wrapInParagraphs(html);
|
|
||||||
return DOMPurify.sanitize(wrapped, {
|
|
||||||
ALLOWED_TAGS: [
|
ALLOWED_TAGS: [
|
||||||
// Basic formatting
|
// Basic formatting
|
||||||
'b',
|
'b',
|
||||||
|
|||||||
Reference in New Issue
Block a user