示例#1
0
文件: Musics.cs 项目: apple0523/Weibo
        public static Music UploadMusic(User user)
        {
            try
            {
                if (user != null)
                {
                    HttpPostedFile file = HttpContext.Current.Request.Files[0];
                    if (file != null)
                    {
                        string title = Path.GetFileNameWithoutExtension(file.FileName);
                        string exe   = Path.GetExtension(file.FileName);
                        if (exe == ".mp3")
                        {
                            if (file.ContentLength < BaseConfigs.GetMusicUploadSize)
                            {
                                string dateNow = Utils.GetDate();
                                string path    = BaseConfigs.GetMusicUploadPath + dateNow + "/";
                                Utils.CreateDir(path);
                                string guid        = Guid.NewGuid().ToString();
                                string newFileName = guid + exe;
                                file.SaveAs(Utils.GetMapPath(path + newFileName));

                                Music music = new Music();
                                music.MusicUrl = BaseConfigs.GetWebDomain + path + newFileName;
                                music.Title    = title;

                                music.ID = Musics.CreateMusic(music);
                                if (music.ID > 0)
                                {
                                    return(music);
                                }
                            }
                        }
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return(null);
            }
        }
示例#2
0
文件: Urls.cs 项目: apple0523/Weibo
        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);
            }
        }