Skip to content

Commit 12c1d8a

Browse files
authored
Return folder as part of file metadata (#369)
* path: "/folder-1/folder-2" * when not in folder make sure path has "/" * api.Files jsonfile, adds two fields: downloads, views
1 parent 80528fb commit 12c1d8a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
space level. Make sure to start the application with -DMONGOUPDATE=1. You can also run the [fixCounts.js](https://github.com/clowder-framework/clowder/blob/develop/scripts/updates/fix-counts.js)
1313
script prior to upgrading to minimize the downtime.
1414

15+
### Added
16+
- [#228](https://github.com/clowder-framework/clowder/issues/228) api.Files jsonfile, adds two fields "downloads" and "views"
17+
1518
### Added
1619
- MRI previewer for NIFTY (.nii) files.
1720
- HEIC (.heic) and HEIF (.heif) mimetypes to support new Apple iPhone image file format.

app/api/Files.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,12 @@ class Files @Inject()(
716716
}
717717

718718
def jsonFile(file: File, serverAdmin: Boolean = false): JsValue = {
719+
val foldersContainingFile = folders.findByFileId(file.id)
720+
val allPaths: List[List[String]] = (for (folder <- foldersContainingFile) yield (folderPath(folder, List()).tail))
721+
var path_str = allPaths.map(xl => "/" + xl.map(x => x.toString()).mkString("/")).mkString("")
722+
if(path_str == "") {
723+
path_str = "/"
724+
}
719725
val defaultMap = Map(
720726
"id" -> file.id.toString,
721727
"filename" -> file.filename,
@@ -725,7 +731,11 @@ class Files @Inject()(
725731
"size" -> file.length.toString,
726732
"thumbnail" -> file.thumbnail_id.orNull,
727733
"authorId" -> file.author.id.stringify,
728-
"status" -> file.status)
734+
"status" -> file.status,
735+
"views" -> file.stats.views.toString(),
736+
"downloads" -> file.stats.downloads.toString(),
737+
"path" -> path_str
738+
)
729739

730740
// Only include filepath if using DiskByte storage and user is serverAdmin
731741
val jsonMap = file.loader match {

0 commit comments

Comments
 (0)