feat: improve support for binary & audio files

This commit is contained in:
tdurieux
2024-04-28 10:01:40 +01:00
parent 72c8f80bce
commit 3a00a27153
4 changed files with 28 additions and 7 deletions

View File

@@ -6,8 +6,10 @@
<div class="h-100 overflow-auto" ng-if="type == 'pdf'">
<pdfviewer class="h-100 overflow-auto" src="{{url}}" id="viewer"></pdfviewer>
</div>
<div ng-if="type == 'audio'"><audio controls="controls"><source src="{{url}}" /></audio></div>
<div ng-if="type == 'IPython'"><notebook file="url"></notebook></div>
<div ng-if="type == 'error'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto" translate="ERRORS.{{content}}">Error</h1></div></div>
<div ng-if="type == 'loading' && !error" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Loading...</h1></div></div>
<div ng-if="type == 'empty'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Empty repository!</h1></div>
<div ng-if="content == null && type != 'empty'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Empty file!</h1></div>
<div ng-if="content == null && type != 'empty'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Empty file!</h1></div>
<div ng-if="type == 'binary'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Unsupported binary file. You can download the file: <a target="_blank" ng-href="{{url}}&download=true">here</a>.</h1></div>

View File

@@ -1511,16 +1511,24 @@ angular
"heif",
"heic",
];
const audioFiles = ["wav", "mp3", "ogg", "wma", "flac", "aac", "m4a"];
const mediaFiles = [
"wav",
"mp3",
"ogg",
"mp4",
"avi",
"webm",
"mov",
"mpg",
"wma",
"mpeg",
"mkv",
"flv",
"wmv",
"3gp",
"3g2",
"m4v",
"f4v",
"f4p",
"f4a",
"f4b",
];
$scope.$on("$routeUpdate", function (event, current) {
@@ -1647,6 +1655,9 @@ angular
if (mediaFiles.indexOf(extension) > -1) {
return "media";
}
if (audioFiles.indexOf(extension) > -1) {
return "audio";
}
return "code";
}
@@ -1693,6 +1704,13 @@ angular
$scope.content = $sce.trustAsHtml(orgHTMLDocument.toString());
$scope.type = "html";
}
if (
$scope.type == "code" &&
res.headers("content-type") == "application/octet-stream"
) {
$scope.type = "binary";
$scope.content = "binary";
}
setTimeout(() => {
Prism.highlightAll();
}, 50);
@@ -1844,7 +1862,6 @@ angular
$scope.type = "empty";
$scope.$apply();
} else {
$scope.$apply(() => {
selectFile();
updateContent();

File diff suppressed because one or more lines are too long

View File

@@ -41,6 +41,8 @@ router.post("/", async (req: express.Request, res: express.Response) => {
anonymizer.once("transform", (data) => {
if (!mime && data.isText) {
res.contentType("text/plain");
} else if (!mime && !data.isText) {
res.contentType("application/octet-stream");
}
});
function handleStreamError(error: Error) {