mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-27 11:20:42 +01:00
Improve workspace file viewer previews
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
d503982075
commit
fec3c19a0e
8 files changed
+185
-63
No files matched your search
@@ -87,6 +87,13 @@ const IMAGE_CONTENT_TYPES = new Map([
|
||||
[".webp", "image/webp"],
|
||||
]);
|
||||
|
||||
const VIDEO_CONTENT_TYPES = new Map([
|
||||
[".m4v", "video/mp4"],
|
||||
[".mov", "video/quicktime"],
|
||||
[".mp4", "video/mp4"],
|
||||
[".webm", "video/webm"],
|
||||
]);
|
||||
|
||||
type IssueRow = typeof issues.$inferSelect;
|
||||
type ExecutionWorkspaceRow = typeof executionWorkspaces.$inferSelect;
|
||||
type ProjectWorkspaceRow = typeof projectWorkspaces.$inferSelect;
|
||||
@@ -118,7 +125,9 @@ type WorkspaceFileListQueryInput = {
|
||||
};
|
||||
|
||||
function previewCapForKind(kind: WorkspaceFilePreviewKind) {
|
||||
return kind === "image" || kind === "pdf" ? WORKSPACE_FILE_MEDIA_MAX_BYTES : WORKSPACE_FILE_TEXT_MAX_BYTES;
|
||||
return kind === "image" || kind === "video" || kind === "pdf"
|
||||
? WORKSPACE_FILE_MEDIA_MAX_BYTES
|
||||
: WORKSPACE_FILE_TEXT_MAX_BYTES;
|
||||
}
|
||||
|
||||
function relativePathFromReal(rootReal: string, targetReal: string) {
|
||||
@@ -184,6 +193,7 @@ function shouldPruneSegments(segments: string[]) {
|
||||
function contentTypeForPath(filePath: string): string | null {
|
||||
const ext = path.extname(filePath).toLowerCase();
|
||||
if (IMAGE_CONTENT_TYPES.has(ext)) return IMAGE_CONTENT_TYPES.get(ext) ?? null;
|
||||
if (VIDEO_CONTENT_TYPES.has(ext)) return VIDEO_CONTENT_TYPES.get(ext) ?? null;
|
||||
if (ext === ".pdf") return "application/pdf";
|
||||
if (ext === ".svg") return "image/svg+xml";
|
||||
if (ext === ".html" || ext === ".htm") return "text/html";
|
||||
@@ -194,6 +204,7 @@ function contentTypeForPath(filePath: string): string | null {
|
||||
function previewKindForKnownContentType(contentType: string | null): WorkspaceFilePreviewKind | null {
|
||||
if (!contentType) return null;
|
||||
if (contentType.startsWith("image/") && contentType !== "image/svg+xml") return "image";
|
||||
if (contentType.startsWith("video/")) return "video";
|
||||
if (contentType === "application/pdf") return "pdf";
|
||||
if (contentType === "text/html") return "unsupported";
|
||||
if (contentType === "image/svg+xml" || contentType.startsWith("text/")) return "text";
|
||||
|
||||
@@ -1936,6 +1936,7 @@ async function isRuntimeServiceUrlHealthy(
|
||||
) {
|
||||
if (!url) return true;
|
||||
const healthUrl = resolveRuntimeServiceHealthUrl(url, input);
|
||||
if (!healthUrl) return true;
|
||||
try {
|
||||
const response = await fetch(healthUrl, { signal: AbortSignal.timeout(2_000) });
|
||||
return response.ok;
|
||||
|
||||
Reference in new issue
Block a user