controller: delete avatars older than a month and get a fresh one
This commit is contained in:
parent
48547e0932
commit
f2a93d1986
|
@ -820,17 +820,26 @@ namespace SparkleShare {
|
||||||
string avatar_path = SparkleHelpers.CombineMore (SparklePaths.SparkleLocalIconPath,
|
string avatar_path = SparkleHelpers.CombineMore (SparklePaths.SparkleLocalIconPath,
|
||||||
size + "x" + size, "status");
|
size + "x" + size, "status");
|
||||||
|
|
||||||
if (!Directory.Exists (avatar_path)) {
|
string avatar_file_path = Path.Combine (avatar_path, "avatar-" + email);
|
||||||
Directory.CreateDirectory (avatar_path);
|
|
||||||
SparkleHelpers.DebugInfo ("Config", "Created '" + avatar_path + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
string avatar_file_path = SparkleHelpers.CombineMore (avatar_path, "avatar-" + email);
|
|
||||||
|
|
||||||
if (File.Exists (avatar_file_path)) {
|
if (File.Exists (avatar_file_path)) {
|
||||||
return avatar_file_path;
|
FileInfo avatar_info = new FileInfo (avatar_file_path);
|
||||||
|
|
||||||
|
// Delete avatars older than a month and get a new one
|
||||||
|
if (avatar_info.CreationTime < DateTime.Now.AddMonths (-1)) {
|
||||||
|
avatar_info.Delete ();
|
||||||
|
return GetAvatar (email, size);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return avatar_file_path;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
if (!Directory.Exists (avatar_path)) {
|
||||||
|
Directory.CreateDirectory (avatar_path);
|
||||||
|
SparkleHelpers.DebugInfo ("Config", "Created '" + avatar_path + "'");
|
||||||
|
}
|
||||||
|
|
||||||
// Let's try to get the person's gravatar for next time
|
// Let's try to get the person's gravatar for next time
|
||||||
WebClient web_client = new WebClient ();
|
WebClient web_client = new WebClient ();
|
||||||
Uri uri = new Uri ("https://secure.gravatar.com/avatar/" + GetMD5 (email) +
|
Uri uri = new Uri ("https://secure.gravatar.com/avatar/" + GetMD5 (email) +
|
||||||
|
@ -850,6 +859,8 @@ namespace SparkleShare {
|
||||||
if (tmp_file_info.Length > 255)
|
if (tmp_file_info.Length > 255)
|
||||||
File.Move (tmp_file_path, avatar_file_path);
|
File.Move (tmp_file_path, avatar_file_path);
|
||||||
|
|
||||||
|
SparkleHelpers.DebugInfo ("Controller", "Fetched gravatar: " + email);
|
||||||
|
|
||||||
if (AvatarFetched != null)
|
if (AvatarFetched != null)
|
||||||
AvatarFetched ();
|
AvatarFetched ();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue