Send Non books to your Devices (#1691)

* Only restrict non-epub/pdf for Kindle devices on Send To.

* Removed restriction to email non-epub/pdfs to devices.
This commit is contained in:
Joe Milazzo 2022-12-11 09:55:59 -06:00 committed by GitHub
parent ee5ea708d9
commit b672cf545d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 20 deletions

View file

@ -7,6 +7,7 @@ using API.DTOs.Device;
using API.DTOs.Email;
using API.Entities;
using API.Entities.Enums;
using API.Entities.Enums.Device;
using API.SignalR;
using Kavita.Common;
using Microsoft.Extensions.Logging;
@ -105,12 +106,14 @@ public class DeviceService : IDeviceService
public async Task<bool> SendTo(IReadOnlyList<int> chapterIds, int deviceId)
{
var files = await _unitOfWork.ChapterRepository.GetFilesForChaptersAsync(chapterIds);
if (files.Any(f => f.Format is not (MangaFormat.Epub or MangaFormat.Pdf)))
throw new KavitaException("Cannot Send non Epub or Pdf to devices as not supported");
var device = await _unitOfWork.DeviceRepository.GetDeviceById(deviceId);
if (device == null) throw new KavitaException("Device doesn't exist");
var files = await _unitOfWork.ChapterRepository.GetFilesForChaptersAsync(chapterIds);
if (files.Any(f => f.Format is not (MangaFormat.Epub or MangaFormat.Pdf)) && device.Platform == DevicePlatform.Kindle)
throw new KavitaException("Cannot Send non Epub or Pdf to devices as not supported on Kindle");
device.LastUsed = DateTime.Now;
_unitOfWork.DeviceRepository.Update(device);
await _unitOfWork.CommitAsync();