|
|
@ -6,6 +6,9 @@ import app.entities.SearchFilter; |
|
|
|
import app.entities.db.DbFile; |
|
|
|
import app.repositories.FilePSRepository; |
|
|
|
import app.repositories.FileRepository; |
|
|
|
import app.services.ProfileService; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.core.io.InputStreamResource; |
|
|
|
import org.springframework.data.domain.Page; |
|
|
@ -26,21 +29,52 @@ import java.time.Instant; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
@RestController |
|
|
|
@RequestMapping("api/files") |
|
|
|
@RequestMapping(FileController.endpoint) |
|
|
|
public class FileController { |
|
|
|
|
|
|
|
public static final String endpoint = "api/file"; |
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private FileRepository fileRepository; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private FilePSRepository filePSRepository; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ProfileService profileService; |
|
|
|
|
|
|
|
@GetMapping("/edit/{uuid}") |
|
|
|
@CheckWebAccess |
|
|
|
@CheckPermitionFlag(flag = "z") |
|
|
|
@CollectStatistic(stage = CollectStages.COMBINED) |
|
|
|
public ResponseEntity<DbFile> getDbFile(@PathVariable String uuid) { |
|
|
|
DbFile dbFile = fileRepository.findById(UUID.fromString(uuid)).orElse(null); |
|
|
|
if (dbFile == null) return ResponseEntity.notFound().build(); |
|
|
|
return ResponseEntity.ok(dbFile); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/edit") |
|
|
|
@CheckWebAccess |
|
|
|
@CheckPermitionFlag(flag = "z") |
|
|
|
@CollectStatistic(stage = CollectStages.COMBINED) |
|
|
|
public ResponseEntity editDbFile(@RequestBody DbFile dbFileEdited) { |
|
|
|
DbFile dbFile = fileRepository.findById(dbFileEdited.getId()).orElse(null); |
|
|
|
if (dbFile == null) return ResponseEntity.notFound().build(); |
|
|
|
dbFile.setTags(dbFileEdited.getTags()); |
|
|
|
fileRepository.save(dbFile); |
|
|
|
return ResponseEntity.ok().build(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping |
|
|
|
@CheckWebAccess |
|
|
|
@CheckPermitionFlag(flag = "z") |
|
|
|
@CollectStatistic(stage = CollectStages.COMBINED) |
|
|
|
public ResponseEntity upload(@CookieValue(value = "steam64") String steam64, |
|
|
|
@RequestParam("file") MultipartFile multipartFile) throws IOException { |
|
|
|
@RequestParam("file") MultipartFile multipartFile, |
|
|
|
@RequestParam(value = "tags", required = false) String tags) throws IOException { |
|
|
|
if (multipartFile.isEmpty() || multipartFile.getSize() == 0L) return ResponseEntity.noContent().build(); |
|
|
|
|
|
|
|
UUID uuid = UUID.randomUUID(); |
|
|
@ -53,6 +87,7 @@ public class FileController { |
|
|
|
dbFile.setData(multipartFile.getBytes()); |
|
|
|
dbFile.setTimestamp(timestamp); |
|
|
|
dbFile.setId(uuid); |
|
|
|
dbFile.setTags(tags); |
|
|
|
fileRepository.save(dbFile); |
|
|
|
return ResponseEntity.ok(uuid.toString()); |
|
|
|
} |
|
|
@ -76,10 +111,23 @@ public class FileController { |
|
|
|
@CheckPermitionFlag(flag = "z") |
|
|
|
@CollectStatistic(stage = CollectStages.COMBINED) |
|
|
|
public Page<DbFile> getFiles(Pageable pageable, @RequestBody(required = false) SearchFilter searchFilter) { |
|
|
|
return filePSRepository.getFiles(pageable); |
|
|
|
String steam64_ids = searchFilter.getAccountsSteam64(profileService); |
|
|
|
|
|
|
|
return filePSRepository.getFiles(pageable, |
|
|
|
steam64_ids.isEmpty(), steam64_ids, |
|
|
|
searchFilter.getBeginUnixTime(), |
|
|
|
searchFilter.getEndUnixTime()); |
|
|
|
} |
|
|
|
|
|
|
|
private static String encodeFileName(String fileName) throws UnsupportedEncodingException { |
|
|
|
return URLEncoder.encode(fileName, StandardCharsets.UTF_8).replace("+", "%20"); |
|
|
|
} |
|
|
|
|
|
|
|
public String getUrl(String tags) { |
|
|
|
logger.info("Search " + tags + " in files"); |
|
|
|
DbFile dbFile = fileRepository.getDbFilesByTag(tags); |
|
|
|
if (dbFile == null) |
|
|
|
throw new RuntimeException("Cannot find: " + tags); |
|
|
|
return endpoint+"/"+dbFile.getId(); |
|
|
|
} |
|
|
|
} |
|
|
|