-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added preview for json, vtt and m3u8 files
- Loading branch information
Showing
16 changed files
with
343 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
{ | ||
"name": "mixwave", | ||
"scripts": { | ||
"dev": "turbo watch dev", | ||
"build": "turbo build", | ||
"start": "turbo start" | ||
"dev": "turbo dev", | ||
"build": "turbo build" | ||
}, | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from "../contract"; | ||
|
||
export type { JobDto, FolderDto } from "../types"; | ||
export type { JobDto, FolderDto, PreviewDto } from "../types"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
Sheet, | ||
SheetContent, | ||
SheetDescription, | ||
SheetHeader, | ||
SheetTitle, | ||
} from "@/components/ui/sheet"; | ||
import type { PreviewDto } from "@/tsr"; | ||
|
||
type StoragePreviewProps = { | ||
preview: PreviewDto | null; | ||
onClose(): void; | ||
}; | ||
|
||
export function StoragePreview({ preview, onClose }: StoragePreviewProps) { | ||
return ( | ||
<Sheet open={preview !== null} onOpenChange={onClose}> | ||
<SheetContent className="sm:max-w-none w-[640px]"> | ||
<SheetHeader> | ||
<SheetTitle>Preview</SheetTitle> | ||
{preview ? ( | ||
<> | ||
<SheetDescription> | ||
<p>{preview.path}</p> | ||
</SheetDescription> | ||
<pre className="text-xs overflow-auto">{preview.data}</pre> | ||
</> | ||
) : null} | ||
</SheetHeader> | ||
</SheetContent> | ||
</Sheet> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { TableCell, TableRow } from "@/components/ui/table"; | ||
import { tsr } from "@/tsr"; | ||
import { useState } from "react"; | ||
import { Loader } from "./Loader"; | ||
import type { FolderDto, PreviewDto } from "@/tsr"; | ||
|
||
type StorageRowFileProps = { | ||
name: string; | ||
content: Extract<FolderDto["contents"][0], { type: "file" }>; | ||
setPreview(preview: PreviewDto): void; | ||
}; | ||
|
||
export function StorageRowFile({ | ||
name, | ||
content, | ||
setPreview, | ||
}: StorageRowFileProps) { | ||
const [loading, setLoading] = useState(false); | ||
|
||
const onClick = async () => { | ||
setLoading(true); | ||
try { | ||
const response = await tsr.getStoragePreview.query({ | ||
query: { path: content.path }, | ||
}); | ||
if (response.status === 200) { | ||
setPreview(response.body); | ||
} | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const isPreview = | ||
name.endsWith(".vtt") || name.endsWith(".m3u8") || name.endsWith(".json"); | ||
|
||
return ( | ||
<TableRow> | ||
<TableCell></TableCell> | ||
<TableCell> | ||
{isPreview ? ( | ||
<button | ||
disabled={loading} | ||
className="flex items-center disabled:text-muted-foreground" | ||
onClick={onClick} | ||
> | ||
{name} | ||
{loading ? <Loader className="w-4 h-4 ml-2" /> : null} | ||
</button> | ||
) : ( | ||
name | ||
)} | ||
</TableCell> | ||
<TableCell>{content.size} bytes</TableCell> | ||
</TableRow> | ||
); | ||
} |
Oops, something went wrong.