Add archived threads and mobile file viewer (#3155)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: codex <[email protected]>
This commit is contained in:
93 files changed
+6792
-1137
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import {
|
||||
isWorkspaceBrowserPreviewPath,
|
||||
isWorkspaceImagePreviewPath,
|
||||
isWorkspacePreviewEntryPath,
|
||||
} from "./filePreview.ts";
|
||||
|
||||
describe("workspace file previews", () => {
|
||||
it.each(["report.html", "report.HTM", "document.pdf?download=1"])(
|
||||
"recognizes browser preview path %s",
|
||||
(path) => {
|
||||
expect(isWorkspaceBrowserPreviewPath(path)).toBe(true);
|
||||
expect(isWorkspacePreviewEntryPath(path)).toBe(true);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"icon.png",
|
||||
"photo.JPEG",
|
||||
"animation.gif",
|
||||
"vector.svg#mark",
|
||||
"texture.webp",
|
||||
"image.avif",
|
||||
])("recognizes image preview path %s", (path) => {
|
||||
expect(isWorkspaceImagePreviewPath(path)).toBe(true);
|
||||
expect(isWorkspacePreviewEntryPath(path)).toBe(true);
|
||||
});
|
||||
|
||||
it.each(["README.md", "src/index.ts", "image.png.ts", "png"])(
|
||||
"rejects non-preview path %s",
|
||||
(path) => {
|
||||
expect(isWorkspacePreviewEntryPath(path)).toBe(false);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
export const WORKSPACE_BROWSER_PREVIEW_EXTENSIONS = [".htm", ".html", ".pdf"] as const;
|
||||
|
||||
export const WORKSPACE_IMAGE_PREVIEW_EXTENSIONS = [
|
||||
".avif",
|
||||
".gif",
|
||||
".ico",
|
||||
".jpeg",
|
||||
".jpg",
|
||||
".png",
|
||||
".svg",
|
||||
".webp",
|
||||
] as const;
|
||||
|
||||
function hasPreviewExtension(path: string, extensions: ReadonlyArray<string>): boolean {
|
||||
const pathWithoutQuery = path.split(/[?#]/, 1)[0]?.toLowerCase() ?? "";
|
||||
return extensions.some((extension) => pathWithoutQuery.endsWith(extension));
|
||||
}
|
||||
|
||||
export function isWorkspaceBrowserPreviewPath(path: string): boolean {
|
||||
return hasPreviewExtension(path, WORKSPACE_BROWSER_PREVIEW_EXTENSIONS);
|
||||
}
|
||||
|
||||
export function isWorkspaceImagePreviewPath(path: string): boolean {
|
||||
return hasPreviewExtension(path, WORKSPACE_IMAGE_PREVIEW_EXTENSIONS);
|
||||
}
|
||||
|
||||
export function isWorkspacePreviewEntryPath(path: string): boolean {
|
||||
return isWorkspaceBrowserPreviewPath(path) || isWorkspaceImagePreviewPath(path);
|
||||
}
|
||||
Reference in new issue
Block a user