- Updated .env.example to include configuration for OnlyOffice Document Server. - Modified the workspace configuration to remove the drive-suite path. - Adjusted TypeScript environment imports for consistency. - Enhanced Next.js configuration to disable canvas in Webpack. - Updated package.json to include new dependencies for OnlyOffice and PDF.js. - Added global styles for OnlyOffice theme integration in the CSS. - Created new layout and page components for the Drive feature, including public sharing and editing functionalities. - Updated metadata handling across various layouts to reflect the new app structure.
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
"use client"
|
|
|
|
import { useQuery } from "@tanstack/react-query"
|
|
import { fetchDrivePreviewBlob, fetchDriveServerPreview, blobForPreview } from "@/lib/api/drive-download"
|
|
import { commitPreviewBlobUrl } from "@/lib/api/preview-blob-url"
|
|
import { useAuthReady } from "@/lib/api/use-auth-ready"
|
|
import type { DriveFileInfo } from "@/lib/api/types"
|
|
import { drivePreviewKind, driveServerThumbnail } from "@/lib/drive/drive-preview"
|
|
|
|
export type DriveThumbDisplay = "image" | "video"
|
|
|
|
export type DrivePreviewThumb = {
|
|
url: string
|
|
display: DriveThumbDisplay
|
|
}
|
|
|
|
export function useDrivePreviewThumb(file: DriveFileInfo, enabled: boolean) {
|
|
const { ready, authenticated } = useAuthReady()
|
|
const clientKind = drivePreviewKind(file)
|
|
const canPreview =
|
|
file.type === "file" &&
|
|
clientKind !== "audio" &&
|
|
(driveServerThumbnail(file) || clientKind !== null)
|
|
|
|
return useQuery({
|
|
queryKey: ["drive", "preview-thumb", file.path, file.etag],
|
|
enabled: ready && authenticated && enabled && canPreview,
|
|
queryFn: async ({ client, queryKey }): Promise<DrivePreviewThumb> => {
|
|
const previous = client.getQueryData<DrivePreviewThumb>(queryKey)
|
|
|
|
if (driveServerThumbnail(file)) {
|
|
try {
|
|
const raw = await fetchDriveServerPreview(file, 400, 300)
|
|
const blob = blobForPreview(raw, file.mime_type ?? "", file.name)
|
|
return commitPreviewBlobUrl(previous, {
|
|
url: URL.createObjectURL(blob),
|
|
display: "image",
|
|
})
|
|
} catch (err) {
|
|
// PDF / bureautique : pas de repli client (<img> ne lit pas le binaire).
|
|
if (!clientKind || clientKind === "audio" || clientKind === "pdf") {
|
|
throw err
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!clientKind || clientKind === "audio" || clientKind === "pdf") {
|
|
throw new Error("preview unavailable")
|
|
}
|
|
|
|
const blob = await fetchDrivePreviewBlob({
|
|
path: file.path,
|
|
name: file.name,
|
|
mime_type: file.mime_type ?? "",
|
|
})
|
|
const previewBlob = blobForPreview(blob, file.mime_type ?? "", file.name)
|
|
return commitPreviewBlobUrl(previous, {
|
|
url: URL.createObjectURL(previewBlob),
|
|
display: clientKind === "video" ? "video" : "image",
|
|
})
|
|
},
|
|
staleTime: 5 * 60_000,
|
|
gcTime: 10 * 60_000,
|
|
retry: 1,
|
|
})
|
|
}
|