feat: redirect to another link if file is not supported

This commit is contained in:
jabuxas 2024-10-16 23:34:08 -03:00
parent 18bc590525
commit 7ed16a5397
2 changed files with 12 additions and 2 deletions

View File

@ -29,7 +29,7 @@ var extensions = map[string]string{
".log": "text", ".txt": "text", ".csv": "text", ".log": "text", ".txt": "text", ".csv": "text",
".json": "text", ".env": "text", ".sum": "text", ".json": "text", ".env": "text", ".sum": "text",
".gitignore": "text", ".dockerfile": "text", ".Makefile": "text", ".gitignore": "text", ".dockerfile": "text", ".Makefile": "text",
".rst": "text", ".rst": "text", ".el": "text",
} }
func DisplayFile(app *Application, file string, w http.ResponseWriter) { func DisplayFile(app *Application, file string, w http.ResponseWriter) {
@ -59,5 +59,5 @@ func getType(file string) string {
if fileType, exists := extensions[extension]; exists { if fileType, exists := extensions[extension]; exists {
return fileType return fileType
} }
return "text" return "unknown"
} }

View File

@ -187,6 +187,11 @@
border-radius: 10px; border-radius: 10px;
border: 3px solid #2e2e2e; border: 3px solid #2e2e2e;
} }
a {
color: #0288d1;
text-decoration: none;
}
</style> </style>
</head> </head>
@ -204,6 +209,11 @@
<source src="{{.Name}}" type="video/mp4" /> <source src="{{.Name}}" type="video/mp4" />
Your browser does not support the video tag. Your browser does not support the video tag.
</video> </video>
{{else}}
<p>
Couldn't detect file from extension, visit
<a href="http://{{.Path}}">this link</a> to see/download your file.
</p>
{{end}} {{end}}
</div> </div>
<footer>file uploaded in {{.TimeUploaded}}</footer> <footer>file uploaded in {{.TimeUploaded}}</footer>