Added download-info
- Cleared some imports - Added setting for database-clear on startup
This commit is contained in:
parent
cd9a800bf0
commit
36d085bfbc
@ -15,6 +15,18 @@
|
|||||||
<i class="fas fa-cloud-download-alt mr-2"></i>
|
<i class="fas fa-cloud-download-alt mr-2"></i>
|
||||||
Download
|
Download
|
||||||
</button>
|
</button>
|
||||||
<p class="text-gray-600 text-center w-2/3">Files are available for a limited time. Ensure the code or link is correct.</p>
|
<p class="text-gray-600 text-center w-2/3">Files are available for a limited time. Ensure the code or link is correct and the file is still downloadable.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<dialog #password_modal class="modal">
|
||||||
|
<div class="modal-box">
|
||||||
|
<h3 class="font-bold text-lg">Please enter the file password</h3>
|
||||||
|
<p class="py-4">Please enter the download password:</p>
|
||||||
|
<input type="password" placeholder="Password..." class="input input-bordered w-full max-w-xs" />
|
||||||
|
<div class="modal-action">
|
||||||
|
<form method="dialog">
|
||||||
|
<button class="btn">Cancel download</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
@ -3,18 +3,13 @@ package de.w665.sharepulse.db;
|
|||||||
import com.rethinkdb.RethinkDB;
|
import com.rethinkdb.RethinkDB;
|
||||||
import com.rethinkdb.gen.exc.ReqlOpFailedError;
|
import com.rethinkdb.gen.exc.ReqlOpFailedError;
|
||||||
import com.rethinkdb.net.Connection;
|
import com.rethinkdb.net.Connection;
|
||||||
import com.rethinkdb.net.Result;
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.annotation.PreDestroy;
|
import jakarta.annotation.PreDestroy;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class RethinkDBService {
|
public class RethinkDBService {
|
||||||
@ -24,6 +19,9 @@ public class RethinkDBService {
|
|||||||
private final RethinkDB r;
|
private final RethinkDB r;
|
||||||
private final Connection connection;
|
private final Connection connection;
|
||||||
|
|
||||||
|
@Value("${sharepulse.auto-reset-on-startup}")
|
||||||
|
private boolean autoResetOnStartup;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public RethinkDBService(RethinkDBConfig config, RethinkDBConnector connector) {
|
public RethinkDBService(RethinkDBConfig config, RethinkDBConnector connector) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@ -66,9 +64,12 @@ public class RethinkDBService {
|
|||||||
r.db(config.getDatabase()).tableCreate("file_uploads").run(connection).stream();
|
r.db(config.getDatabase()).tableCreate("file_uploads").run(connection).stream();
|
||||||
log.debug("Table 'file_uploads' created successfully.");
|
log.debug("Table 'file_uploads' created successfully.");
|
||||||
} catch (ReqlOpFailedError e) {
|
} catch (ReqlOpFailedError e) {
|
||||||
log.debug("Table 'file_uploads' already exists. Clearing content...");
|
log.debug("Table 'file_uploads' already exists.");
|
||||||
r.db(config.getDatabase()).table("file_uploads").delete().run(connection);
|
if(autoResetOnStartup) {
|
||||||
log.debug("Table 'file_uploads' cleared successfully.");
|
log.debug("Clearing content...");
|
||||||
|
r.db(config.getDatabase()).table("file_uploads").delete().run(connection);
|
||||||
|
log.debug("Table 'file_uploads' cleared successfully.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rethinkdb check if table id_store exists
|
// rethinkdb check if table id_store exists
|
||||||
|
@ -8,7 +8,6 @@ import de.w665.sharepulse.service.FileService;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -71,4 +70,16 @@ public class Download extends ApiRestController {
|
|||||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
.body(resource);
|
.body(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/download-info")
|
||||||
|
public ResponseEntity<Object> getDownloadInfo(@RequestParam String fileId) {
|
||||||
|
FileUpload fileUpload = fileService.getFileUploadByFileId(fileId);
|
||||||
|
|
||||||
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
response.put("fileId", fileUpload.getFileId());
|
||||||
|
response.put("passwordProtected", fileUpload.isPasswordProtected());
|
||||||
|
response.put("singleDownload", fileUpload.isSingleDownload());
|
||||||
|
|
||||||
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
@ -29,6 +29,9 @@ public class FileService {
|
|||||||
@Value("${sharepulse.temp-filestore-path}")
|
@Value("${sharepulse.temp-filestore-path}")
|
||||||
private String tempDirPath;
|
private String tempDirPath;
|
||||||
|
|
||||||
|
@Value("${sharepulse.auto-reset-on-startup}")
|
||||||
|
private boolean autoResetOnStartup;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public FileService(FileIdService fileIdService, FileSecurityService fileSecurityService, FileUploadRepository fileUploadRepository) {
|
public FileService(FileIdService fileIdService, FileSecurityService fileSecurityService, FileUploadRepository fileUploadRepository) {
|
||||||
this.fileIdService = fileIdService;
|
this.fileIdService = fileIdService;
|
||||||
@ -45,9 +48,13 @@ public class FileService {
|
|||||||
Files.createDirectory(path);
|
Files.createDirectory(path);
|
||||||
log.debug("Directory created");
|
log.debug("Directory created");
|
||||||
} else {
|
} else {
|
||||||
log.debug("Directory already exists. Clearing content.");
|
log.debug("Directory already exists.");
|
||||||
FileUtils.cleanDirectory(new File(getTempDirPath()));
|
if(autoResetOnStartup) {
|
||||||
log.debug("Directory content cleared.");
|
log.debug("Clearing content...");
|
||||||
|
FileUtils.cleanDirectory(new File(getTempDirPath()));
|
||||||
|
log.debug("Directory content cleared.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
sharepulse.temp-filestore-path=/temp-filestore
|
sharepulse.temp-filestore-path=/temp-filestore
|
||||||
sharepulse.filepassword-length=6
|
sharepulse.filepassword-length=6
|
||||||
sharepulse.filepassword-charset=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
|
sharepulse.filepassword-charset=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
|
||||||
|
sharepulse.auto-reset-on-startup=false
|
||||||
|
|
||||||
# Static path
|
# Static path
|
||||||
spring.web.resources.static-locations=classpath:/static/browser/
|
spring.web.resources.static-locations=classpath:/static/browser/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user