is allowed */ ?>
} ?>
diff --git a/www/ebooks/download.php b/www/ebooks/download.php
index 8a2c59f5..8c48590b 100644
--- a/www/ebooks/download.php
+++ b/www/ebooks/download.php
@@ -1,12 +1,17 @@
use Safe\DateTimeImmutable;
-// If the user is not logged in, or has less than some amount of downloads, show a thank-you page.
$ebook = null;
-$downloadCount = HttpInput::Int(COOKIE, 'download-count') ?? 0;
-$showThankYouPage = Session::$User === null && $downloadCount < 5;
$downloadUrl = null;
+$downloadCount = HttpInput::Int(COOKIE, 'download-count') ?? 0;
+$source = Enums\EbookDownloadSource::tryFrom(HttpInput::Str(GET, 'source') ?? '');
+
+// Skip the thank you page if any of these are true:
+// * The user is logged in.
+// * Their `download-count` cookie is above some amount.
+// * The link is from a specific source.
+$skipThankYouPage = isset(Session::$User) || $downloadCount > 4 || isset($source);
try{
$urlPath = HttpInput::Str(GET, 'url-path') ?? null;
@@ -17,28 +22,21 @@ try{
throw new Exceptions\InvalidFileException();
}
- $format = Enums\EbookFormatType::tryFrom(HttpInput::Str(GET, 'format') ?? '') ?? Enums\EbookFormatType::Epub;
- switch($format){
- case Enums\EbookFormatType::Kepub:
- $downloadUrl = $ebook->KepubUrl;
- break;
-
- case Enums\EbookFormatType::Azw3:
- $downloadUrl = $ebook->Azw3Url;
- break;
-
- case Enums\EbookFormatType::AdvancedEpub:
- $downloadUrl = $ebook->AdvancedEpubUrl;
- break;
-
- case Enums\EbookFormatType::Epub:
- default:
- $downloadUrl = $ebook->EpubUrl;
- break;
+ $filename = HttpInput::Str(GET, 'filename');
+ if(!isset($filename)){
+ throw new Exceptions\InvalidFileException();
}
- if(!$showThankYouPage){
+ try{
+ $format = Enums\EbookFormatType::FromFilename($filename);
+ }
+ catch(Exceptions\InvalidEbookFormatException){
+ throw new Exceptions\InvalidFileException();
+ }
+
+ if($skipThankYouPage){
// Download the file directly, without showing the thank you page.
+ $downloadUrl = $ebook->GetDownloadUrl($format);
$downloadPath = WEB_ROOT . $downloadUrl;
if(!is_file($downloadPath)){
@@ -54,6 +52,8 @@ try{
exit();
}
+ $downloadUrl = $ebook->GetDownloadUrl($format, Enums\EbookDownloadSource::DownloadPage);
+
// Increment local download count, expires in 2 weeks.
$downloadCount++;
setcookie('download-count', (string)$downloadCount, ['expires' => intval((new DateTimeImmutable('+2 week'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']);
diff --git a/www/ebooks/get.php b/www/ebooks/get.php
index 0fd76d12..313e6fbc 100644
--- a/www/ebooks/get.php
+++ b/www/ebooks/get.php
@@ -200,7 +200,7 @@ catch(Exceptions\EbookNotFoundException){
- Compatible epub — All devices and apps except Kindles and Kobos.
+ Compatible epub — All devices and apps except Kindles and Kobos.
} ?>
@@ -209,7 +209,7 @@ catch(Exceptions\EbookNotFoundException){
- azw3 — Kindle devices and apps. if($ebook->KindleCoverUrl !== null){ ?> Also download the Kindle cover thumbnail to see the cover in your Kindle’s library. Despite what you’ve been told, Kindle does not natively support epub. You may also be interested in our Kindle FAQ. }else{ ?> Also see our Kindle FAQ. } ?>
+ azw3 — Kindle devices and apps. if($ebook->KindleCoverUrl !== null){ ?> Also download the Kindle cover thumbnail to see the cover in your Kindle’s library. Despite what you’ve been told, Kindle does not natively support epub. You may also be interested in our Kindle FAQ. }else{ ?> Also see our Kindle FAQ. } ?>
} ?>
@@ -218,7 +218,7 @@ catch(Exceptions\EbookNotFoundException){
- kepub — Kobo devices and apps. You may also be interested in our Kobo FAQ.
+ kepub — Kobo devices and apps. You may also be interested in our Kobo FAQ.
} ?>
@@ -227,7 +227,7 @@ catch(Exceptions\EbookNotFoundException){
- Advanced epub — An advanced format that uses the latest technology not yet fully supported by most ereaders.
+ Advanced epub — An advanced format that uses the latest technology not yet fully supported by most ereaders.
} ?>