Skip to content

Commit

Permalink
update naming of export zip file and content files
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorHarbo committed Jul 19, 2023
1 parent 6b5badd commit 9e10e4f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ private static ArcEntry safeGetArcEntry(SolrDocument doc) {
* @return the input arc/warc entry, for further use in a stream.
*/
private ArcEntry addArcEntryToZip(ArcEntry entry, ZipOutputStream zos, String contentType, WarcMetadataFromSolr warcMetadata) {
// TODO: Look at naming from Tokes GH issue: https://github.com/netarchivesuite/solrwayback/issues/382
String filename = createFilename(contentType, warcMetadata);
ZipEntry zipArcEntry = new ZipEntry(filename);

Expand All @@ -109,11 +108,14 @@ private ArcEntry addArcEntryToZip(ArcEntry entry, ZipOutputStream zos, String co

/**
* Create unique filename for zip entries from metadata from solr.
* Files in the zip entry gets named by the following structure: waybackdate_id_originalUrlStrippedForNonASCIIChars.extension.
* @param contentType is used to choose how the filename is created.
* @param warcMetadata contains the timestamp, id and file extension, which is used to create the filename.
* @return a string in the format timestamp_id.extension.
* @param warcMetadata contains the timestamp, id, originalUrl and file extension, which is used to create the filename.
* @return a string in the format timestamp_id_originalUrlStrippedForNonASCIIChars.extension.
*/
private String createFilename(String contentType, WarcMetadataFromSolr warcMetadata) {
// TODO: Look at naming from Tokes GH issue: https://github.com/netarchivesuite/solrwayback/issues/382

String filename;
if (contentType.equals("text/html")){
filename = warcMetadata.getId() + "_" + warcMetadata.getUrl() + ".html";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,27 @@ public Response exportZipContent(@QueryParam("contentType") String contentType,

StreamingOutput zip = Facade.exportZipContent(contentType, query, filters);

String filename = createZipFilename(contentType);

return Response.ok(zip)
.header("Content-Disposition", "attachment; filename=test.zip")
.header("Content-Disposition", "attachment; filename=" + filename)
.build();

}

/**
* Create name for zip file. The name includes information on the exported mimetype and the time for the export.
* @param contentType to create filename from.
* @return the filename in the format datetime_contentType_export.zip
*/
private String createZipFilename(String contentType) {
Date date = new Date() ;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");

return dateFormat.format(date) + "_" + contentType.replaceAll(" ", "")
.replaceAll("/", "_") + "_export.zip";
}


/*
// * This will be called from solrwayback page views, when resources can not be resolved (not harvested)
Expand Down

0 comments on commit 9e10e4f

Please sign in to comment.