mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 16:01:16 +01:00
make sure file exists before considering redownload, fix #48
This commit is contained in:
parent
8ef7bd5937
commit
3d1ad616bf
@ -24,48 +24,59 @@ function store_images(uuid, details, callback) {
|
|||||||
} else {
|
} else {
|
||||||
if (skin_url) {
|
if (skin_url) {
|
||||||
logging.log(uuid + " " + skin_url);
|
logging.log(uuid + " " + skin_url);
|
||||||
// set file paths
|
|
||||||
var hash = get_hash(skin_url);
|
var hash = get_hash(skin_url);
|
||||||
if (details && details.hash == hash) {
|
// set file paths
|
||||||
// hash hasn't changed
|
var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
|
||||||
logging.log(uuid + " hash has not changed");
|
var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png";
|
||||||
cache.update_timestamp(uuid, hash);
|
|
||||||
callback(null, hash);
|
|
||||||
} else {
|
|
||||||
// hash has changed
|
|
||||||
logging.log(uuid + " new hash: " + hash);
|
|
||||||
var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
|
|
||||||
var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png";
|
|
||||||
|
|
||||||
if (fs.existsSync(facepath)) {
|
// make sure the file is still there
|
||||||
logging.log(uuid + " Avatar already exists, not downloading");
|
fs.exists(facepath, function(err, face_exists) {
|
||||||
cache.save_hash(uuid, hash);
|
if (err) {
|
||||||
|
logging.error(uuid + "error: " + err);
|
||||||
|
}
|
||||||
|
var exists = !err && face_exists;
|
||||||
|
|
||||||
|
if (exists && details && details.hash == hash) {
|
||||||
|
logging.log(uuid + " hash has not changed");
|
||||||
|
cache.update_timestamp(uuid, hash);
|
||||||
callback(null, hash);
|
callback(null, hash);
|
||||||
} else {
|
} else {
|
||||||
// download skin
|
if (!exists) {
|
||||||
networking.get_skin(skin_url, function(err, img) {
|
logging.warn(uuid + " File was deleted! Downloading again.");
|
||||||
if (err || !img) {
|
} else {
|
||||||
callback(err, null);
|
// hash has changed
|
||||||
} else {
|
logging.log(uuid + " new hash: " + hash);
|
||||||
// extract face / helm
|
}
|
||||||
skins.extract_face(img, facepath, function(err) {
|
if (exists) {
|
||||||
if (err) {
|
logging.log(uuid + " Avatar already exists, not downloading");
|
||||||
callback(err);
|
cache.save_hash(uuid, hash);
|
||||||
} else {
|
callback(null, hash);
|
||||||
logging.log(uuid + " face extracted");
|
} else {
|
||||||
logging.debug(facepath);
|
// download skin
|
||||||
skins.extract_helm(facepath, img, helmpath, function(err) {
|
networking.get_skin(skin_url, function(err, img) {
|
||||||
logging.log(uuid + " helm extracted");
|
if (err || !img) {
|
||||||
logging.debug(helmpath);
|
callback(err, null);
|
||||||
cache.save_hash(uuid, hash);
|
} else {
|
||||||
callback(err, hash);
|
// extract face / helm
|
||||||
});
|
skins.extract_face(img, facepath, function(err) {
|
||||||
}
|
if (err) {
|
||||||
});
|
callback(err);
|
||||||
}
|
} else {
|
||||||
});
|
logging.log(uuid + " face extracted");
|
||||||
|
logging.debug(facepath);
|
||||||
|
skins.extract_helm(facepath, img, helmpath, function(err) {
|
||||||
|
logging.log(uuid + " helm extracted");
|
||||||
|
logging.debug(helmpath);
|
||||||
|
cache.save_hash(uuid, hash);
|
||||||
|
callback(err, hash);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
} else {
|
} else {
|
||||||
// profile found, but has no skin
|
// profile found, but has no skin
|
||||||
cache.save_hash(uuid, null);
|
cache.save_hash(uuid, null);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user