Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2912: Support folder browsing for static resources #2917

Merged

Conversation

okolesn
Copy link
Collaborator

@okolesn okolesn commented Nov 8, 2022

@okolesn okolesn requested a review from mzueva November 8, 2022 08:31
api/build.gradle Outdated
@@ -249,6 +249,9 @@ dependencies {
compile('io.reflectoring.diffparser:diffparser:1.4')

compile 'dnsjava:dnsjava:3.4.3'

//Template engine
compile group: 'org.freemarker', name: 'freemarker', version: '2.3.23'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please try to use Velocity - we already have in the dependencies, so I'd prefer not to add one more template manager here.


@Service
@RequiredArgsConstructor
public class StaticResourcesService {

private static final String DELIMITER = "/";
private static final String TEMPLATE = "folder.ftlh";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please move the settings (template folder, template name) to SystemPreferences?

@@ -46,7 +68,54 @@ public DataStorageStreamingContent getContent(final String path) {
Assert.isTrue(StringUtils.isNotBlank(filePath),
messageHelper.getMessage(MessageConstants.ERROR_STATIC_RESOURCES_INVALID_PATH));
final AbstractDataStorage storage = dataStorageManager.loadByNameOrId(bucketName);
if (Files.isDirectory(Paths.get(path))) {
final List<AbstractDataStorageItem> items = dataStorageManager.getDataStorageItems(storage.getId(),
path, false, null, null).getResults();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix path -> filePath

final String templateName,
final String staticResourcesPrefix) throws IOException{
final VelocityEngine engine = new VelocityEngine();
engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath);
Copy link
Collaborator

Choose a reason for hiding this comment

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

With this configuration, classpath template is not loaded. We need to support both classpath and filesystem resources. Maybe it is easier to use an approach from SMTPNotificationManager where template is passed as a string to Velocity.evaluate method? In this case we can read template using ResourceUtils class or similar. In this case we can leave only one preference STATIC_RESOURCES_FOLDER_TEMPLATE_PATH with full path to template, e.g. classpath/views/folder.vm or /opt/api/templates/folder.html

@@ -46,7 +68,54 @@ public DataStorageStreamingContent getContent(final String path) {
Assert.isTrue(StringUtils.isNotBlank(filePath),
messageHelper.getMessage(MessageConstants.ERROR_STATIC_RESOURCES_INVALID_PATH));
final AbstractDataStorage storage = dataStorageManager.loadByNameOrId(bucketName);
if (Files.isDirectory(Paths.get(path))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check won't work for cloud resource, I will add a new method to check cloud object type

@mzueva mzueva merged commit 6373eae into develop Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants