mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-23 04:36:50 +00:00
Added custom validation for websites.
A website must contain one of the following files in its root directory to be considered valid: index.html index.htm default.html default.htm home.html home.htm This is the first page that is loaded when loading a Qortal-hosted website.
This commit is contained in:
@@ -134,7 +134,7 @@ public class ArbitraryDataRenderer {
|
||||
private String getFilename(String directory, String userPath) {
|
||||
if (userPath == null || userPath.endsWith("/") || userPath.equals("")) {
|
||||
// Locate index file
|
||||
List<String> indexFiles = this.indexFiles();
|
||||
List<String> indexFiles = ArbitraryDataRenderer.indexFiles();
|
||||
for (String indexFile : indexFiles) {
|
||||
String filePath = directory + File.separator + indexFile;
|
||||
if (Files.exists(Paths.get(filePath))) {
|
||||
@@ -173,7 +173,7 @@ public class ArbitraryDataRenderer {
|
||||
return response;
|
||||
}
|
||||
|
||||
private List<String> indexFiles() {
|
||||
public static List<String> indexFiles() {
|
||||
List<String> indexFiles = new ArrayList<>();
|
||||
indexFiles.add("index.html");
|
||||
indexFiles.add("index.htm");
|
||||
|
@@ -18,7 +18,23 @@ import static java.util.stream.Collectors.toMap;
|
||||
public enum Service {
|
||||
AUTO_UPDATE(1, false, null, null),
|
||||
ARBITRARY_DATA(100, false, null, null),
|
||||
WEBSITE(200, false, null, null),
|
||||
WEBSITE(200, true, null, null) {
|
||||
@Override
|
||||
public ValidationResult validate(Path path) {
|
||||
// Custom validation function to require an index HTML file in the root directory
|
||||
List<String> fileNames = ArbitraryDataRenderer.indexFiles();
|
||||
String[] files = path.toFile().list();
|
||||
if (files != null) {
|
||||
for (String file : files) {
|
||||
Path fileName = Paths.get(file).getFileName();
|
||||
if (fileName != null && fileNames.contains(fileName.toString())) {
|
||||
return ValidationResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ValidationResult.MISSING_INDEX_FILE;
|
||||
}
|
||||
},
|
||||
GIT_REPOSITORY(300, false, null, null),
|
||||
IMAGE(400, true, 10*1024*1024L, null),
|
||||
THUMBNAIL(410, true, 500*1024L, null),
|
||||
|
Reference in New Issue
Block a user