Browse Source

When serving a website, delete the unzipped directory if the index file is not found.

This is a quick solution to rebuild directory structures with missing files. This whole area of the code needs some reworking, as serving the site from a temporary folder is not a robust long term solution.
qdn
CalDescent 3 years ago
parent
commit
5a95c827b4
  1. 5
      pom.xml
  2. 14
      src/main/java/org/qortal/api/resource/WebsiteResource.java

5
pom.xml

@ -450,6 +450,11 @@
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!-- For bitset/bitmap compression -->
<dependency>
<groupId>io.druid</groupId>

14
src/main/java/org/qortal/api/resource/WebsiteResource.java

@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.qortal.api.ApiError;
@ -355,8 +356,19 @@ public class WebsiteResource {
inputStream.close();
}
return response;
} catch (FileNotFoundException e) {
LOGGER.info("File not found at path: {}", unzippedPath);
if (inPath.equals("/")) {
// Delete the unzipped folder if no index file was found
try {
FileUtils.deleteDirectory(new File(unzippedPath));
} catch (IOException ioException) {
LOGGER.info("Unable to delete directory: {}", unzippedPath, e);
}
}
} catch (IOException e) {
LOGGER.info("Unable to serve file at path: {}", inPath);
LOGGER.info("Unable to serve file at path: {}", inPath, e);
}
return this.get404Response();

Loading…
Cancel
Save