added /api/AddItem
This commit is contained in:
parent
792e566ea2
commit
521ab2cd95
18
Program.cs
18
Program.cs
|
@ -50,7 +50,7 @@ namespace youtube_downloader
|
|||
f.Save(Path.Combine(webSitePath,f.FileName));
|
||||
rp.AsText("uploaded", "text/plain");
|
||||
},"POST");
|
||||
Route.Add("/api/AddItems", (HttpActionAsync)AddItems,"POST");
|
||||
Route.Add("/api/AddItems", (HttpAction)AddItems,"POST");
|
||||
Route.Add("/", (rq, rp, args) =>
|
||||
{
|
||||
rp.AsFile(rq, Path.Combine(webSitePath, "index.html"));
|
||||
|
@ -243,15 +243,21 @@ namespace youtube_downloader
|
|||
}
|
||||
}
|
||||
|
||||
private static async Task AddItems(HttpListenerRequest request, HttpListenerResponse response, Dictionary<string, string> arguments)
|
||||
private static void AddItems(HttpListenerRequest request, HttpListenerResponse response, Dictionary<string, string> arguments)
|
||||
{
|
||||
using (var req = new StreamReader(request.InputStream,request.ContentEncoding))
|
||||
var f = request.ParseBody(arguments);
|
||||
foreach(var file in f.Values)
|
||||
{
|
||||
List<IDResolutionTypeTriplet> tripletlst = JsonConvert.DeserializeObject<List<IDResolutionTypeTriplet>>(await req.ReadToEndAsync());
|
||||
Server.Functions.Downloader.DownloadItems(tripletlst);
|
||||
response.Redirect("/");
|
||||
|
||||
using (var req = new StreamReader(file.Value))
|
||||
{
|
||||
List<IDResolutionTypeTriplet> tripletlst = JsonConvert.DeserializeObject<List<IDResolutionTypeTriplet>>( req.ReadToEnd());
|
||||
Server.Functions.Downloader.DownloadItems(tripletlst);
|
||||
response.Redirect("/");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
private static string HandleRequest(Stream inputStream, Encoding currentEncoding)
|
||||
|
|
|
@ -22,33 +22,25 @@ namespace youtube_downloader.Server.Models
|
|||
switch(Type)
|
||||
{
|
||||
case InfoType.Video:
|
||||
VideoId? vid = VideoId.TryParse(Id);
|
||||
if (vid.HasValue)
|
||||
{
|
||||
return new InfomationQueueItem(vid.Value, Resolution, download);
|
||||
}
|
||||
break;
|
||||
VideoId vid = Id;
|
||||
|
||||
return new InfomationQueueItem(vid, Resolution, download);
|
||||
|
||||
|
||||
case InfoType.Playlist:
|
||||
PlaylistId? pid = PlaylistId.TryParse(Id);
|
||||
if (pid.HasValue)
|
||||
{
|
||||
return new InfomationQueueItem(pid.Value, Resolution, download);
|
||||
}
|
||||
break;
|
||||
PlaylistId pid = Id;
|
||||
return new InfomationQueueItem(pid, Resolution, download);
|
||||
|
||||
|
||||
case InfoType.Channel:
|
||||
ChannelId? cid = ChannelId.TryParse(Id);
|
||||
if (cid.HasValue)
|
||||
{
|
||||
return new InfomationQueueItem(cid.Value, Resolution, download);
|
||||
}
|
||||
break;
|
||||
ChannelId cid = Id;
|
||||
return new InfomationQueueItem(cid, Resolution, download);
|
||||
|
||||
case InfoType.User:
|
||||
UserName? user = UserName.TryParse(Id);
|
||||
if (user.HasValue)
|
||||
{
|
||||
return new InfomationQueueItem(user.Value, Resolution, download);
|
||||
}
|
||||
break;
|
||||
UserName user = Id;
|
||||
|
||||
return new InfomationQueueItem(user, Resolution, download);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue