|
|
@ -1,5 +1,6 @@ |
|
|
|
package app.updates; |
|
|
|
|
|
|
|
import app.controllers.FileController; |
|
|
|
import app.entities.Stats; |
|
|
|
import app.entities.server.Server; |
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
@ -24,12 +25,14 @@ public class PreviewUpdater extends BaseUpdater{ |
|
|
|
//@Value("${backend.updates.a2s}")
|
|
|
|
private boolean update = true; |
|
|
|
private HashMap<String, String> preview_cache; |
|
|
|
private FileController fileController; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
public PreviewUpdater(Stats stats) { |
|
|
|
public PreviewUpdater(Stats stats, FileController fileController) { |
|
|
|
this.stats = stats; |
|
|
|
restTemplate = new RestTemplate(); |
|
|
|
preview_cache = new HashMap(); |
|
|
|
this.fileController = fileController; |
|
|
|
} |
|
|
|
|
|
|
|
@PostConstruct |
|
|
@ -68,6 +71,10 @@ public class PreviewUpdater extends BaseUpdater{ |
|
|
|
|
|
|
|
public String getPreview(String map) { |
|
|
|
String url; |
|
|
|
//Check dbfile
|
|
|
|
try { |
|
|
|
url = fileController.getUrlWithNameAndTag(map, "map"); |
|
|
|
} catch (Exception ignored) {} |
|
|
|
|
|
|
|
//Check jpg
|
|
|
|
url = preview.formatted(domain, map, "jpg"); |
|
|
@ -75,19 +82,19 @@ public class PreviewUpdater extends BaseUpdater{ |
|
|
|
logger.info("Request: {}", url); |
|
|
|
restTemplate.headForHeaders(url); |
|
|
|
return url; |
|
|
|
} catch (RestClientException err) {} |
|
|
|
} catch (RestClientException ignored) {} |
|
|
|
|
|
|
|
//Check txt contained url
|
|
|
|
url = preview.formatted(domain, map, "url"); |
|
|
|
try { |
|
|
|
logger.info("Request: {}", url); |
|
|
|
return restTemplate.getForEntity(url, String.class).getBody().replace("\n", ""); |
|
|
|
} catch (RestClientException err) {} |
|
|
|
} catch (RestClientException ignored) {} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public String not_found() { |
|
|
|
return preview.formatted(domain, "_default", "jpg"); |
|
|
|
return fileController.getUrlWithNameAndTag("_default", "map"); |
|
|
|
} |
|
|
|
} |
|
|
|