Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for issue #169 -- Added a special case where login redirect is found the id is pulled from the url in a different spot #170

Merged
merged 3 commits into from

2 participants

@sethwebster

No description provided.

...ntProviders/GoogleDocsPresentationsContentProvider.cs
((4 lines not shown))
using System.Net;
using System.Web;
+using System.Text.RegularExpressions;
@davidfowl Owner

Sort usings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@davidfowl davidfowl merged commit 91714e9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 3, 2011
  1. @sethwebster

    Fix for issue #169 -- Added a special case where login redirect is fo…

    sethwebster authored
    …und, the id
    
    is pulled from the url in a different spot
Commits on Dec 4, 2011
  1. @sethwebster
  2. @sethwebster

    Sorted Usings.

    sethwebster authored
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 0 deletions.
  1. +38 −0 JabbR/ContentProviders/GoogleDocsPresentationsContentProvider.cs
View
38 JabbR/ContentProviders/GoogleDocsPresentationsContentProvider.cs
@@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Net;
+using System.Text.RegularExpressions;
using System.Web;
namespace JabbR.ContentProviders
{
public class GoogleDocsPresentationsContentProvider : EmbedContentProvider
{
+ private static readonly Regex _googleDocsInternalUrlIdRegex = new Regex(@".*/d/(.+)/.*");
public override string MediaFormatString
{
get
@@ -15,6 +18,14 @@ public override string MediaFormatString
}
}
+ public override Regex MediaUrlRegex
+ {
+ get
+ {
+ return _googleDocsInternalUrlIdRegex;
+ }
+ }
+
public override IEnumerable<string> Domains
{
get
@@ -24,14 +35,41 @@ public override IEnumerable<string> Domains
}
}
+ protected override bool IsValidContent(HttpWebResponse response)
+ {
+ if (!base.IsValidContent(response))
+ {
+ // Someone may have pasted a link requiring a login --
+ // We can handle that here
+ if (response.ResponseUri.AbsoluteUri.StartsWith("https://accounts.google.com/ServiceLogin") ||
+ response.ResponseUri.AbsoluteUri.StartsWith("http://accounts.google.com/ServiceLogin"))
+ {
+ var qs = HttpUtility.ParseQueryString(response.ResponseUri.Query);
+ if (qs.AllKeys.Contains("continue"))
+ {
+ return Domains.Any(d => qs["continue"].StartsWith(d));
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
protected override IEnumerable<object> ExtractParameters(Uri responseUri)
{
+ // If someone uses a google created share url (hard to find in interface)
+ // this will work
var queryString = HttpUtility.ParseQueryString(responseUri.Query);
string formId = queryString["id"];
if (!String.IsNullOrEmpty(formId))
{
yield return formId;
}
+
+ // If someone uses the obvious link used while they are logged in and editing
+ // the url will come through as a login redirect -- the MediaUrlRegex will
+ // extract the correct Id and we may continue as normal in that case
+ yield return base.ExtractParameters(responseUri).FirstOrDefault();
}
}
}
Something went wrong with that request. Please try again.