3 Commits

Author SHA1 Message Date
15fc367263 logging 2023-06-01 21:16:57 +02:00
8bb6fb902b File Permissions 2023-06-01 18:28:58 +02:00
a57903cd5a readme update 2023-06-01 16:04:21 +02:00
3 changed files with 19 additions and 7 deletions

View File

@ -115,7 +115,7 @@ Wherever you are mounting `/usr/share/Tranga-API` you also need to mount that sa
- [x] Web-UI #1 - [x] Web-UI #1
- [ ] More Connectors - [ ] More Connectors
- [ ] Manganato #2 - [x] Manganato #2
- [ ] ? - [ ] ?
See the [open issues](https://git.bernloehr.eu/glax/Tranga/issues) for a full list of proposed features (and known issues). See the [open issues](https://git.bernloehr.eu/glax/Tranga/issues) for a full list of proposed features (and known issues).

View File

@ -1,7 +1,9 @@
using System.IO.Compression; using System.IO.Compression;
using System.Net; using System.Net;
using System.Runtime.InteropServices;
using System.Xml.Linq; using System.Xml.Linq;
using Logging; using Logging;
using static System.IO.UnixFileMode;
namespace Tranga; namespace Tranga;
@ -129,9 +131,13 @@ public abstract class Connector
private void DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null) private void DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
{ {
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer); DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer);
if (requestResult.result != Stream.Null)
{
byte[] buffer = new byte[requestResult.result.Length]; byte[] buffer = new byte[requestResult.result.Length];
requestResult.result.ReadExactly(buffer, 0, buffer.Length); requestResult.result.ReadExactly(buffer, 0, buffer.Length);
File.WriteAllBytes(fullPath, buffer); File.WriteAllBytes(fullPath, buffer);
}else
logger?.WriteLine(this.GetType().ToString(), "No Stream-Content in result.");
} }
/// <summary> /// <summary>
@ -161,7 +167,7 @@ public abstract class Connector
{ {
string[] split = imageUrl.Split('.'); string[] split = imageUrl.Split('.');
string extension = split[^1]; string extension = split[^1];
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1}/{imageUrls.Length}"); logger?.WriteLine("Connector", $"Downloading Image {chapter + 1}/{imageUrls.Length} {imageUrl}");
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer); DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
} }
@ -171,6 +177,8 @@ public abstract class Connector
logger?.WriteLine("Connector", $"Creating archive {saveArchiveFilePath}"); logger?.WriteLine("Connector", $"Creating archive {saveArchiveFilePath}");
//ZIP-it and ship-it //ZIP-it and ship-it
ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath); ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath);
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
File.SetUnixFileMode(saveArchiveFilePath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
Directory.Delete(tempFolder, true); //Cleanup Directory.Delete(tempFolder, true); //Cleanup
} }
@ -249,7 +257,7 @@ public abstract class Connector
catch (HttpRequestException e) catch (HttpRequestException e)
{ {
logger?.WriteLine(this.GetType().ToString(), e.Message); logger?.WriteLine(this.GetType().ToString(), e.Message);
logger?.WriteLine(this.GetType().ToString(), $"Waiting {_rateLimit[requestType] * 2}"); logger?.WriteLine(this.GetType().ToString(), $"Waiting {_rateLimit[requestType] * 2}... Retrying.");
Thread.Sleep(_rateLimit[requestType] * 2); Thread.Sleep(_rateLimit[requestType] * 2);
} }
} }

View File

@ -1,6 +1,8 @@
using System.Text; using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Newtonsoft.Json; using Newtonsoft.Json;
using static System.IO.UnixFileMode;
namespace Tranga; namespace Tranga;
@ -56,6 +58,8 @@ public readonly struct Publication
string seriesInfoPath = Path.Join(publicationFolder, "series.json"); string seriesInfoPath = Path.Join(publicationFolder, "series.json");
if(!File.Exists(seriesInfoPath)) if(!File.Exists(seriesInfoPath))
File.WriteAllText(seriesInfoPath,this.GetSeriesInfoJson()); File.WriteAllText(seriesInfoPath,this.GetSeriesInfoJson());
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
File.SetUnixFileMode(seriesInfoPath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
} }
/// <returns>Serialized JSON String for series.json</returns> /// <returns>Serialized JSON String for series.json</returns>