public ActionResult CanUpload(string filename) { filename = filename.Replace('+', ' '); if (Uploads.ContainsKey(Request.RemoteEndPoint.Address.ToString())) { return(Json(new { success = false, reason = "One upload at a time, please." })); } if (filename.Contains(Path.DirectorySeparatorChar)) { return(Json(new { success = false, reason = "Invalid filename." })); } if (!SongNameRegex.IsMatch(filename)) { return(Json(new { success = false, reason = "File name is not in \"Artist Name - Song Title.mp3\" format." })); } if (File.Exists(Path.Combine(Program.Configuration.MusicPath, filename))) { return(Json(new { success = false, reason = "This song is already in our library." })); } var minutes = MusicRunner.MinutesUntilNextUpload(Request.RemoteEndPoint.Address.ToString()); if (minutes > 0) { return(Json(new { success = false, reason = string.Format("You need to wait another {0} minutes before you can upload again.", minutes) })); } return(Json(new { success = true })); }
public ActionResult StartUpload(string filename, long length64) { filename = filename.Replace('+', ' '); if (Uploads.ContainsKey(Request.RemoteEndPoint.Address.ToString())) { return(Json(new { success = false, reason = "One upload at a time, please." })); } if (length64 > 104857600) // 100 MB { return(Json(new { success = false, reason = "File too large." })); } if (filename.Contains(Path.DirectorySeparatorChar)) { return(Json(new { success = false, error = "Invalid filename." })); } if (!SongNameRegex.IsMatch(filename)) { return(Json(new { success = false, error = "File name is not in \"Artist Name - Song Title.mp3\" format." })); } if (File.Exists(Path.Combine(Program.Configuration.MusicPath, filename))) { return(Json(new { success = false, error = "This song is already in our library." })); } var minutes = MusicRunner.MinutesUntilNextUpload(Request.RemoteEndPoint.Address.ToString()); if (minutes < 0) { return(Json(new { success = false, error = string.Format("You need to wait another {0} minutes before you can upload again.", minutes) })); } Uploads.Add(Request.RemoteEndPoint.Address.ToString(), new UploadInProgress { PartialData = string.Empty, Filename = filename, FinalLength = length64 }); return(Json(new { success = true, partLength = UploadedPartLength })); }