File download for attached file assets
parent
8491c01d8b
commit
8871eecea3
|
|
@ -3,7 +3,7 @@
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
<#macro "org.librecms.assets.FileAsset" asset>
|
<#macro "org.librecms.assets.FileAsset" asset>
|
||||||
<h3><a href="${asset.assetPath}">${asset.title}</a></h3>
|
<h3><a href="/content-sections/${asset.contentSection}/files${asset.assetPath}">${asset.title}</a></h3>
|
||||||
<p>${asset.description}</p>
|
<p>${asset.description}</p>
|
||||||
<small>${asset.mimeType} ${asset.size} Bytes</small>
|
<small>${asset.mimeType} ${asset.size} Bytes</small>
|
||||||
<#-- <p><code>A file asset</code></p> -->
|
<#-- <p><code>A file asset</code></p> -->
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import java.util.Optional;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
|
@ -44,7 +45,7 @@ import javax.ws.rs.core.StreamingOutput;
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
@Path("/{content-section}/files")
|
@Path("/{content-section}/files/")
|
||||||
public class Files {
|
public class Files {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(Files.class);
|
private static final Logger LOGGER = LogManager.getLogger(Files.class);
|
||||||
|
|
@ -60,6 +61,7 @@ public class Files {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/uuid-{uuid}")
|
@Path("/uuid-{uuid}")
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Response getFileByUuid(
|
public Response getFileByUuid(
|
||||||
@PathParam("content-section") final String sectionName,
|
@PathParam("content-section") final String sectionName,
|
||||||
@PathParam("uuid") final String uuid
|
@PathParam("uuid") final String uuid
|
||||||
|
|
@ -82,7 +84,9 @@ public class Files {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{path:^(?!uuid).+$}")
|
//@Path("/{path:^(?!uuid).+$}")
|
||||||
|
@Path("/{path:.+}")
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Response getFile(
|
public Response getFile(
|
||||||
@PathParam("content-section") final String sectionName,
|
@PathParam("content-section") final String sectionName,
|
||||||
@PathParam("path") final String path
|
@PathParam("path") final String path
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ package org.librecms.pages.models;
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
import org.librecms.assets.BinaryAsset;
|
import org.librecms.assets.BinaryAsset;
|
||||||
import org.librecms.contentsection.AssetManager;
|
import org.librecms.contentsection.AssetManager;
|
||||||
|
import org.librecms.contentsection.Folder;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
@ -46,6 +47,12 @@ public abstract class AbstractBinaryAssetModelBuilder<T extends BinaryAsset, M e
|
||||||
super.addProperties(asset, model);
|
super.addProperties(asset, model);
|
||||||
model.setAssetPath(assetManager.getAssetPath(asset));
|
model.setAssetPath(assetManager.getAssetPath(asset));
|
||||||
model.setBinaryAssetUuid(asset.getUuid());
|
model.setBinaryAssetUuid(asset.getUuid());
|
||||||
|
model.setContentSection(
|
||||||
|
assetManager
|
||||||
|
.getAssetFolder(asset)
|
||||||
|
.map(folder -> folder.getSection().getDisplayName())
|
||||||
|
.orElse("")
|
||||||
|
);
|
||||||
model.setDescription(
|
model.setDescription(
|
||||||
globalizationHelper.getValueFromLocalizedString(
|
globalizationHelper.getValueFromLocalizedString(
|
||||||
asset.getDescription()
|
asset.getDescription()
|
||||||
|
|
|
||||||
|
|
@ -27,17 +27,19 @@ import org.librecms.assets.BinaryAsset;
|
||||||
public class BinaryAssetModel extends AbstractAssetModel {
|
public class BinaryAssetModel extends AbstractAssetModel {
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
private String mimeType;
|
private String mimeType;
|
||||||
|
|
||||||
private long size;
|
private long size;
|
||||||
|
|
||||||
private String binaryAssetUuid;
|
private String binaryAssetUuid;
|
||||||
|
|
||||||
|
private String contentSection;
|
||||||
|
|
||||||
private String assetPath;
|
private String assetPath;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return BinaryAsset.class.getName();
|
return BinaryAsset.class.getName();
|
||||||
|
|
@ -83,6 +85,14 @@ public class BinaryAssetModel extends AbstractAssetModel {
|
||||||
this.binaryAssetUuid = binaryAssetUuid;
|
this.binaryAssetUuid = binaryAssetUuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getContentSection() {
|
||||||
|
return contentSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentSection(final String contentSection) {
|
||||||
|
this.contentSection = contentSection;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAssetPath() {
|
public String getAssetPath() {
|
||||||
return assetPath;
|
return assetPath;
|
||||||
}
|
}
|
||||||
|
|
@ -90,9 +100,5 @@ public class BinaryAssetModel extends AbstractAssetModel {
|
||||||
public void setAssetPath(final String assetPath) {
|
public void setAssetPath(final String assetPath) {
|
||||||
this.assetPath = assetPath;
|
this.assetPath = assetPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue