Example #1
0
 private void btnImportUrlShortenersList_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     using (var client = new WebClient()) {
         var dataString = client.DownloadString("https://kosciol-jezusa.pl/api/UrlShortList");
         if (dataString.IsNotNullOrEmpty())
         {
             var result = JsonConvert.DeserializeObject <List <UrlShortInfo> >(dataString);
             if (result.IsNotNull())
             {
                 var uow = new UnitOfWork();
                 foreach (var item in result)
                 {
                     var q = new XPQuery <UrlShort>(uow).Where(x => x.ShortUrl == item.Short).Any();
                     if (!q)
                     {
                         var s = new UrlShort(uow)
                         {
                             ShortUrl = item.Short,
                             Url      = item.Url
                         };
                         s.Save();
                         uow.CommitChanges();
                     }
                 }
             }
         }
     }
 }
Example #2
0
        public ActionResult <string> Get()
        {
            var url        = GetReqParam("url");
            var host       = this.Request.Host.ToString();
            var hostPrefix = Request.IsHttps ? "https://" : "http://";

            if (url.IsNotNullOrEmpty())
            {
                var uow  = new UnitOfWork();
                var _url = new XPQuery <UrlShort>(uow).Where(x => x.Url == url).FirstOrDefault();
                if (_url.IsNull())
                {
                    _url = new UrlShort(uow)
                    {
                        Url      = url,
                        ShortUrl = GetShortUrl(uow)
                    };
                    _url.Save();
                    uow.CommitChanges();
                }

                return($"{hostPrefix}{host}/{_url.ShortUrl}");
            }
            return(url);
        }
Example #3
0
        private static string UrlToShortLink(System.Text.RegularExpressions.Match m)
        {
            string v = m.Value;

            if (v.Contains(BaseConfigs.GetShortLinkDomainName))
            {
                return(v);
            }
            string code = UrlShort.ShortUrl(v)[0];

            return(BaseConfigs.GetShortLinkDomainName + code);
        }
Example #4
0
        private void MenuItemDownloadLink_Click(object sender, RoutedEventArgs e)
        {
            if (this.SearchResults.SelectedItems.Count != 1)
            {
                return;
            }

            Beatmap map = (Beatmap)this.SearchResults.SelectedItems[0];

            this.ShortURLOverlay.BeginAnimation(Grid.OpacityProperty, new DoubleAnimation()
            {
                Duration     = new Duration(new TimeSpan(0, 0, 0, 0, 500)),
                FillBehavior = FillBehavior.HoldEnd,
                From         = 0.0,
                To           = 1.0
            });
            this.ShortURLOverlay.Visibility = Visibility.Visible;


            ThreadPool.QueueUserWorkItem(new WaitCallback((object ob) =>
            {
                string url      = string.Format("{0}beatmaps/{1}/download/{2}.{3}", Configuration.ApiLocation, map.Ranked_ID, Uri.EscapeUriString(Helpers.CleanLink(map.Name)), map.Type.ToString().ToLower());
                string urlshort = UrlShort.Short(url);

                Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
                {
                    System.Windows.Clipboard.SetDataObject(urlshort);

                    DoubleAnimation anim = new DoubleAnimation()
                    {
                        Duration     = new Duration(new TimeSpan(0, 0, 0, 0, 500)),
                        FillBehavior = FillBehavior.HoldEnd,
                        From         = 1.0,
                        To           = 0.0
                    };

                    anim.Completed += (object ssender, EventArgs ee) =>
                    {
                        this.ShortURLOverlay.Visibility = Visibility.Hidden;
                    };

                    this.ShortURLOverlay.BeginAnimation(Grid.OpacityProperty, anim);
                }));
            }));
        }
Example #5
0
 public JsonResult Upload()
 {
     try
     {
         if (Request.Form["weibo"] == null)
         {
             throw new Exception();
         }
         string cookie      = Request.Form["weibo"].ToString();
         string uid         = cookie.Split('&')[0].Replace("UID=", "");
         string pwd         = Utils.UrlDecode(cookie.Split('&')[1].Replace("PWD=", ""));
         User   CurrentUser = Users.GetUserByID(TypeConverter.StrToLong(uid, -1));
         if (CurrentUser == null)
         {
             throw new Exception();
         }
         if (CurrentUser.Password != pwd)
         {
             throw new Exception();
         }
         Music music = Musics.UploadMusic(CurrentUser);
         if (music != null)
         {
             Entity.Url url = new Url();
             url.MediaID     = music.ID;
             url.ShortLink   = UrlShort.ShortUrl(music.MusicUrl)[0];
             url.OriginalUrl = music.MusicUrl;
             url.Type        = TypeConfigs.GetUrlMusic;
             url.ID          = Urls.CreateUrl(url);
             if (url.ID > 0)
             {
                 string shortlink = BaseConfigs.GetShortLinkDomainName + url.ShortLink;
                 return(Json(new JsonModel(CodeStruct.UploadSuccess, shortlink + " " + music.Title)));
             }
         }
         return(Json(new JsonModel(CodeStruct.Error, "-1")));
     }
     catch (Exception ex)
     {
         return(Json(new JsonModel(CodeStruct.Error, "-1")));
     }
 }
        public ShortenerRepo(string url, LiteDatabase db)
        {
            var urls = db.GetCollection <UrlShort>();

            //Validate and generate new
            while (urls.Exists(u => u.Token == GenerateToken().Token))
            {
                ;
            }

            urlShort = new UrlShort()
            {
                Token = Token,
                URL   = url,
                //Prepare a open link
                ShortenedURL = "http://" + HttpContext.Current.Request.Url.Authority + "/oo?url=" + Token
            };
            // Save the model to  the DB
            urls.Insert(urlShort);
        }
Example #7
0
        public static string AnalysisUrl(string url)
        {
            try
            {
                if (!Utils.IsURL(url))
                {
                    return(null);
                }

                string tmpCode = "";
                if (IsShortLink(url, ref tmpCode))
                {
                    return(tmpCode);
                }

                string shortlink = UrlShort.ShortUrl(url)[0];
                Url    u         = GetUrlByShortLink(shortlink);
                if (u != null)
                {
                    UpdateUrlForRefCount(u.ID);
                }
                else
                {
                    u             = new Url();
                    u.MediaID     = -1;
                    u.OriginalUrl = url;
                    u.ShortLink   = shortlink;
                    u.Type        = TypeConfigs.GetUrlNormal;
                    u.ID          = Urls.CreateUrl(u);
                }
                if (u.MediaID < 0)
                {
                    long mediaID = 0;
                    int  type    = TypeConfigs.GetUrlNormal;
                    if (Videos.IsVideoUrl(url))
                    {
                        VideoInfo vInfo = Videos.GetVideo(url);
                        if (vInfo != null)
                        {
                            long vid = Videos.CreateVideo(vInfo);
                            if (vid > 0)
                            {
                                mediaID = vid;
                                type    = TypeConfigs.GetUrlVideo;
                            }
                        }
                    }
                    if (Musics.IsMusicUrl(url))
                    {
                        Music music = new Music();
                        music.Title    = Path.GetFileNameWithoutExtension(url);
                        music.MusicUrl = url;
                        long mid = Musics.CreateMusic(music);
                        if (mid > 0)
                        {
                            mediaID = mid;
                            type    = TypeConfigs.GetUrlMusic;
                        }
                    }
                    if (Votes.IsVoteUrl(url))
                    {
                        long vid  = Votes.GetVoteIdFromUrl(url);
                        Vote vote = Votes.GetVoteByID(vid);
                        if (vote != null)
                        {
                            mediaID = vote.ID;
                            type    = TypeConfigs.GetUrlVote;
                        }
                    }
                    if (mediaID != 0)
                    {
                        UpdateUrlForMedia(u.ID, mediaID, type);
                        return(shortlink);
                    }
                    else
                    {
                        return(shortlink);
                    }
                }
                else
                {
                    return(shortlink);
                }
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return(null);
            }
        }