예제 #1
0
        private LibNeeo.IO.File GetRequestedFile(FileRequest fileRequest)
        {
            switch (fileRequest.FileCategory)
            {
            case FileCategory.Shared:
                return(SharedMedia.GetMedia(fileRequest.Name, fileRequest.MediaType));

            case FileCategory.Group:
                return(NeeoGroup.GetGroupIcon(fileRequest.Name));

            default:
                return(null);
            }
        }
예제 #2
0
        private LibNeeo.IO.File GetRequestedFile(string fileID, FileCategory fileCategory, MediaType mediaType)
        {
            string filePath = null;

            switch (fileCategory)
            {
            case FileCategory.Shared:
                return(SharedMedia.GetMedia(fileID, mediaType));

                break;

            case FileCategory.Group:
                return(NeeoGroup.GetGroupIcon(fileID));

                break;

            default:
                return(null);
            }
        }
예제 #3
0
        public async Task <HttpResponseMessage> Put([FromUri] string type, [FromUri] string sessionID)
        {
            long startingPosition = 0;

            try
            {
                if (type != "resumable" || NeeoUtility.IsNullOrEmpty(sessionID))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }
                var session = await UploadSessionManager.ValidateSessionAsync(sessionID);

                if (session == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }
                session.FileInfo.Extension =
                    MimeTypeMapping.GetMimeTypeDetail(session.FileInfo.MimeType.GetDescription()).Extension;
                long?  contentLength = Request.Content.Headers.ContentLength;
                string contentType   = Request.Content.Headers.ContentType == null
                    ? null
                    : Request.Content.Headers.ContentType.ToString();

                if (Request.Content.Headers.Contains("Content-Range"))
                {
                    var contentRange = Request.Content.Headers.GetValues("Content-Range").First();

                    if (contentRange == "bytes */*")
                    {
                        var file = SharedMedia.GetMedia(session.FileInfo.Name, session.FileInfo.MediaType);
                        if (file != null)
                        {
                            var response = Request.CreateResponse((HttpStatusCode)308);
                            response.Headers.Add("Range", "bytes=0-" + file.Info.Length);
                            response.ReasonPhrase = "Resumable Incomplete";
                            return(response);
                        }
                        else
                        {
                            var response = Request.CreateResponse((HttpStatusCode)308);
                            response.Headers.Add("Range", "bytes=0-0");
                            response.ReasonPhrase = "Resumable Incomplete";
                            return(response);
                        }
                    }
                    else
                    {
                        var delimeter   = new char[] { '-', '/', ' ' };
                        var rangeValues = contentRange.Split(delimeter);
                        if (rangeValues.Length != 4)
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest));
                        }
                        if (Convert.ToInt64(rangeValues[2]) != session.FileInfo.Length)
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest));
                        }
                        startingPosition = Convert.ToInt64(rangeValues[1]);
                    }
                }

                if (contentLength == null || contentLength > (long)session.FileInfo.Length)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }
                using (var stream = await Request.Content.ReadAsStreamAsync())
                {
                    var newFile = new File()
                    {
                        Info       = session.FileInfo,
                        FileStream = new FileDataStream()
                        {
                            Stream  = stream,
                            Postion = startingPosition
                        }
                    };

                    if (SharedMedia.Save(new NeeoUser(session.FileInfo.Creator), newFile, FileCategory.Shared, 0))
                    {
                        // check the length of the file with the database then delete it.
                        await UploadSessionManager.DeleteSessionAsync(sessionID);

                        var response = new HttpResponseMessage(HttpStatusCode.Created);
                        response.Headers.Location = new Uri(newFile.Info.Url);
                        return(response);
                    }
                }
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
            catch (Exception exception)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }