mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 21:43:24 -07:00
Made the supported image formats extendable, and supplied a SVG implementation right away with the jira addon.
This commit is contained in:
parent
9bf9c0e4e6
commit
fc192827f1
21 changed files with 1354 additions and 676 deletions
|
@ -32,7 +32,7 @@ namespace GreenshotImgurPlugin {
|
|||
/// Description of ImgurUtils.
|
||||
/// </summary>
|
||||
public static class ImgurUtils {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImgurUtils));
|
||||
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(ImgurUtils));
|
||||
private const string SmallUrlPattern = "http://i.imgur.com/{0}s.jpg";
|
||||
private static readonly ImgurConfiguration Config = IniConfig.GetIniSection<ImgurConfiguration>();
|
||||
private const string AuthUrlPattern = "https://api.imgur.com/oauth2/authorize?response_type=code&client_id={ClientId}&redirect_uri={RedirectUrl}&state={State}";
|
||||
|
@ -64,7 +64,7 @@ namespace GreenshotImgurPlugin {
|
|||
RetrieveImgurThumbnail(imgurInfo);
|
||||
Config.runtimeImgurHistory.Add(hash, imgurInfo);
|
||||
} else {
|
||||
LOG.DebugFormat("Deleting not found ImgUr {0} from config.", hash);
|
||||
Log.DebugFormat("Deleting not found ImgUr {0} from config.", hash);
|
||||
Config.ImgurUploadHistory.Remove(hash);
|
||||
saveNeeded = true;
|
||||
}
|
||||
|
@ -74,16 +74,16 @@ namespace GreenshotImgurPlugin {
|
|||
HttpWebResponse response = ((HttpWebResponse)wE.Response);
|
||||
// Image no longer available
|
||||
if (response.StatusCode == HttpStatusCode.Redirect) {
|
||||
LOG.InfoFormat("ImgUr image for hash {0} is no longer available", hash);
|
||||
Log.InfoFormat("ImgUr image for hash {0} is no longer available", hash);
|
||||
Config.ImgurUploadHistory.Remove(hash);
|
||||
redirected = true;
|
||||
}
|
||||
}
|
||||
if (!redirected) {
|
||||
LOG.Error("Problem loading ImgUr history for hash " + hash, wE);
|
||||
Log.Error("Problem loading ImgUr history for hash " + hash, wE);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.Error("Problem loading ImgUr history for hash " + hash, e);
|
||||
Log.Error("Problem loading ImgUr history for hash " + hash, e);
|
||||
}
|
||||
}
|
||||
if (saveNeeded) {
|
||||
|
@ -146,7 +146,7 @@ namespace GreenshotImgurPlugin {
|
|||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("Upload to imgur gave an exeption: ", ex);
|
||||
Log.Error("Upload to imgur gave an exeption: ", ex);
|
||||
throw;
|
||||
}
|
||||
} else {
|
||||
|
@ -200,10 +200,10 @@ namespace GreenshotImgurPlugin {
|
|||
/// <param name="imgurInfo"></param>
|
||||
public static void RetrieveImgurThumbnail(ImgurInfo imgurInfo) {
|
||||
if (imgurInfo.SmallSquare == null) {
|
||||
LOG.Warn("Imgur URL was null, not retrieving thumbnail.");
|
||||
Log.Warn("Imgur URL was null, not retrieving thumbnail.");
|
||||
return;
|
||||
}
|
||||
LOG.InfoFormat("Retrieving Imgur image for {0} with url {1}", imgurInfo.Hash, imgurInfo.SmallSquare);
|
||||
Log.InfoFormat("Retrieving Imgur image for {0} with url {1}", imgurInfo.Hash, imgurInfo.SmallSquare);
|
||||
HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(string.Format(SmallUrlPattern, imgurInfo.Hash), HTTPMethod.GET);
|
||||
webRequest.ServicePoint.Expect100Continue = false;
|
||||
// Not for getting the thumbnail, in anonymous modus
|
||||
|
@ -213,7 +213,7 @@ namespace GreenshotImgurPlugin {
|
|||
Stream responseStream = response.GetResponseStream();
|
||||
if (responseStream != null)
|
||||
{
|
||||
imgurInfo.Image = Image.FromStream(responseStream);
|
||||
imgurInfo.Image = ImageHelper.FromStream(responseStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -226,16 +226,21 @@ namespace GreenshotImgurPlugin {
|
|||
/// <returns>ImgurInfo</returns>
|
||||
public static ImgurInfo RetrieveImgurInfo(string hash, string deleteHash) {
|
||||
string url = Config.ImgurApi3Url + "/image/" + hash + ".xml";
|
||||
LOG.InfoFormat("Retrieving Imgur info for {0} with url {1}", hash, url);
|
||||
Log.InfoFormat("Retrieving Imgur info for {0} with url {1}", hash, url);
|
||||
HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(url, HTTPMethod.GET);
|
||||
webRequest.ServicePoint.Expect100Continue = false;
|
||||
SetClientId(webRequest);
|
||||
string responseString;
|
||||
string responseString = null;
|
||||
try {
|
||||
using (WebResponse response = webRequest.GetResponse()) {
|
||||
LogRateLimitInfo(response);
|
||||
using (StreamReader reader = new StreamReader(response.GetResponseStream(), true)) {
|
||||
responseString = reader.ReadToEnd();
|
||||
var responseStream = response.GetResponseStream();
|
||||
if (responseStream != null)
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(responseStream, true))
|
||||
{
|
||||
responseString = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (WebException wE) {
|
||||
|
@ -246,9 +251,13 @@ namespace GreenshotImgurPlugin {
|
|||
}
|
||||
throw;
|
||||
}
|
||||
LOG.Debug(responseString);
|
||||
ImgurInfo imgurInfo = ImgurInfo.ParseResponse(responseString);
|
||||
imgurInfo.DeleteHash = deleteHash;
|
||||
ImgurInfo imgurInfo = null;
|
||||
if (responseString != null)
|
||||
{
|
||||
Log.Debug(responseString);
|
||||
imgurInfo = ImgurInfo.ParseResponse(responseString);
|
||||
imgurInfo.DeleteHash = deleteHash;
|
||||
}
|
||||
return imgurInfo;
|
||||
}
|
||||
|
||||
|
@ -257,21 +266,26 @@ namespace GreenshotImgurPlugin {
|
|||
/// </summary>
|
||||
/// <param name="imgurInfo"></param>
|
||||
public static void DeleteImgurImage(ImgurInfo imgurInfo) {
|
||||
LOG.InfoFormat("Deleting Imgur image for {0}", imgurInfo.DeleteHash);
|
||||
Log.InfoFormat("Deleting Imgur image for {0}", imgurInfo.DeleteHash);
|
||||
|
||||
try {
|
||||
string url = Config.ImgurApi3Url + "/image/" + imgurInfo.DeleteHash + ".xml";
|
||||
HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(url, HTTPMethod.DELETE);
|
||||
webRequest.ServicePoint.Expect100Continue = false;
|
||||
SetClientId(webRequest);
|
||||
string responseString;
|
||||
string responseString = null;
|
||||
using (WebResponse response = webRequest.GetResponse()) {
|
||||
LogRateLimitInfo(response);
|
||||
using (StreamReader reader = new StreamReader(response.GetResponseStream(), true)) {
|
||||
responseString = reader.ReadToEnd();
|
||||
var responseStream = response.GetResponseStream();
|
||||
if (responseStream != null)
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(responseStream, true))
|
||||
{
|
||||
responseString = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG.InfoFormat("Delete result: {0}", responseString);
|
||||
Log.InfoFormat("Delete result: {0}", responseString);
|
||||
} catch (WebException wE) {
|
||||
// Allow "Bad request" this means we already deleted it
|
||||
if (wE.Status == WebExceptionStatus.ProtocolError) {
|
||||
|
@ -293,7 +307,7 @@ namespace GreenshotImgurPlugin {
|
|||
/// <param name="key"></param>
|
||||
private static void LogHeader(IDictionary<string, string> nameValues, string key) {
|
||||
if (nameValues.ContainsKey(key)) {
|
||||
LOG.InfoFormat("key={0}", nameValues[key]);
|
||||
Log.InfoFormat("key={0}", nameValues[key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue