scanfile/server/web/fileView.templ

207 lines
4.7 KiB
Text

package web
import "git.jmbit.de/jmb/scanfile/server/internal/sqlc"
import "git.jmbit.de/jmb/scanfile/server/web/templui/components/table"
import "encoding/hex"
import "git.jmbit.de/jmb/scanfile/server/web/templui/components/button"
import "git.jmbit.de/jmb/scanfile/server/web/templui/components/modal"
import "git.jmbit.de/jmb/scanfile/server/internal/processing"
import "fmt"
templ FileView(file sqlc.File, fileProperties sqlc.FileProperty) {
@Base(file.Name) {
<div class="w-full">
<h1 class="text-4xl">File Name: {file.Name}</h1>
@FileViewDeleteModal(file.ID.String())
@FileViewDownloadModal(file.ID.String())
<br/>
</div>
<div class="grid grid-cols-2 gap-4">
@FileViewGenericTable(file, fileProperties)
if processing.TypeFromMime(file.Mimetype) == processing.TypeMSOffice {
@FileViewMsofficeLoader(file.ID.String())
}
</div>
}
}
templ FileViewGenericTable(file sqlc.File, fileProperties sqlc.FileProperty) {
<div class="w-full">
<h2 class="text-3xl">Generic Information</h2>
@table.Table() {
@table.Row() {
@table.Cell() {
Size
}
@table.Cell() {
{file.Size} Bytes
}
}
@table.Row() {
@table.Cell() {
Filetype
}
@table.Cell() {
{file.Mimetype}
}
}
@table.Row() {
@table.Cell() {
Blake2b Hash
}
@table.Cell() {
{hex.EncodeToString(file.Blake2)}
}
}
@table.Row() {
@table.Cell() {
SHA256 Hash
}
@table.Cell() {
{hex.EncodeToString(fileProperties.Sha256)}
}
}
@table.Row() {
@table.Cell() {
MD5 Hash
}
@table.Cell() {
{hex.EncodeToString(fileProperties.Md5)}
}
}
if fileProperties.LibmagicMime.Valid {
@table.Row() {
@table.Cell() {
Mimetype
}
@table.Cell() {
{fileProperties.LibmagicMime.String}
}
}
}
if fileProperties.LibmagicExtension.Valid {
@table.Row() {
@table.Cell() {
File Extensions
}
@table.Cell() {
{fileProperties.LibmagicExtension.String}
}
}
}
if fileProperties.LibmagicApple.Valid {
@table.Row() {
@table.Cell() {
Apple Filetype
}
@table.Cell() {
{fileProperties.LibmagicApple.String}
}
}
}
@table.Row() {
@table.Cell() {
Uploaded
}
@table.Cell() {
{file.Created.Time.String()}
}
}
}
</div>
}
templ FileViewDeleteModal(fileid string) {
@modal.Trigger(modal.TriggerProps{
ModalID: "delete-modal",
Class: "p-1",
}) {
@button.Button(button.Props{
Variant: button.VariantDestructive,
}) {
Delete
}
}
@modal.Modal(modal.Props{
ID: "delete-modal",
Class: "max-w-md",
}) {
@modal.Header() {
Are you sure you want to delete this file?
}
@modal.Body() {
This action cannot be undone. This will permanently delete the file from the server.
}
@modal.Footer() {
<div class="flex gap-2">
@modal.Close(modal.CloseProps{
ModalID: "delete-modal",
}) {
@button.Button() {
Cancel
}
}
@modal.Close(modal.CloseProps{
ModalID: "delete-modal",
}) {
@button.Button(button.Props{
Variant: button.VariantDestructive,
Href: fmt.Sprintf("/files/%s/delete", fileid),
}) {
Delete
}
}
</div>
}
}
@modal.Script()
}
templ FileViewDownloadModal(fileid string) {
@modal.Trigger(modal.TriggerProps{
ModalID: "download-modal",
Class: "p-1",
}) {
@button.Button(button.Props{
Variant: button.VariantDefault,
}) {
Download
}
}
@modal.Modal(modal.Props{
ID: "download-modal",
Class: "max-w-md",
}) {
@modal.Header() {
Download this file?
}
@modal.Body() {
files downloaded from scanfile can be harmful to your system. Are you sure you want to continue?
}
@modal.Footer() {
<div class="flex gap-2">
@modal.Close(modal.CloseProps{
ModalID: "download-modal",
}) {
@button.Button() {
Cancel
}
}
@modal.Close(modal.CloseProps{
ModalID: "download-modal",
}) {
@button.Button(button.Props{
Variant: button.VariantDestructive,
Href: fmt.Sprintf("/files/%s/download", fileid),
}) {
Download
}
}
</div>
}
}
@modal.Script()
}