diff --git a/.vs/youtube-downloader/xs/UserPrefs.xml b/.vs/youtube-downloader/xs/UserPrefs.xml index 06dcd6e..74df1f4 100644 --- a/.vs/youtube-downloader/xs/UserPrefs.xml +++ b/.vs/youtube-downloader/xs/UserPrefs.xml @@ -1,5 +1,5 @@  - + @@ -7,7 +7,7 @@ - + @@ -16,21 +16,14 @@ - - - - - - - - + diff --git a/Program.cs b/Program.cs index de49e70..f80ad3c 100644 --- a/Program.cs +++ b/Program.cs @@ -26,6 +26,7 @@ using Dasync.Collections; using YoutubeExplode.Search; using Hyperlinq; using System.Net.Sockets; +using System.IO.Compression; namespace TYTD { @@ -216,6 +217,67 @@ namespace TYTD Downloader.RouteAdd("/api/HomePageChanger.html", "Admin", "Change Home Page", (HttpAction)ChangeFrontEnd); Downloader.RouteAdd("/api/SetHomePage", "Admin", "Used by /api/HomePageChanger.html to actually change home page", (HttpAction)SetFrontEnd, "POST"); + Downloader.RouteAdd("/api/RemoveUnwanted", "Admin", "Used by /api/InstallExtensionUpload", (req, resp, args) => { + if(AuthorizedAdmin(req, resp, args)) + { + req.ParseBody(args); + foreach(var a in args) + { + try + { + ApiLoader.UninstallExtension(a.Key); + } + catch(Exception ex) + { + _ = ex; + } + } + } + },"POST"); + Downloader.RouteAdd("/api/InstallExtensionUpload", "Admin", "Install Extension from Upload",(request, response, arguments) => + { + if (Authorized(request, response, arguments)) + { + Directory.CreateDirectory("extension_temp"); + var files = request.ParseBody(arguments, (fieldName, fileName, contentType) => + { + return File.Create($"extension_temp/{fileName}"); + }); + List<(ext_conf conf, string name)> ext_names = new List<(ext_conf, string)>(); + foreach (var f in files) + { + f.Value.Dispose(); + string key = f.Value.FileName; + ext_names.Add(ApiLoader.InstallExtension($"extension_temp/{key}")); + } + Directory.Delete("extension_temp",true); + StringBuilder fields = new StringBuilder(); + + foreach (var item in ext_names) + { + + string name = WebUtility.HtmlEncode(item.name); + string name_text = WebUtility.HtmlEncode(item.conf.name); + string desc = string.Join("
", item.conf.desc.Split('\n').Select(e => { return WebUtility.HtmlEncode(e); })); + + + string data = ""; + string root = Path.Combine(Environment.CurrentDirectory, "config"); + string fallbackIcon = Path.Combine(root, "default_icon.png"); + string icon = Path.Combine(root, "apiicons", name + ".png"); + string icon2 = File.Exists(icon) ? icon : fallbackIcon; + if (File.Exists(icon2)) + { + + data = Convert.ToBase64String(File.ReadAllBytes(icon2)); + } + fields.Append(" {name_text}{desc}"); + } + + string html = $"Extensions Installed

Do You Want all of these Extensions

If you kill the downloader before Accept, these extensions will be installed

{fields.ToString()}
Remove ThisIcon Title Description
"; + response.AsText(html); + } + },"POST"); Route.Add("/api/example_tripple_structure.json", (req, resp, args) => { @@ -1849,4 +1911,5 @@ namespace TYTD } } + } diff --git a/TYTD.Api/MyClass.cs b/TYTD.Api/MyClass.cs index ff2449d..1512389 100644 --- a/TYTD.Api/MyClass.cs +++ b/TYTD.Api/MyClass.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Compression; using System.Net; using System.Reflection; using System.Text; using System.Threading; +using Newtonsoft.Json; using SimpleHttp; using TYTD.Server.Functions; using TYTD.Server.Models; @@ -152,6 +154,58 @@ namespace TYTD } public static class ApiLoader { + public static void CopyDir(string src, string dest,bool canoverride=false) + { + Directory.CreateDirectory(dest); + //Console.WriteLine($"Created directory {dest}"); ; + foreach (var dir in Directory.EnumerateDirectories(src)) + { + CopyDir(dir, Path.Combine(dest, Path.GetFileName(dir))); + } + foreach (var file in Directory.EnumerateFiles(src)) + { + if(File.Exists(Path.Combine(dest, Path.GetFileName(file)))) + { + if(canoverride) + { + File.Delete(Path.Combine(dest, Path.GetFileName(file))); + + } + else { continue; } + } + File.Copy(file, Path.Combine(dest, Path.GetFileName(file))); + //Console.WriteLine($"Copied {file} -> {Path.Combine(dest, Path.GetFileName(file))}"); + } + //Console.WriteLine($"Copied directory {src} -> {dest}"); + } + public static void UninstallExtension(string name) + { + Directory.Delete($"config/apidll/{name}",true); + Directory.Delete($"config/apistore/{name}", true); + File.Delete($"config/apiicons/{name}.png"); + } + public static (ext_conf conf,string name) InstallExtension(string archive) + { + if(Directory.Exists($"{archive}_contents")) + { + Directory.Delete($"{archive}_contents", true); + } + ZipFile.ExtractToDirectory(archive, $"{archive}_contents"); + //we need to read manifest json + string manifest = $"{archive}_contents/manifest.json"; + ext_conf conf = JsonConvert.DeserializeObject(File.ReadAllText(manifest)); + string extName = Path.GetFileName(conf.binPath); + + Directory.CreateDirectory($"config/apidll/{extName}"); + Directory.CreateDirectory($"config/apistore/{extName}"); + Directory.CreateDirectory("config/apiicons"); + File.Copy($"{archive}_contents/{conf.icon}", $"config/apiicons/{extName}.png"); + string parDirOf = Path.GetDirectoryName($"{archive}_contents/{conf.binPath}"); + CopyDir(parDirOf, $"config/apidll/{extName}", true); + CopyDir($"{archive}_contents/files", $"config/apistore/{extName}", true); + Directory.Delete($"{archive}_contents"); + return (conf,extName); + } static bool start_term=false; public static bool StartTermination { get { return start_term; } set { start_term = value; if (start_term) { _cancel.Cancel(); } } } public static bool Restart { get; set; } @@ -311,4 +365,13 @@ namespace TYTD return _cancel.Token; } } + public class ext_conf + { + public string binPath { get; set; } + public string name { get; set; } + public string icon { get; set; } + public string desc { get; set; } + public bool hasHomePageOverride { get; set; } + } + } diff --git a/TYTD.Api/TYTD.Api.csproj b/TYTD.Api/TYTD.Api.csproj index ea31976..539c427 100644 --- a/TYTD.Api/TYTD.Api.csproj +++ b/TYTD.Api/TYTD.Api.csproj @@ -108,6 +108,10 @@ ..\packages\Hyperlinq.1.0.7\lib\net40-client\Hyperlinq.dll + + ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll + + diff --git a/TYTD.Api/bin/Release/TYTD.Api.dll b/TYTD.Api/bin/Release/TYTD.Api.dll index 405788f..cdde82e 100644 Binary files a/TYTD.Api/bin/Release/TYTD.Api.dll and b/TYTD.Api/bin/Release/TYTD.Api.dll differ diff --git a/TYTD.Api/obj/Release/TYTD.Api.csproj.CoreCompileInputs.cache b/TYTD.Api/obj/Release/TYTD.Api.csproj.CoreCompileInputs.cache index 9f43baf..f36e2ae 100644 --- a/TYTD.Api/obj/Release/TYTD.Api.csproj.CoreCompileInputs.cache +++ b/TYTD.Api/obj/Release/TYTD.Api.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -2b6dff7469b08f0770687859f1e70f9debc18804 +26643813a9972b2be5fd1ee18aabc6455f9a285b diff --git a/TYTD.Api/obj/Release/TYTD.Api.csprojAssemblyReference.cache b/TYTD.Api/obj/Release/TYTD.Api.csprojAssemblyReference.cache index 6f7375d..5021ec1 100644 Binary files a/TYTD.Api/obj/Release/TYTD.Api.csprojAssemblyReference.cache and b/TYTD.Api/obj/Release/TYTD.Api.csprojAssemblyReference.cache differ diff --git a/TYTD.Api/obj/Release/TYTD.Api.dll b/TYTD.Api/obj/Release/TYTD.Api.dll index 405788f..cdde82e 100644 Binary files a/TYTD.Api/obj/Release/TYTD.Api.dll and b/TYTD.Api/obj/Release/TYTD.Api.dll differ diff --git a/TYTD.Api/packages.config b/TYTD.Api/packages.config index 2e6ac4a..3409a5d 100644 --- a/TYTD.Api/packages.config +++ b/TYTD.Api/packages.config @@ -10,6 +10,7 @@ + diff --git a/bin/Release/TYTD.Api.dll b/bin/Release/TYTD.Api.dll index 405788f..cdde82e 100644 Binary files a/bin/Release/TYTD.Api.dll and b/bin/Release/TYTD.Api.dll differ diff --git a/bin/Release/youtube-downloader.exe b/bin/Release/youtube-downloader.exe index 2cb3968..38ce462 100644 Binary files a/bin/Release/youtube-downloader.exe and b/bin/Release/youtube-downloader.exe differ diff --git a/obj/x86/Release/youtube-downloader.csproj.CoreCompileInputs.cache b/obj/x86/Release/youtube-downloader.csproj.CoreCompileInputs.cache index d0ef135..21c1b36 100644 --- a/obj/x86/Release/youtube-downloader.csproj.CoreCompileInputs.cache +++ b/obj/x86/Release/youtube-downloader.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -7dbe06743fabd9c4c1020515efeec8905e352f88 +e3eba772fa8089a24bf256884284d266adbd5661 diff --git a/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache b/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache index 3e42103..ffbd940 100644 Binary files a/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache and b/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache differ diff --git a/obj/x86/Release/youtube-downloader.exe b/obj/x86/Release/youtube-downloader.exe index 2cb3968..38ce462 100644 Binary files a/obj/x86/Release/youtube-downloader.exe and b/obj/x86/Release/youtube-downloader.exe differ diff --git a/packages.config b/packages.config index fca9106..a0bf820 100644 --- a/packages.config +++ b/packages.config @@ -13,6 +13,7 @@ + diff --git a/youtube-downloader.csproj b/youtube-downloader.csproj index 8d6438d..965c569 100644 --- a/youtube-downloader.csproj +++ b/youtube-downloader.csproj @@ -118,6 +118,10 @@ packages\Hyperlinq.1.0.7\lib\net40-client\Hyperlinq.dll + + packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll + +