Skip to content

Commit

Permalink
Download blobs as UTF strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jk1 committed Jan 13, 2020
1 parent 817f623 commit 735e5a9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ class StoreService {
}
}

@Throws(IOException::class)
fun getBlobString(id: String, blobName: String): String {
val tx = store.beginReadonlyTransaction()
try {
val entity = getEntity(id, tx)
return entity.getBlobString(blobName) ?: throw NotFoundException("there is no blob $blobName")
} finally {
tx.commit()
}
}

private fun Entity.applyValues(property: EntityProperty) {
property.value = safeTrim(property.value)
val value = property.string2value()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import jetbrains.xodus.browser.web.AppRoute
import jetbrains.xodus.browser.web.ChangeSummary
import jetbrains.xodus.browser.web.WebApplication
import mu.KLogging
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.net.URI
import java.nio.charset.StandardCharsets


class Entities(webApp: WebApplication) : AppRoute, ResourceSupport(webApp) {
Expand Down Expand Up @@ -88,6 +93,19 @@ class Entities(webApp: WebApplication) : AppRoute, ResourceSupport(webApp) {
}
}
}
get("/{entityId}/blobString/{blobName}") {
val entityId = call.entityId
val blobName = call.parameters["blobName"] ?: ""
logger.debug { "getting entity by entity id '$entityId'" }
val encodedBlobName = URI(null, null, blobName, null).toASCIIString().replace(",".toRegex(), "%2C")
call.response.headers.append("Content-Disposition", "attachment; filename=$encodedBlobName.txt")
call.respondOutputStream(ContentType.parse("text/plain;charset=utf-8")) {
val blobString = call.storeService.getBlobString(entityId, blobName)
val writer = BufferedWriter(OutputStreamWriter(this, StandardCharsets.UTF_8))
writer.write(blobString)
writer.flush()
}
}
get("/{entityId}/links/{linkName}") {
val entityId = call.entityId
val linkName = call.parameters["linkName"] ?: ""
Expand Down
4 changes: 4 additions & 0 deletions entity-browser-frontend/app/controller/data-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ angular.module('xodus').controller('DataViewController', [
dataViewCtrl.blobLink = function (entity, blob) {
return navigation.api.blobLink(entity.id, blob.name);
};

dataViewCtrl.blobStringLink = function (entity, blob) {
return navigation.api.blobStringLink(entity.id, blob.name);
};
};

function newPager(searchTerm) {
Expand Down
4 changes: 4 additions & 0 deletions entity-browser-frontend/app/controller/form-view/blobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ angular.module('xodus').controller('BlobsController', [
return navigation.api.blobLink($scope.state.current.id, blob.name);
};

$scope.downloadStringLink = function (blob) {
return navigation.api.blobStringLink($scope.state.current.id, blob.name);
};

}]
);
7 changes: 6 additions & 1 deletion entity-browser-frontend/app/service/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ angular.module('xodus').factory('navigationService', [
return 'api/dbs/' + db.uuid + '/entities/' + entityId + "/blob/" + name;
}

function blobStringLink(entityId, name) {
return 'api/dbs/' + db.uuid + '/entities/' + entityId + "/blobString/" + name;
}

function toType(typeId) {
return angular.isDefined(typeId) ? $location.path(prefix).search({typeId: typeId.toString()}) : toType(0);
}
Expand Down Expand Up @@ -40,7 +44,8 @@ angular.module('xodus').factory('navigationService', [
toEntity: toEntity,
forceReload: forceReload,
api: {
blobLink: blobLink
blobLink: blobLink,
blobStringLink: blobStringLink
}
};
};
Expand Down
6 changes: 5 additions & 1 deletion entity-browser-frontend/app/templates/data-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ <h4 class="panel-title pull-left" style="padding-top: 5.5px;">
<td>
<a class="btn btn-default" target="_self"
data-ng-href="{{dataViewCtrl.blobLink(item, p)}}">
<i class="fa fa-download"></i>
<i class="fa fa-download"> Binary</i>
</a>
<a class="btn btn-default" target="_self"
data-ng-href="{{dataViewCtrl.blobStringLink(item, p)}}">
<i class="fa fa-download"> UTF</i>
</a>
</td>
</tr>
Expand Down

2 comments on commit 735e5a9

@cemremengu
Copy link

@cemremengu cemremengu commented on 735e5a9 Nov 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work in v1.3, the functionality is there but the download as UTF button is not there. I am trying it for issue descriptions

@lehvolk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will bump a version then. Thanks.

Please sign in to comment.