added /api/AddItem

This commit is contained in:
Michael Nolan 2021-09-25 01:53:44 -05:00
parent 792e566ea2
commit 521ab2cd95
5 changed files with 28 additions and 30 deletions

View File

@ -50,7 +50,7 @@ namespace youtube_downloader
f.Save(Path.Combine(webSitePath,f.FileName)); f.Save(Path.Combine(webSitePath,f.FileName));
rp.AsText("uploaded", "text/plain"); rp.AsText("uploaded", "text/plain");
},"POST"); },"POST");
Route.Add("/api/AddItems", (HttpActionAsync)AddItems,"POST"); Route.Add("/api/AddItems", (HttpAction)AddItems,"POST");
Route.Add("/", (rq, rp, args) => Route.Add("/", (rq, rp, args) =>
{ {
rp.AsFile(rq, Path.Combine(webSitePath, "index.html")); 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); using (var req = new StreamReader(file.Value))
response.Redirect("/"); {
List<IDResolutionTypeTriplet> tripletlst = JsonConvert.DeserializeObject<List<IDResolutionTypeTriplet>>( req.ReadToEnd());
Server.Functions.Downloader.DownloadItems(tripletlst);
response.Redirect("/");
}
} }
} }
/* /*
private static string HandleRequest(Stream inputStream, Encoding currentEncoding) private static string HandleRequest(Stream inputStream, Encoding currentEncoding)

View File

@ -22,33 +22,25 @@ namespace youtube_downloader.Server.Models
switch(Type) switch(Type)
{ {
case InfoType.Video: case InfoType.Video:
VideoId? vid = VideoId.TryParse(Id); VideoId vid = Id;
if (vid.HasValue)
{ return new InfomationQueueItem(vid, Resolution, download);
return new InfomationQueueItem(vid.Value, Resolution, download);
}
break;
case InfoType.Playlist: case InfoType.Playlist:
PlaylistId? pid = PlaylistId.TryParse(Id); PlaylistId pid = Id;
if (pid.HasValue) return new InfomationQueueItem(pid, Resolution, download);
{
return new InfomationQueueItem(pid.Value, Resolution, download);
}
break;
case InfoType.Channel: case InfoType.Channel:
ChannelId? cid = ChannelId.TryParse(Id); ChannelId cid = Id;
if (cid.HasValue) return new InfomationQueueItem(cid, Resolution, download);
{
return new InfomationQueueItem(cid.Value, Resolution, download);
}
break;
case InfoType.User: case InfoType.User:
UserName? user = UserName.TryParse(Id); UserName user = Id;
if (user.HasValue)
{ return new InfomationQueueItem(user, Resolution, download);
return new InfomationQueueItem(user.Value, Resolution, download);
}
break;
} }
return null; return null;
} }

Binary file not shown.