Skip to content

Commit 2780e23

Browse files
committed
added file preview, updated copyright, added proxy agent for file analyzer
1 parent 07ffea2 commit 2780e23

File tree

13 files changed

+299
-70
lines changed

13 files changed

+299
-70
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"DATABUS_OIDC_REQUIRED_ROLE": "",
5151
"LOOKUP_BASE_URL": "http://localhost:3004",
5252
"MAX_WORKERS": "1",
53-
"METRICS_PORT": "3001"
53+
"METRICS_PORT": "3001",
5454
}
5555
},
5656
{

devenv/package.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

public/dist/main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/components/file-browser/file-browser.html

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@
4040

4141
<!-- Table view tab ng-style="{ 'width' : column.width }" -->
4242
<div ng-if="$ctrl.activeTab == 0">
43-
<table class="table is-fullwidth" >
43+
<table class="table is-fullwidth">
4444
<tr style="cursor:pointer;">
45-
<th ng-repeat='column in $ctrl.config.columns'
46-
ng-click="$ctrl.sortBy(column.field + '.value')">{{ column.label }}</th>
45+
<th ng-repeat='column in $ctrl.config.columns' ng-click="$ctrl.sortBy(column.field + '.value')">{{
46+
column.label }}</th>
4747
<th ng-click="$ctrl.sortBy('size.numericalValue')" style="text-align: right;">Download</th>
4848
</tr>
4949
<tr style="position:relative;"
5050
ng-repeat-start="binding in $ctrl.queryResult.bindings | limitTo:$ctrl.tableLimit | orderBy:$ctrl.sortProperty:$ctrl.sortReverse">
5151

52-
<td ng-repeat='column in $ctrl.config.columns' style="cursor:pointer;"
53-
ng-click="binding.epxanded = !binding.epxanded">
52+
<td ng-repeat="column in $ctrl.config.columns" style="cursor:pointer;"
53+
ng-click="binding.epxanded = !binding.epxanded; $ctrl.loadPreview(binding)">
5454
<div ng-if="$first" style="margin-right:1em; cursor:pointer;"
5555
ng-class="{ right : !binding.epxanded, down : binding.epxanded }" class="arrow"></div>{{
5656
$ctrl.getCellValues(binding, column); }}
@@ -68,8 +68,17 @@
6868
<tr ng-repeat-end ng-if="binding.epxanded">
6969
<td ng-attr-colspan="{{ $ctrl.config.columns.length + 1 }}" style="padding:0; max-width: 0px;">
7070
<div>
71-
<pre ng-if="binding.preview.value != null">{{ binding.preview.value }}</pre>
72-
<pre ng-if="binding.preview.value == null">Preview could not be loaded</pre>
71+
<div ng-if="binding.preview.state == 'loading'">
72+
<pre>Loading preview…</pre>
73+
</div>
74+
75+
<pre ng-if="binding.preview.state == 'success'">
76+
{{ binding.preview.value }}
77+
</pre>
78+
79+
<div ng-if="binding.preview.state == 'error'">
80+
<pre>Preview could not be loaded</pre>
81+
</div>
7382
</div>
7483
</td>
7584
</tr>

public/js/components/file-browser/file-browser.js

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const DatabusConstants = require("../../utils/databus-constants");
22
const DatabusUtils = require("../../utils/databus-utils");
3-
43
// hinzufügen eines Controllers zum Modul
54
function FileBrowserController($http, $scope) {
65

@@ -10,7 +9,7 @@ function FileBrowserController($http, $scope) {
109
ctrl.activeTab = 0;
1110
ctrl.$scope = $scope;
1211

13-
ctrl.$onInit = function() {
12+
ctrl.$onInit = function () {
1413

1514
ctrl.lastRequestRevision = 0;
1615
ctrl.tableLimit = 20;
@@ -20,24 +19,56 @@ function FileBrowserController($http, $scope) {
2019
ctrl.queryResult = {};
2120
}
2221

23-
ctrl.sortBy = function(property) {
22+
ctrl.loadPreview = async function (binding) {
23+
binding.preview = { state: 'loading', value: null };
24+
25+
try {
26+
const params = new URLSearchParams({
27+
url: binding.file.value,
28+
compression: binding.compression?.value || ''
29+
});
30+
31+
const res = await fetch('/app/file/preview?' + params.toString(), {
32+
credentials: 'same-origin'
33+
});
34+
35+
if (!res.ok) throw new Error('Network error');
36+
37+
const data = await res.json();
38+
if (data.preview != null) {
39+
binding.preview.state = 'success';
40+
binding.preview.value = data.preview;
41+
} else {
42+
binding.preview.state = 'error';
43+
binding.preview.value = 'Preview could not be loaded';
44+
}
45+
46+
} catch (e) {
47+
binding.preview.state = 'error';
48+
binding.preview.value = 'Preview could not be loaded';
49+
}
50+
51+
if (!ctrl.$scope.$root.$$phase) ctrl.$scope.$apply();
52+
};
53+
54+
ctrl.sortBy = function (property) {
2455

2556

26-
if(ctrl.sortProperty == property) {
57+
if (ctrl.sortProperty == property) {
2758
ctrl.sortReverse = !ctrl.sortReverse;
2859
}
2960
ctrl.sortProperty = property;
3061
}
3162

32-
ctrl.getCellValues = function(binding, column) {
63+
ctrl.getCellValues = function (binding, column) {
3364

34-
if(binding[column.field] == undefined) {
65+
if (binding[column.field] == undefined) {
3566
return "";
3667
}
37-
68+
3869
var value = binding[column.field].value;
3970

40-
if(column.uriToName) {
71+
if (column.uriToName) {
4172
value = DatabusUtils.uriToName(value);
4273
}
4374

@@ -46,32 +77,32 @@ function FileBrowserController($http, $scope) {
4677

4778
}
4879

49-
ctrl.formatUploadSize = function(size) {
80+
ctrl.formatUploadSize = function (size) {
5081
return DatabusUtils.formatFileSize(size);
5182
};
5283

53-
ctrl.createRelativeUri = function(url) {
84+
ctrl.createRelativeUri = function (url) {
5485
var u = new URL(url);
5586
return u.pathname;
5687
}
5788

58-
ctrl.formatVariant = function(value) {
89+
ctrl.formatVariant = function (value) {
5990
var variants = value.split(', ');
6091
value = "";
61-
for(variant of variants) {
62-
if(variant != undefined && variant != "") {
92+
for (variant of variants) {
93+
if (variant != undefined && variant != "") {
6394
value += variant + ", ";
6495
}
6596
}
6697

67-
if(value == "") {
98+
if (value == "") {
6899
return "none";
69100
}
70101

71102
return value.substr(0, value.length - 2);
72103
}
73104

74-
ctrl.querySparql = async function(query) {
105+
ctrl.querySparql = async function (query) {
75106

76107
ctrl.isLoading = true;
77108
ctrl.totalSize = 0;
@@ -84,11 +115,11 @@ function FileBrowserController($http, $scope) {
84115
url: DatabusConstants.DATABUS_SPARQL_ENDPOINT_URL,
85116
data: "format=json&query=" + encodeURIComponent(query),
86117
headers: {
87-
"Content-type" : "application/x-www-form-urlencoded"
118+
"Content-type": "application/x-www-form-urlencoded"
88119
},
89120
}
90121

91-
var updateResponse = await ctrl.$http(req);
122+
var updateResponse = await ctrl.$http(req);
92123

93124
var data = updateResponse.data;
94125

@@ -99,29 +130,29 @@ function FileBrowserController($http, $scope) {
99130

100131
ctrl.queryResult.uriList = "";
101132

102-
for(var b in ctrl.queryResult.bindings) {
133+
for (var b in ctrl.queryResult.bindings) {
103134
var binding = ctrl.queryResult.bindings[b];
104135
binding.size.numericalValue = parseInt(binding.size.value);
105136
ctrl.queryResult.uriList += binding.file.value + "\n";
106137

107-
if(binding.variant != undefined) {
108-
binding.variant.value = ctrl.formatVariant(binding.variant.value);
138+
if (binding.variant != undefined) {
139+
binding.variant.value = ctrl.formatVariant(binding.variant.value);
109140
}
110-
111-
141+
142+
112143

113144

114145
ctrl.totalSize += binding.size.numericalValue;
115146
ctrl.numFiles++;
116147
}
117148

118149
ctrl.totalSize = ctrl.formatUploadSize(ctrl.totalSize);
119-
120-
if(!$scope.$root.$$phase) {
150+
151+
if (!$scope.$root.$$phase) {
121152
ctrl.$scope.$apply();
122153
}
123154

124-
} catch(e) {
155+
} catch (e) {
125156
console.log(e);
126157
}
127158
}
@@ -131,13 +162,22 @@ function FileBrowserController($http, $scope) {
131162
* using the query builders
132163
* @return {[type]} [description]
133164
*/
134-
ctrl.$doCheck = function() {
165+
ctrl.$doCheck = function () {
135166

136-
if(ctrl.query != ctrl.fileQuery) {
167+
if (ctrl.query != ctrl.fileQuery) {
137168
ctrl.fileQuery = ctrl.query;
138169
ctrl.querySparql(ctrl.fullQuery);
139170
}
140171
}
172+
173+
function decodeBz2(uint8array) {
174+
try {
175+
const decompressed = decompress(uint8array);
176+
return new TextDecoder().decode(decompressed);
177+
} catch (e) {
178+
return null;
179+
}
180+
}
141181
}
142182

143183

public/js/publish/version-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class VersionHandler extends EntityHandler {
9393
this.errors.push('err_no_artifact_selected');
9494
}
9595

96-
if (!DatabusUtils.isValidResourceLabel(this.title)) {
96+
if (!DatabusUtils.isValidResourceLabel(this.title, 1)) {
9797
this.errors.push('err_invalid_version_title');
9898
}
9999

public/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
"bulma-extensions": "^6.2.7",
2020
"bulma-steps": "^2.2.1",
2121
"bulma-timeline": "^3.0.4",
22+
"bz2": "^1.0.1",
2223
"check-licenses": "^1.0.6",
2324
"codemirror": "^5.63.0",
25+
"compressjs": "^1.0.3",
2426
"jquery": "^3.6.0",
2527
"js-sha256": "^0.9.0",
2628
"jstable-editor": "^3.15.45",
2729
"markdown-it": ">=12.3.2",
2830
"moment": "^2.24.0",
31+
"pako": "^2.1.0",
2932
"sass": "^1.22.9",
33+
"seek-bzip": "^2.0.0",
3034
"stream-file": "^0.2.4",
3135
"yasgui-yasqe": "^2.11.22"
3236
},

public/templates/footer.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<h2 style="color:white;">DBpedia</h2>
88

99
<p><i>Global and Unified Access to Knowledge Graphs</i> <br/>
10-
© Copyright 2023&nbsp;by DBpedia. All Rights Reserved.</p>
10+
© Copyright 2025&nbsp;by DBpedia. All Rights Reserved.</p>
1111
<a class="has-text-white" href="/imprint">Imprint</a>
1212
| <a target="_blank" class="has-text-white" href="https://github.com/dbpedia/databus/issues?q=is%253Aissue+is%253Aopen">Report Issue</a>
1313
| <a target="_blank" class="has-text-white" href="http://dev.dbpedia.org/Download_Data">Download Data</a>

0 commit comments

Comments
 (0)