diff options
Diffstat (limited to 'juick-www/src/main/java/com/juick/service')
-rw-r--r-- | juick-www/src/main/java/com/juick/service/CloudflareCache.java | 55 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/service/cloudflare/FilesPayload.java | 20 |
2 files changed, 0 insertions, 75 deletions
diff --git a/juick-www/src/main/java/com/juick/service/CloudflareCache.java b/juick-www/src/main/java/com/juick/service/CloudflareCache.java deleted file mode 100644 index 64e048dc..00000000 --- a/juick-www/src/main/java/com/juick/service/CloudflareCache.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.juick.service; - -import com.juick.service.cloudflare.FilesPayload; -import com.juick.User; -import com.juick.server.component.UserUpdatedEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ApplicationListener; -import org.springframework.http.*; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponents; -import org.springframework.web.util.UriComponentsBuilder; - -import java.util.Arrays; - -public class CloudflareCache implements ApplicationListener<UserUpdatedEvent> { - private static final Logger logger = LoggerFactory.getLogger(CloudflareCache.class); - @Value("${cloudflare_auth_email:email@example.com}") - private String authEmail; - @Value("${cloudflare_api_key:secret}") - private String apiKey; - @Value("${cloudflare_zone_id:zoneid}") - private String zoneId; - private final static String baseUri = "https://api.cloudflare.com/client/v4"; - @Override - public void onApplicationEvent(UserUpdatedEvent event) { - User user = event.getUser(); - logger.debug("Purging Cloudflare cache for {} avatar", user.getName()); - UriComponents uriComponents = UriComponentsBuilder.fromUriString("{baseUri}/zones/{zoneId}/purge_cache") - .buildAndExpand(baseUri, zoneId); - HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.add("X-Auth-Email", authEmail); - httpHeaders.add("X-Auth-Key", apiKey); - httpHeaders.setContentType(MediaType.APPLICATION_JSON); - FilesPayload payload = new FilesPayload(); - payload.setFiles(Arrays.asList( - String.format("http://i.juick.com/a/%d.png", user.getUid()), - String.format("http://i.juick.com/as/%d.png", user.getUid()), - String.format("http://i.juick.com/a/%d.jpg", user.getUid()), - String.format("http://i.juick.com/as/%d.jpg", user.getUid()), - String.format("https://i.juick.com/a/%d.png", user.getUid()), - String.format("https://i.juick.com/as/%d.png", user.getUid()), - String.format("https://i.juick.com/a/%d.jpg", user.getUid()), - String.format("https://i.juick.com/as/%d.jpg", user.getUid()) - )); - RestTemplate api = new RestTemplate(); - api.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); - ResponseEntity<String> response = api.exchange(uriComponents.toUri(), - HttpMethod.DELETE, - new HttpEntity<>(payload, httpHeaders), String.class); - logger.info("Cloudflare response: {}", response.getBody()); - } -} diff --git a/juick-www/src/main/java/com/juick/service/cloudflare/FilesPayload.java b/juick-www/src/main/java/com/juick/service/cloudflare/FilesPayload.java deleted file mode 100644 index 35d9e72f..00000000 --- a/juick-www/src/main/java/com/juick/service/cloudflare/FilesPayload.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.juick.service.cloudflare; - -import java.util.ArrayList; -import java.util.List; - -public class FilesPayload { - private List<String> files; - - public FilesPayload() { - files = new ArrayList<>(); - } - - public List<String> getFiles() { - return files; - } - - public void setFiles(List<String> files) { - this.files = files; - } -} |