feat: add secure remote channel media

This commit is contained in:
lofyer
2026-08-09 20:33:35 +08:00
parent 6c891f3522
commit 66b098ae36
46 changed files with 4403 additions and 1594 deletions
+5 -22
View File
@@ -39,6 +39,7 @@ import type {
SearchResult
} from './types'
import { UrlImporter } from './url-importer'
import { mimeTypeFromFileName } from '../file-media-type'
type ScannedFile = {
absolutePath: string
@@ -94,27 +95,6 @@ function isInside(root: string, candidate: string): boolean {
return path === '' || (!path.startsWith('..') && !isAbsolute(path))
}
function mimeTypeFor(path: string): string {
const extension = extname(path).toLowerCase()
const types: Record<string, string> = {
'.csv': 'text/csv',
'.docx':
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'.html': 'text/html',
'.htm': 'text/html',
'.json': 'application/json',
'.md': 'text/markdown',
'.pdf': 'application/pdf',
'.pptx':
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'.txt': 'text/plain',
'.xlsx':
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'.xml': 'application/xml'
}
return types[extension] ?? 'text/plain'
}
export class KnowledgeService {
readonly database: KnowledgeDatabase
private readonly managedRoot: string
@@ -633,7 +613,10 @@ export class KnowledgeService {
sourceId: source.id,
externalId: file.relativePath,
title: parsed.title,
mimeType: mimeTypeFor(file.absolutePath),
mimeType: mimeTypeFromFileName(
file.absolutePath,
'text/plain'
),
sourceLocation: file.absolutePath,
checksum,
metadata: {