mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +00:00
@@ -20,6 +20,7 @@ import java.net.URISyntaxException;
|
|||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The core of parabot
|
* The core of parabot
|
||||||
@@ -206,30 +207,19 @@ public class Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the cache and removes the cache contents if required
|
* Method that removes the cache contents after 3 days
|
||||||
*/
|
*/
|
||||||
private static void validateCache() {
|
private static void validateCache() {
|
||||||
File[] cache = Directories.getCachePath().listFiles();
|
File[] cache = Directories.getCachePath().listFiles();
|
||||||
Integer lowest = null;
|
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
for (File f : cache) {
|
for (File f : cache) {
|
||||||
int date = (int) (f.lastModified() / 1000);
|
long age = new Date().getTime() - f.lastModified();
|
||||||
if (lowest == null || date < lowest) {
|
|
||||||
lowest = date;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
if (age > 3 * 24 * 60 * 60 * 1000) {
|
||||||
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(WebUtil.getContents("http://bdn.parabot.org/api/v2/bot/cache", "date=" + lowest));
|
f.delete();
|
||||||
if ((boolean) object.get("result")) {
|
}
|
||||||
Core.verbose("Making space for the latest cache files");
|
|
||||||
Directories.clearCache();
|
|
||||||
} else {
|
|
||||||
Core.verbose("Cache is up to date");
|
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException | ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user