mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 20:08:19 +02:00
Compare commits
260 Commits
4b4e24c6a0
...
testing
| Author | SHA1 | Date | |
|---|---|---|---|
| 57cb48cbd0 | |||
| 611e8a04df | |||
| 6231f9a842 | |||
| 7f9bea00a4 | |||
| 1360b7afc5 | |||
| 3a8a2d2c86 | |||
| af01e4a6a4 | |||
| d4ea40a875 | |||
| 09e6b07186 | |||
| 26987c983f | |||
| b3df3bf144 | |||
| 757d7a8ab0 | |||
| ddcab0c6ed | |||
| f1a61a7b90 | |||
| 78e7e8fc06 | |||
| d1b2f0ab19 | |||
| 8439b8b2ab | |||
| 62090d1677 | |||
| e0735eea0f | |||
| 65418c0495 | |||
| 35e36a557c | |||
| ee3789fdfd | |||
| aae5c88ec9 | |||
| 0cb239a4e6 | |||
| b24308021b | |||
| 2d662c269b | |||
| c8be88d645 | |||
| 48914985d2 | |||
| f94513a4ae | |||
| b76f460778 | |||
| f9e017ec11 | |||
| ec54cad58c | |||
| a5c82b2505 | |||
| 35bbbc521e | |||
| 2cb898d8eb | |||
| c23d29436f | |||
| cb14a7c31f | |||
| 55f04710a7 | |||
| 6fa166363a | |||
| 1b0aa7d543 | |||
| 0c94e6e5fe | |||
| ffe1f4fd2c | |||
| e96b2585e0 | |||
| 3b8570cf57 | |||
| 6c61869e66 | |||
| 1c6398414d | |||
| 29d21f06e5 | |||
| b4a0ce68c3 | |||
| 94a8dfc90a | |||
| 81463de409 | |||
| e31ecbd66b | |||
| c81a3633de | |||
| 5883ed6426 | |||
| 7e70288662 | |||
| 24299a955a | |||
| 49856657ca | |||
| 16ef2fc9f1 | |||
| 32f7a6642a | |||
| 4d5c95b119 | |||
| 6da116acb3 | |||
| 34b7d0c2a3 | |||
| cb06cbbb61 | |||
| a0eb2be4bd | |||
| ce9195272d | |||
| d6bb9fca21 | |||
| 4f6053172d | |||
| bbaf3c46b3 | |||
| ccaed156bb | |||
| dcf8ada486 | |||
| 9d560692dc | |||
| 9d2dd2eabb | |||
| 16c0cde526 | |||
| 7189dccd89 | |||
| 044553abcb | |||
| f2bc48bc52 | |||
| 93d3878b07 | |||
| cae8cde53f | |||
| 394944e11a | |||
| fb004657eb | |||
| 9d84716278 | |||
| 461272d02a | |||
| 7a8ae9e175 | |||
| 31a22416ee | |||
| f08e77102f | |||
| 6604c1b412 | |||
| 2ab1ae04c1 | |||
| 902ebc48ff | |||
| 54efc5fd5b | |||
| 6f3ccda0ed | |||
| 04da402847 | |||
| d8c8310a48 | |||
| fd508b7e6c | |||
| 3c4f1c16db | |||
| fa29c21dfb | |||
| 15f38f009f | |||
| b34aa5e73a | |||
| d63733bb5a | |||
| d9144e3708 | |||
| 072a5c3210 | |||
| ed2dc72c75 | |||
| 56397dd0d2 | |||
| 9deac27f11 | |||
| 637ad2e215 | |||
| 650cbffc8a | |||
| c8fcde656e | |||
| 10d0a65637 | |||
| 35053bbc85 | |||
| d7cbafba50 | |||
| e9052de0e6 | |||
| e9231691fd | |||
| 191d805afa | |||
| 826b0e4b98 | |||
| 1abee5149c | |||
| ed148ce3d6 | |||
| ddf009293a | |||
| c6bb949224 | |||
| 2ff163067a | |||
| 88ecf8d20b | |||
| 96b2e8d97a | |||
| 29cdaa382e | |||
|
|
1ff3673adb | ||
|
|
f54d12b729 | ||
| e063cf1fd9 | |||
| 8170e1d762 | |||
| 254383b006 | |||
| df431e533a | |||
| 9a4cc0cbaf | |||
| 861cf7e166 | |||
| 7e34b3b91e | |||
| 29d36484f9 | |||
| ba1ebcd6ba | |||
|
|
cc655b0acd | ||
| 2c6e8e4d16 | |||
| fab2886684 | |||
| d9ccf71b21 | |||
| f36f34f212 | |||
| ff10432c79 | |||
| 776e1e4890 | |||
| db0643fa19 | |||
| 3eeb563ca1 | |||
| 7a88b1f7ee | |||
| b5411e9c6c | |||
| 07b260dea6 | |||
| 71ad32de31 | |||
| ecd2c2722f | |||
| ff1e467ada | |||
| 3f5c9d0ca1 | |||
|
|
538825f0ef | ||
| 24f68b4a8e | |||
| e51e90aabc | |||
| dc2c27f4bd | |||
|
|
406d8eef51 | ||
| 1fba599c79 | |||
| a668a16035 | |||
| f89b8e1977 | |||
| 11290062c0 | |||
| f46910fac6 | |||
| f974c5ddd1 | |||
| a01963a125 | |||
| 8a877ee465 | |||
| c370e656f1 | |||
| 58ed976737 | |||
| 1b6af73a0c | |||
| 70fe23857b | |||
| 0027af2d36 | |||
| 1a8f70f501 | |||
| f0de0a29da | |||
|
|
d4227f2b8f | ||
| aa67c11050 | |||
| 7b38d0aa2b | |||
| 64e31fad54 | |||
| 49a70e2341 | |||
| 9659f2a68a | |||
| d474868116 | |||
| b1312c4164 | |||
| 33856f9927 | |||
| 02ab3d8cae | |||
| 7974c58fd5 | |||
| 503d9dfb5f | |||
| 62b035f6c5 | |||
| 40c70fbf19 | |||
| 49bd66ccab | |||
| 9b251169a5 | |||
| aa29c45094 | |||
| bd60fda05a | |||
| 8ecbdb91b2 | |||
| cb1c68f295 | |||
| 421a25ec31 | |||
| 2d122a918f | |||
| 100cb06ba0 | |||
| 6125b036bf | |||
| 3fe3fc09b0 | |||
| 96d5b09391 | |||
| 84aecda916 | |||
| 0803a92a66 | |||
| 7f55aaf85d | |||
| 3853e2daa2 | |||
| 852fbf5ae8 | |||
| 4e7a725fee | |||
| 698d138642 | |||
| 8efb60652b | |||
| fe60b98cb8 | |||
| 63442e9af6 | |||
| 703e32a30e | |||
| 4ddfe4a54c | |||
| fb2b4d6920 | |||
| 496b49ccb3 | |||
| b3efcf19d9 | |||
| 0903ec606b | |||
| 6cfa29e3dd | |||
| 0519ed26de | |||
| aacdb72d6a | |||
| 3283dd7290 | |||
| 937c5cb7a7 | |||
| 225b7f02ad | |||
| 6258e07f20 | |||
| 622198a09e | |||
| 49b382fe1f | |||
| 5a6dc5a5b2 | |||
| 4bc70eca68 | |||
| 63fee081e6 | |||
| e45b72dcf9 | |||
| 021ad5e804 | |||
| 8e0c964883 | |||
| d6e945741a | |||
| 3a3306240f | |||
| 110dd36166 | |||
| 065cac62af | |||
| 563afa1e6f | |||
| be2adff57d | |||
| adc7ee606e | |||
| a764f381c9 | |||
| 590ccdd09a | |||
| 0f0a49f74f | |||
| a1a5028858 | |||
| 1792952039 | |||
| 9e62eb53cb | |||
| f3c4b012b0 | |||
| cd00d35f22 | |||
| 7e1c65b470 | |||
| 4247ae7740 | |||
| a5954ed5c8 | |||
| d08544b892 | |||
| f6f86deb7f | |||
| 16f5817a31 | |||
| d5d9f44a5f | |||
| 83bc3b418b | |||
| 205f0a1629 | |||
| a1c2942208 | |||
|
|
4ef3e877ce | ||
| 7dba2518f9 | |||
|
|
7506a0201e | ||
| 91fb815153 | |||
| 6faf8bc733 | |||
| bdff5b7aec | |||
| 5af8060d7b | |||
|
|
6ed8ff1d52 | ||
|
|
3324ed6e4a | ||
| 67fd9d284b | |||
|
|
08f26dd21d |
4
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
4
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -1,13 +1,13 @@
|
|||||||
name: Bug Report
|
name: Bug Report
|
||||||
description: File a bug report
|
description: File a bug report
|
||||||
title: "[It broke]: "
|
title: "[Tranga broke]: <title>"
|
||||||
labels: ["bug"]
|
labels: ["bug"]
|
||||||
body:
|
body:
|
||||||
- type: textarea
|
- type: textarea
|
||||||
attributes:
|
attributes:
|
||||||
label: What is broken?
|
label: What is broken?
|
||||||
description: What happened? How did we get here?
|
description: What happened? How did we get here?
|
||||||
placeholder: The place where you tell me what you expected to happen, and what happened instead.
|
placeholder: Tell me what you expected to happen, and what happened instead.
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: textarea
|
- type: textarea
|
||||||
|
|||||||
13
.github/ISSUE_TEMPLATE/new_connector.yml
vendored
13
.github/ISSUE_TEMPLATE/new_connector.yml
vendored
@@ -1,6 +1,6 @@
|
|||||||
name: New Connector Request
|
name: New Connector Request
|
||||||
description: Request a new site to be added
|
description: Request a new site to be added
|
||||||
title: "[New Connector]: "
|
title: "[New Connector]: <title>"
|
||||||
labels: ["New Connector"]
|
labels: ["New Connector"]
|
||||||
body:
|
body:
|
||||||
- type: input
|
- type: input
|
||||||
@@ -9,15 +9,12 @@ body:
|
|||||||
placeholder: https://
|
placeholder: https://
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: checkboxes
|
|
||||||
attributes:
|
|
||||||
label: Is the Website free to access?
|
|
||||||
description: We can't support pay-to-use sites, or captcha-proxied sites as Cloudflare.
|
|
||||||
options:
|
|
||||||
- label: The Website is freely accessible.
|
|
||||||
required: true
|
|
||||||
- type: textarea
|
- type: textarea
|
||||||
attributes:
|
attributes:
|
||||||
label: Anything else?
|
label: Anything else?
|
||||||
validations:
|
validations:
|
||||||
required: false
|
required: false
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
If you want implement this read [Contributing](https://github.com/C9Glax/tranga#contributing). Thank you!
|
||||||
31
.github/PULL_REQUEST_TEMPLATE/new_connector.yml
vendored
Normal file
31
.github/PULL_REQUEST_TEMPLATE/new_connector.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: New Connector Implementation
|
||||||
|
description: New Connector
|
||||||
|
title: "<title>"
|
||||||
|
labels: ["New Connector"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thank you for contributing. Please make sure you have read [Contributing](https://github.com/C9Glax/tranga#contributing).
|
||||||
|
Just for the sake of completion:
|
||||||
|
- type: checkboxes
|
||||||
|
id: Contributing
|
||||||
|
attributes:
|
||||||
|
label: Contributing
|
||||||
|
description: I have checked
|
||||||
|
options:
|
||||||
|
- label: Formatting (if not done yet, mark this PR as draft)
|
||||||
|
required: false
|
||||||
|
- label: I have read https://github.com/C9Glax/tranga#if-you-want-to-add-a-new-website-connector
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: Existing Issue
|
||||||
|
placeholder: #<Issue number>
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Anything else?
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
10
.github/workflows/docker-image-cuttingedge.yml
vendored
10
.github/workflows/docker-image-cuttingedge.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
# https://github.com/docker/setup-qemu-action#usage
|
# https://github.com/docker/setup-qemu-action#usage
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
@@ -22,7 +22,7 @@ jobs:
|
|||||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v3.10.0
|
uses: docker/setup-buildx-action@v3.11.1
|
||||||
|
|
||||||
# https://github.com/docker/login-action#docker-hub
|
# https://github.com/docker/login-action#docker-hub
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
@@ -33,12 +33,12 @@ jobs:
|
|||||||
|
|
||||||
# https://github.com/docker/build-push-action#multi-platform-image
|
# https://github.com/docker/build-push-action#multi-platform-image
|
||||||
- name: Build and push API
|
- name: Build and push API
|
||||||
uses: docker/build-push-action@v6.15.0
|
uses: docker/build-push-action@v6.18.0
|
||||||
with:
|
with:
|
||||||
context: ./
|
context: ./
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
|
#platforms: linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/arm64,linux/arm/v7
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/arm64,linux/arm/v7
|
||||||
pull: true
|
pull: true
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
|
|||||||
6
.github/workflows/docker-image-master.yml
vendored
6
.github/workflows/docker-image-master.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
# https://github.com/docker/setup-qemu-action#usage
|
# https://github.com/docker/setup-qemu-action#usage
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
@@ -22,7 +22,7 @@ jobs:
|
|||||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v3.10.0
|
uses: docker/setup-buildx-action@v3.11.1
|
||||||
|
|
||||||
# https://github.com/docker/login-action#docker-hub
|
# https://github.com/docker/login-action#docker-hub
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
@@ -33,7 +33,7 @@ jobs:
|
|||||||
|
|
||||||
# https://github.com/docker/build-push-action#multi-platform-image
|
# https://github.com/docker/build-push-action#multi-platform-image
|
||||||
- name: Build and push API
|
- name: Build and push API
|
||||||
uses: docker/build-push-action@v6.15.0
|
uses: docker/build-push-action@v6.18.0
|
||||||
with:
|
with:
|
||||||
context: ./
|
context: ./
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ name: Docker Image CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "postgres-Server-V2" ]
|
branches: [ "testing" ]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -13,7 +13,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
# https://github.com/docker/setup-qemu-action#usage
|
# https://github.com/docker/setup-qemu-action#usage
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
@@ -22,7 +22,7 @@ jobs:
|
|||||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v3.10.0
|
uses: docker/setup-buildx-action@v3.11.1
|
||||||
|
|
||||||
# https://github.com/docker/login-action#docker-hub
|
# https://github.com/docker/login-action#docker-hub
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
@@ -33,13 +33,13 @@ jobs:
|
|||||||
|
|
||||||
# https://github.com/docker/build-push-action#multi-platform-image
|
# https://github.com/docker/build-push-action#multi-platform-image
|
||||||
- name: Build and push API
|
- name: Build and push API
|
||||||
uses: docker/build-push-action@v6.15.0
|
uses: docker/build-push-action@v6.18.0
|
||||||
with:
|
with:
|
||||||
context: ./
|
context: ./
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
|
#platforms: linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/arm64,linux/arm/v7
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/arm64,linux/arm/v7
|
||||||
pull: true
|
pull: true
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
glax/tranga-api:Server-V2
|
glax/tranga-api:testing
|
||||||
@@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||||
<PackageReference Include="HtmlAgilityPack" Version="1.12.0" />
|
<PackageReference Include="HtmlAgilityPack" Version="1.12.2" />
|
||||||
<PackageReference Include="log4net" Version="3.0.4" />
|
<PackageReference Include="JikanDotNet" Version="2.9.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.3" />
|
<PackageReference Include="log4net" Version="3.2.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.3" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.8" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@@ -23,16 +24,19 @@
|
|||||||
<PackageReference Include="Npgsql" Version="9.0.3" />
|
<PackageReference Include="Npgsql" Version="9.0.3" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
|
||||||
<PackageReference Include="PuppeteerSharp" Version="20.1.3" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.11" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
|
<PackageReference Include="Soenneker.Utils.String.NeedlemanWunsch" Version="3.0.978" />
|
||||||
<PackageReference Include="Soenneker.Utils.String.NeedlemanWunsch" Version="3.0.929" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="9.0.4" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="8.1.0" />
|
<PackageReference Include="System.Drawing.Common" Version="9.0.8" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="9.0.3" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Migrations\" />
|
<Folder Include="Migrations\Manga\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="Log4Net.config.xml" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace API.APIEndpointRecords;
|
|
||||||
|
|
||||||
public record DownloadAvailableChaptersJobRecord([Required]string language, [Required]ulong recurrenceTimeMs, [Required]string localLibraryId);
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
namespace API.APIEndpointRecords;
|
|
||||||
|
|
||||||
public record GotifyRecord(string endpoint, string appToken, int priority)
|
|
||||||
{
|
|
||||||
public bool Validate()
|
|
||||||
{
|
|
||||||
if (endpoint == string.Empty)
|
|
||||||
return false;
|
|
||||||
if (appToken == string.Empty)
|
|
||||||
return false;
|
|
||||||
if (priority < 0 || priority > 10)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace API.APIEndpointRecords;
|
|
||||||
|
|
||||||
public record LunaseaRecord(string id)
|
|
||||||
{
|
|
||||||
private static Regex validateRex = new(@"(?:device|user)\/[0-9a-zA-Z\-]+");
|
|
||||||
public bool Validate()
|
|
||||||
{
|
|
||||||
if (id == string.Empty)
|
|
||||||
return false;
|
|
||||||
if (!validateRex.IsMatch(id))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace API.APIEndpointRecords;
|
|
||||||
|
|
||||||
public record ModifyJobRecord(ulong? RecurrenceMs, bool? Enabled);
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace API.APIEndpointRecords;
|
|
||||||
|
|
||||||
public record NewLibraryRecord(string path, string name)
|
|
||||||
{
|
|
||||||
public bool Validate()
|
|
||||||
{
|
|
||||||
if (path.Length < 1) //TODO Better Path validation
|
|
||||||
return false;
|
|
||||||
if (name.Length < 1)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
namespace API.APIEndpointRecords;
|
|
||||||
|
|
||||||
public record NtfyRecord(string endpoint, string username, string password, string topic, int priority)
|
|
||||||
{
|
|
||||||
public bool Validate()
|
|
||||||
{
|
|
||||||
if (endpoint == string.Empty)
|
|
||||||
return false;
|
|
||||||
if (username == string.Empty)
|
|
||||||
return false;
|
|
||||||
if (password == string.Empty)
|
|
||||||
return false;
|
|
||||||
if (priority < 1 || priority > 5)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace API.APIEndpointRecords;
|
|
||||||
|
|
||||||
public record PushoverRecord(string apptoken, string user)
|
|
||||||
{
|
|
||||||
public bool Validate()
|
|
||||||
{
|
|
||||||
if (apptoken == string.Empty)
|
|
||||||
return false;
|
|
||||||
if (user == string.Empty)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
18
API/Constants.cs
Normal file
18
API/Constants.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using SixLabors.ImageSharp;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public struct Constants
|
||||||
|
{
|
||||||
|
public const string TRANGA =
|
||||||
|
"\n\n" +
|
||||||
|
" _______ v2\n" +
|
||||||
|
"|_ _|.----..---.-..-----..-----..---.-.\n" +
|
||||||
|
" | | | _|| _ || || _ || _ |\n" +
|
||||||
|
" |___| |__| |___._||__|__||___ ||___._|\n" +
|
||||||
|
" |_____| \n\n";
|
||||||
|
|
||||||
|
public static readonly Size ImageSmSize = new (225, 320);
|
||||||
|
public static readonly Size ImageMdSize = new (450, 640);
|
||||||
|
public static readonly Size ImageLgSize = new (900, 1280);
|
||||||
|
}
|
||||||
24
API/Controllers/DTOs/AltTitle.cs
Normal file
24
API/Controllers/DTOs/AltTitle.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="API.Schema.MangaContext.AltTitle"/> DTO
|
||||||
|
/// </summary>
|
||||||
|
public sealed record AltTitle(string Language, string Title)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Language of the Title
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Language of the Title")]
|
||||||
|
public string Language { get; init; } = Language;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Title
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Title")]
|
||||||
|
public string Title { get; init; } = Title;
|
||||||
|
}
|
||||||
17
API/Controllers/DTOs/Author.cs
Normal file
17
API/Controllers/DTOs/Author.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="API.Schema.MangaContext.Author"/> DTO
|
||||||
|
/// </summary>
|
||||||
|
public sealed record Author(string Key, string Name) : Identifiable(Key)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the Author.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Name of the Author.")]
|
||||||
|
public string Name { get; init; } = Name;
|
||||||
|
}
|
||||||
52
API/Controllers/DTOs/Chapter.cs
Normal file
52
API/Controllers/DTOs/Chapter.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="API.Schema.MangaContext.Chapter"/> DTO
|
||||||
|
/// </summary>
|
||||||
|
public sealed record Chapter(string Key, string MangaId, int? Volume, string ChapterNumber, string? Title, IEnumerable<MangaConnectorId> MangaConnectorIds, bool Downloaded) : Identifiable(Key)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Identifier of the Manga this Chapter belongs to
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Identifier of the Manga this Chapter belongs to")]
|
||||||
|
public string MangaId { get; init; } = MangaId;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Volume number
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Volume number")]
|
||||||
|
public int? Volume { get; init; } = Volume;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Chapter number
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Chapter number")]
|
||||||
|
public string ChapterNumber { get; init; } = ChapterNumber;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Title of the Chapter
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Title of the Chapter")]
|
||||||
|
public string? Title { get; init; } = Title;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether Chapter is Downloaded (on disk)
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Whether Chapter is Downloaded (on disk)")]
|
||||||
|
public bool Downloaded { get; init; } = Downloaded;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ids of the Manga on MangaConnectors
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Ids of the Manga on MangaConnectors")]
|
||||||
|
public IEnumerable<MangaConnectorId> MangaConnectorIds { get; init; } = MangaConnectorIds;
|
||||||
|
}
|
||||||
21
API/Controllers/DTOs/FileLibrary.cs
Normal file
21
API/Controllers/DTOs/FileLibrary.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
public sealed record FileLibrary(string Key, string BasePath, string LibraryName) : Identifiable(Key)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The directory Path of the library
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The directory Path of the library")]
|
||||||
|
public string BasePath { get; internal set; } = BasePath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Name of the library
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Name of the library")]
|
||||||
|
public string LibraryName { get; internal set; } = LibraryName;
|
||||||
|
}
|
||||||
18
API/Controllers/DTOs/Identifiable.cs
Normal file
18
API/Controllers/DTOs/Identifiable.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="API.Schema.Identifiable"/>
|
||||||
|
/// </summary>
|
||||||
|
public record Identifiable(string Key)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Unique Identifier of the DTO
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Unique Identifier of the DTO")]
|
||||||
|
[StringLength(TokenGen.MaximumLength, MinimumLength = TokenGen.MinimumLength)]
|
||||||
|
public string Key { get; init; } = Key;
|
||||||
|
}
|
||||||
23
API/Controllers/DTOs/LibraryConnector.cs
Normal file
23
API/Controllers/DTOs/LibraryConnector.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using API.Schema.LibraryContext.LibraryConnectors;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
public record LibraryConnector(string Key, string BaseUrl, LibraryType Type) : Identifiable(Key)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Url of the Library instance
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Url]
|
||||||
|
[Description("The Url of the Library instance")]
|
||||||
|
public string BaseUrl { get; init;} = BaseUrl;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="LibraryType"/>
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Library Type")]
|
||||||
|
public LibraryType Type { get; init; } = Type;
|
||||||
|
}
|
||||||
25
API/Controllers/DTOs/Link.cs
Normal file
25
API/Controllers/DTOs/Link.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="API.Schema.MangaContext.Link"/> DTO
|
||||||
|
/// </summary>
|
||||||
|
public sealed record Link(string Key, string Provider, string Url) : Identifiable(Key)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the Provider
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Name of the Provider")]
|
||||||
|
public string Provider { get; init; } = Provider;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Url
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Url")]
|
||||||
|
public string Url { get; init; } = Url;
|
||||||
|
}
|
||||||
73
API/Controllers/DTOs/Manga.cs
Normal file
73
API/Controllers/DTOs/Manga.cs
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using API.Schema.MangaContext;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="Schema.MangaContext.Manga"/> DTO
|
||||||
|
/// </summary>
|
||||||
|
public sealed record Manga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus, IEnumerable<MangaConnectorId> MangaConnectorIds, float IgnoreChaptersBefore, uint? Year, string? OriginalLanguage, IEnumerable<string> ChapterIds, IEnumerable<Author> Authors, IEnumerable<string> Tags, IEnumerable<Link> Links, IEnumerable<AltTitle> AltTitles, string? FileLibraryId)
|
||||||
|
: MinimalManga(Key, Name, Description, ReleaseStatus, MangaConnectorIds)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Chapter cutoff for Downloads (Chapters before this will not be downloaded)
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Chapter cutoff for Downloads (Chapters before this will not be downloaded)")]
|
||||||
|
public float IgnoreChaptersBefore { get; init; } = IgnoreChaptersBefore;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Release Year
|
||||||
|
/// </summary>
|
||||||
|
[Description("Release Year")]
|
||||||
|
public uint? Year { get; init; } = Year;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Release Language
|
||||||
|
/// </summary>
|
||||||
|
[Description("Release Language")]
|
||||||
|
public string? OriginalLanguage { get; init; } = OriginalLanguage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Keys of ChapterDTOs
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Keys of ChapterDTOs")]
|
||||||
|
public IEnumerable<string> ChapterIds { get; init; } = ChapterIds;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Author-names
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Author-names")]
|
||||||
|
public IEnumerable<Author> Authors { get; init; } = Authors;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Manga Tags
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Manga Tags")]
|
||||||
|
public IEnumerable<string> Tags { get; init; } = Tags;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Links for more Metadata
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Links for more Metadata")]
|
||||||
|
public IEnumerable<Link> Links { get; init; } = Links;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Alt Titles of Manga
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Alt Titles of Manga")]
|
||||||
|
public IEnumerable<AltTitle> AltTitles { get; init; } = AltTitles;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Id of the Library the Manga gets downloaded to
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Id of the Library the Manga gets downloaded to")]
|
||||||
|
public string? FileLibraryId { get; init; } = FileLibraryId;
|
||||||
|
}
|
||||||
28
API/Controllers/DTOs/MangaConnector.cs
Normal file
28
API/Controllers/DTOs/MangaConnector.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
public sealed record MangaConnector(string Name, bool Enabled, string IconUrl, string[] SupportedLanguages) : Identifiable(Name)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether Connector is used for Searches and Downloads
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Whether Connector is used for Searches and Downloads")]
|
||||||
|
public bool Enabled { get; init; } = Enabled;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Languages supported by the Connector
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Languages supported by the Connector")]
|
||||||
|
public string[] SupportedLanguages { get; init; } = SupportedLanguages;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Url of the Website Icon
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Url of the Website Icon")]
|
||||||
|
public string IconUrl { get; init; } = IconUrl;
|
||||||
|
}
|
||||||
38
API/Controllers/DTOs/MangaConnectorId.cs
Normal file
38
API/Controllers/DTOs/MangaConnectorId.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using API.Schema.MangaContext;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="MangaConnectorId{T}"/> DTO
|
||||||
|
/// </summary>
|
||||||
|
public sealed record MangaConnectorId(string Key, string MangaConnectorName, string ForeignKey, string? WebsiteUrl, bool UseForDownload) : Identifiable(Key)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the Connector
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Name of the Connector")]
|
||||||
|
public string MangaConnectorName { get; init; } = MangaConnectorName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Key of the referenced DTO
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Key of the referenced DTO")]
|
||||||
|
public string ForeignKey { get; init; } = ForeignKey;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Website Link for reference, if any
|
||||||
|
/// </summary>
|
||||||
|
[Description("Website Link for reference, if any")]
|
||||||
|
public string? WebsiteUrl { get; init; } = WebsiteUrl;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether this Link is used for downloads
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Whether this Link is used for downloads")]
|
||||||
|
public bool UseForDownload { get; init; } = UseForDownload;
|
||||||
|
}
|
||||||
39
API/Controllers/DTOs/MinimalManga.cs
Normal file
39
API/Controllers/DTOs/MinimalManga.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using API.Schema.MangaContext;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shortened Version of <see cref="Manga"/>
|
||||||
|
/// </summary>
|
||||||
|
public record MinimalManga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus, IEnumerable<MangaConnectorId> MangaConnectorIds) : Identifiable(Key)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the Manga
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Name of the Manga")]
|
||||||
|
public string Name { get; init; } = Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Description of the Manga
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Description of the Manga")]
|
||||||
|
public string Description { get; init; } = Description;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ReleaseStatus of the Manga
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("ReleaseStatus of the Manga")]
|
||||||
|
public MangaReleaseStatus ReleaseStatus { get; init; } = ReleaseStatus;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ids of the Manga on MangaConnectors
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Ids of the Manga on MangaConnectors")]
|
||||||
|
public IEnumerable<MangaConnectorId> MangaConnectorIds { get; init; } = MangaConnectorIds;
|
||||||
|
}
|
||||||
46
API/Controllers/DTOs/NotificationConnector.cs
Normal file
46
API/Controllers/DTOs/NotificationConnector.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
public record NotificationConnector(string Name, string Url, string HttpMethod, string Body, Dictionary<string, string> Headers) : Identifiable(Name)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Name of the Notification Connector
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Name of the Notification Connector")]
|
||||||
|
public string Name { get; init; } = Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Url of the Instance
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Formatting placeholders: "%title" and "%text" will be replaced when notifications are sent</remarks>
|
||||||
|
[Required]
|
||||||
|
[Url]
|
||||||
|
[Description("The Url of the Instance")]
|
||||||
|
public string Url { get; internal set; } = Url;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The HTTP Request Method to use for notifications
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The HTTP Request Method to use for notifications")]
|
||||||
|
public string HttpMethod { get; internal set; } = HttpMethod;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Request Body to use to send notifications
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Formatting placeholders: "%title" and "%text" will be replaced when notifications are sent</remarks>
|
||||||
|
[Required]
|
||||||
|
[Description("The Request Body to use to send notifications")]
|
||||||
|
public string Body { get; internal set; } = Body;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Request Headers to use to send notifications
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Formatting placeholders: "%title" and "%text" will be replaced when notifications are sent</remarks>
|
||||||
|
[Required]
|
||||||
|
[Description("The Request Headers to use to send notifications")]
|
||||||
|
public Dictionary<string, string> Headers { get; internal set; } = Headers;
|
||||||
|
}
|
||||||
33
API/Controllers/DTOs/PeriodicWorker.cs
Normal file
33
API/Controllers/DTOs/PeriodicWorker.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using API.Workers;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="IPeriodic"/> DTO (<seealso cref="Worker"/> <seealso cref="BaseWorker"/>)
|
||||||
|
/// </summary>
|
||||||
|
public sealed record PeriodicWorker(string Key, IEnumerable<string> Dependencies, IEnumerable<string> MissingDependencies, bool DependenciesFulfilled, WorkerExecutionState State, DateTime LastExecution, TimeSpan Interval, DateTime NextExecution)
|
||||||
|
: Worker(Key, Dependencies, MissingDependencies, DependenciesFulfilled, State)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Timestamp when Worker executed last.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Timestamp when Worker executed last.")]
|
||||||
|
public DateTime LastExecution { get; init; } = LastExecution;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interval at which Worker runs.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Interval at which Worker runs.")]
|
||||||
|
public TimeSpan Interval { get; init; } = Interval;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Timestamp when Worker is scheduled to execute next.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Timestamp when Worker is scheduled to execute next.")]
|
||||||
|
public DateTime NextExecution { get; init; } = LastExecution;
|
||||||
|
}
|
||||||
39
API/Controllers/DTOs/Worker.cs
Normal file
39
API/Controllers/DTOs/Worker.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using API.Workers;
|
||||||
|
|
||||||
|
namespace API.Controllers.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="BaseWorker"/> DTO
|
||||||
|
/// </summary>
|
||||||
|
public record Worker(string Key, IEnumerable<string> Dependencies, IEnumerable<string> MissingDependencies, bool DependenciesFulfilled, WorkerExecutionState State) : Identifiable(Key)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Workers this worker depends on having ran.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Workers this worker depends on having ran.")]
|
||||||
|
public IEnumerable<string> Dependencies { get; init; } = Dependencies;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Workers that have not yet ran, that need to run for this Worker to run.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Workers that have not yet ran, that need to run for this Worker to run.")]
|
||||||
|
public IEnumerable<string> MissingDependencies { get; init; } = MissingDependencies;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Worker can run.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Worker can run.")]
|
||||||
|
public bool DependenciesFulfilled { get; init; } = DependenciesFulfilled;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Execution state of the Worker.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("Execution state of the Worker.")]
|
||||||
|
public WorkerExecutionState State { get; init; } = State;
|
||||||
|
}
|
||||||
147
API/Controllers/FileLibraryController.cs
Normal file
147
API/Controllers/FileLibraryController.cs
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
using API.Controllers.Requests;
|
||||||
|
using API.Schema.MangaContext;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
using FileLibrary = API.Controllers.DTOs.FileLibrary;
|
||||||
|
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
|
public class FileLibraryController(MangaContext context) : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all <see cref="DTOs.FileLibrary"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType<List<FileLibrary>>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public async Task<Results<Ok<List<FileLibrary>>, InternalServerError>> GetFileLibraries ()
|
||||||
|
{
|
||||||
|
if (await context.FileLibraries.ToListAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
List<FileLibrary> fileLibraries = result.Select(f => new FileLibrary(f.Key, f.BasePath, f.LibraryName)).ToList();
|
||||||
|
|
||||||
|
return TypedResults.Ok(fileLibraries);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns <see cref="FileLibrary"/> with <paramref name="FileLibraryId"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="FileLibraryId"><see cref="FileLibrary"/>.Key</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="FileLibrary"/> with <paramref name="FileLibraryId"/> not found.</response>
|
||||||
|
[HttpGet("{FileLibraryId}")]
|
||||||
|
[ProducesResponseType<FileLibrary>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
public async Task<Results<Ok<FileLibrary>, NotFound<string>>> GetFileLibrary (string FileLibraryId)
|
||||||
|
{
|
||||||
|
if(await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == FileLibraryId, HttpContext.RequestAborted) is not { } library)
|
||||||
|
return TypedResults.NotFound(nameof(FileLibraryId));
|
||||||
|
|
||||||
|
return TypedResults.Ok(new FileLibrary(library.Key, library.BasePath, library.LibraryName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the <see cref="FileLibraryId"/>.BasePath with <paramref name="FileLibraryId"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="FileLibraryId"><see cref="FileLibrary"/>.Key</param>
|
||||||
|
/// <param name="newBasePath">New <see cref="FileLibraryId"/>.BasePath</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="FileLibrary"/> with <paramref name="FileLibraryId"/> not found.</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpPatch("{FileLibraryId}/ChangeBasePath")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
|
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> ChangeLibraryBasePath (string FileLibraryId, [FromBody]string newBasePath)
|
||||||
|
{
|
||||||
|
if(await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == FileLibraryId, HttpContext.RequestAborted) is not { } library)
|
||||||
|
return TypedResults.NotFound(nameof(FileLibraryId));
|
||||||
|
|
||||||
|
//TODO Path check
|
||||||
|
library.BasePath = newBasePath;
|
||||||
|
|
||||||
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the <see cref="FileLibraryId"/>.LibraryName with <paramref name="FileLibraryId"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="FileLibraryId"><see cref="FileLibrary"/>.Key</param>
|
||||||
|
/// <param name="newName">New <see cref="FileLibraryId"/>.LibraryName</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="FileLibrary"/> with <paramref name="FileLibraryId"/> not found.</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpPatch("{FileLibraryId}/ChangeName")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
|
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> ChangeLibraryName (string FileLibraryId, [FromBody] string newName)
|
||||||
|
{
|
||||||
|
if(await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == FileLibraryId, HttpContext.RequestAborted) is not { } library)
|
||||||
|
return TypedResults.NotFound(nameof(FileLibraryId));
|
||||||
|
|
||||||
|
//TODO Name check
|
||||||
|
library.LibraryName = newName;
|
||||||
|
|
||||||
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates new <see cref="FileLibrary"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="requestData">New <see cref="FileLibrary"/> to add</param>
|
||||||
|
/// <response code="200">Key of new Library</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpPut]
|
||||||
|
[ProducesResponseType<string>(Status201Created, "text/plain")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
|
public async Task<Results<Created<string>, InternalServerError<string>>> CreateNewLibrary ([FromBody]CreateLibraryRecord requestData)
|
||||||
|
{
|
||||||
|
//TODO Parameter check
|
||||||
|
Schema.MangaContext.FileLibrary library = new Schema.MangaContext.FileLibrary(requestData.BasePath, requestData.LibraryName);
|
||||||
|
context.FileLibraries.Add(library);
|
||||||
|
|
||||||
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
|
|
||||||
|
return TypedResults.Created(string.Empty, library.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the <see cref="FileLibraryId"/>.LibraryName with <paramref name="FileLibraryId"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="FileLibraryId"><see cref="FileLibrary"/>.Key</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="FileLibrary"/> with <paramref name="FileLibraryId"/> not found.</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpDelete("{FileLibraryId}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
|
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> DeleteLocalLibrary (string FileLibraryId)
|
||||||
|
{
|
||||||
|
if(await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == FileLibraryId, HttpContext.RequestAborted) is not { } library)
|
||||||
|
return TypedResults.NotFound(nameof(FileLibraryId));
|
||||||
|
|
||||||
|
context.FileLibraries.Remove(library);
|
||||||
|
|
||||||
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,364 +0,0 @@
|
|||||||
using API.APIEndpointRecords;
|
|
||||||
using API.Schema;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
using API.Schema.Jobs;
|
|
||||||
using Asp.Versioning;
|
|
||||||
using log4net;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
|
||||||
// ReSharper disable InconsistentNaming
|
|
||||||
|
|
||||||
namespace API.Controllers;
|
|
||||||
|
|
||||||
[ApiVersion(2)]
|
|
||||||
[ApiController]
|
|
||||||
[Route("v{version:apiVersion}/[controller]")]
|
|
||||||
public class JobController(PgsqlContext context, ILog Log) : Controller
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Returns all Jobs
|
|
||||||
/// </summary>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
[HttpGet]
|
|
||||||
[ProducesResponseType<Job[]>(Status200OK, "application/json")]
|
|
||||||
public IActionResult GetAllJobs()
|
|
||||||
{
|
|
||||||
Job[] ret = context.Jobs.ToArray();
|
|
||||||
return Ok(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns Jobs with requested Job-IDs
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ids">Array of Job-IDs</param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
[HttpPost("WithIDs")]
|
|
||||||
[ProducesResponseType<Job[]>(Status200OK, "application/json")]
|
|
||||||
public IActionResult GetJobs([FromBody]string[] ids)
|
|
||||||
{
|
|
||||||
Job[] ret = context.Jobs.Where(job => ids.Contains(job.JobId)).ToArray();
|
|
||||||
return Ok(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get all Jobs in requested State
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="JobState">Requested Job-State</param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
[HttpGet("State/{JobState}")]
|
|
||||||
[ProducesResponseType<Job[]>(Status200OK, "application/json")]
|
|
||||||
public IActionResult GetJobsInState(JobState JobState)
|
|
||||||
{
|
|
||||||
Job[] jobsInState = context.Jobs.Where(job => job.state == JobState).ToArray();
|
|
||||||
return Ok(jobsInState);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns all Jobs of requested Type
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="JobType">Requested Job-Type</param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
[HttpGet("Type/{JobType}")]
|
|
||||||
[ProducesResponseType<Job[]>(Status200OK, "application/json")]
|
|
||||||
public IActionResult GetJobsOfType(JobType JobType)
|
|
||||||
{
|
|
||||||
Job[] jobsOfType = context.Jobs.Where(job => job.JobType == JobType).ToArray();
|
|
||||||
return Ok(jobsOfType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns all Jobs of requested Type and State
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="JobType">Requested Job-Type</param>
|
|
||||||
/// <param name="JobState">Requested Job-State</param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
[HttpGet("TypeAndState/{JobType}/{JobState}")]
|
|
||||||
[ProducesResponseType<Job[]>(Status200OK, "application/json")]
|
|
||||||
public IActionResult GetJobsOfType(JobType JobType, JobState JobState)
|
|
||||||
{
|
|
||||||
Job[] jobsOfType = context.Jobs.Where(job => job.JobType == JobType && job.state == JobState).ToArray();
|
|
||||||
return Ok(jobsOfType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Return Job with ID
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="JobId">Job-ID</param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
/// <response code="404">Job with ID could not be found</response>
|
|
||||||
[HttpGet("{JobId}")]
|
|
||||||
[ProducesResponseType<Job>(Status200OK, "application/json")]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
public IActionResult GetJob(string JobId)
|
|
||||||
{
|
|
||||||
Job? ret = context.Jobs.Find(JobId);
|
|
||||||
return (ret is not null) switch
|
|
||||||
{
|
|
||||||
true => Ok(ret),
|
|
||||||
false => NotFound()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new DownloadAvailableChaptersJob
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="MangaId">ID of Manga</param>
|
|
||||||
/// <param name="record">Job-Configuration</param>
|
|
||||||
/// <response code="201">Job-IDs</response>
|
|
||||||
/// <response code="400">Could not find ToLibrary with ID</response>
|
|
||||||
/// <response code="404">Could not find Manga with ID</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPut("DownloadAvailableChaptersJob/{MangaId}")]
|
|
||||||
[ProducesResponseType<string[]>(Status201Created, "application/json")]
|
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult CreateDownloadAvailableChaptersJob(string MangaId, [FromBody]DownloadAvailableChaptersJobRecord record)
|
|
||||||
{
|
|
||||||
if (context.Mangas.Find(MangaId) is not { } m)
|
|
||||||
return NotFound();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
LocalLibrary? l = context.LocalLibraries.Find(record.localLibraryId);
|
|
||||||
if (l is null)
|
|
||||||
return BadRequest();
|
|
||||||
m.Library = l;
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Job retrieveChapters = new RetrieveChaptersJob(m, record.language, record.recurrenceTimeMs);
|
|
||||||
Job downloadChapters = new DownloadAvailableChaptersJob(m, record.recurrenceTimeMs, dependsOnJobs: [retrieveChapters]);
|
|
||||||
return AddJobs([retrieveChapters, downloadChapters]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new DownloadSingleChapterJob
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ChapterId">ID of the Chapter</param>
|
|
||||||
/// <response code="201">Job-IDs</response>
|
|
||||||
/// <response code="404">Could not find Chapter with ID</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPut("DownloadSingleChapterJob/{ChapterId}")]
|
|
||||||
[ProducesResponseType<string[]>(Status201Created, "application/json")]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult CreateNewDownloadChapterJob(string ChapterId)
|
|
||||||
{
|
|
||||||
if(context.Chapters.Find(ChapterId) is not { } c)
|
|
||||||
return NotFound();
|
|
||||||
Job job = new DownloadSingleChapterJob(c);
|
|
||||||
return AddJobs([job]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new UpdateFilesDownloadedJob
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="MangaId">ID of the Manga</param>
|
|
||||||
/// <response code="201">Job-IDs</response>
|
|
||||||
/// <response code="201">Could not find Manga with ID</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPut("UpdateFilesJob/{MangaId}")]
|
|
||||||
[ProducesResponseType<string[]>(Status201Created, "application/json")]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult CreateUpdateFilesDownloadedJob(string MangaId)
|
|
||||||
{
|
|
||||||
if(context.Mangas.Find(MangaId) is not { } m)
|
|
||||||
return NotFound();
|
|
||||||
Job job = new UpdateFilesDownloadedJob(m, 0);
|
|
||||||
return AddJobs([job]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new UpdateMetadataJob for all Manga
|
|
||||||
/// </summary>
|
|
||||||
/// <response code="201">Job-IDs</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPut("UpdateAllFilesJob")]
|
|
||||||
[ProducesResponseType<string[]>(Status201Created, "application/json")]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult CreateUpdateAllFilesDownloadedJob()
|
|
||||||
{
|
|
||||||
List<UpdateFilesDownloadedJob> jobs = context.Mangas.Select(m => new UpdateFilesDownloadedJob(m, 0, null, null)).ToList();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
context.Jobs.AddRange(jobs);
|
|
||||||
context.SaveChanges();
|
|
||||||
return Created();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Not Implemented: Create a new UpdateMetadataJob
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="MangaId">ID of the Manga</param>
|
|
||||||
/// <response code="201">Job-IDs</response>
|
|
||||||
/// <response code="404">Could not find Manga with ID</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPut("UpdateMetadataJob/{MangaId}")]
|
|
||||||
[ProducesResponseType<string[]>(Status201Created, "application/json")]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult CreateUpdateMetadataJob(string MangaId)
|
|
||||||
{
|
|
||||||
return StatusCode(Status501NotImplemented);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Not Implemented: Create a new UpdateMetadataJob for all Manga
|
|
||||||
/// </summary>
|
|
||||||
/// <response code="201">Job-IDs</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPut("UpdateAllMetadataJob")]
|
|
||||||
[ProducesResponseType<string[]>(Status201Created, "application/json")]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult CreateUpdateAllMetadataJob()
|
|
||||||
{
|
|
||||||
return StatusCode(Status501NotImplemented);
|
|
||||||
}
|
|
||||||
|
|
||||||
private IActionResult AddJobs(Job[] jobs)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
context.Jobs.AddRange(jobs);
|
|
||||||
context.SaveChanges();
|
|
||||||
return new CreatedResult((string?)null, jobs.Select(j => j.JobId).ToArray());
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Delete Job with ID and all children
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="JobId">Job-ID</param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
/// <response code="404">Job could not be found</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpDelete("{JobId}")]
|
|
||||||
[ProducesResponseType(Status200OK)]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult DeleteJob(string JobId)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if(context.Jobs.Find(JobId) is not { } ret)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
context.Remove(ret);
|
|
||||||
context.SaveChanges();
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IQueryable<Job> GetChildJobs(string parentJobId)
|
|
||||||
{
|
|
||||||
IQueryable<Job> children = context.Jobs.Where(j => j.ParentJobId == parentJobId);
|
|
||||||
foreach (Job child in children)
|
|
||||||
foreach (Job grandChild in GetChildJobs(child.JobId))
|
|
||||||
children.Append(grandChild);
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Modify Job with ID
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="JobId">Job-ID</param>
|
|
||||||
/// <param name="modifyJobRecord">Fields to modify, set to null to keep previous value</param>
|
|
||||||
/// <response code="202">Job modified</response>
|
|
||||||
/// <response code="400">Malformed request</response>
|
|
||||||
/// <response code="404">Job with ID not found</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPatch("{JobId}")]
|
|
||||||
[ProducesResponseType<Job>(Status202Accepted, "application/json")]
|
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult ModifyJob(string JobId, [FromBody]ModifyJobRecord modifyJobRecord)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Job? ret = context.Jobs.Find(JobId);
|
|
||||||
if(ret is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
ret.RecurrenceMs = modifyJobRecord.RecurrenceMs ?? ret.RecurrenceMs;
|
|
||||||
ret.Enabled = modifyJobRecord.Enabled ?? ret.Enabled;
|
|
||||||
|
|
||||||
context.SaveChanges();
|
|
||||||
return new AcceptedResult(ret.JobId, ret);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Starts the Job with the requested ID
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="JobId">Job-ID</param>
|
|
||||||
/// <response code="202">Job started</response>
|
|
||||||
/// <response code="404">Job with ID not found</response>
|
|
||||||
/// <response code="409">Job was already running</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPost("{JobId}/Start")]
|
|
||||||
[ProducesResponseType(Status202Accepted)]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType(Status409Conflict)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult StartJob(string JobId)
|
|
||||||
{
|
|
||||||
Job? ret = context.Jobs.Find(JobId);
|
|
||||||
if (ret is null)
|
|
||||||
return NotFound();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (ret.state >= JobState.Running && ret.state < JobState.Completed)
|
|
||||||
return new ConflictResult();
|
|
||||||
ret.LastExecution = DateTime.UnixEpoch;
|
|
||||||
context.SaveChanges();
|
|
||||||
return Accepted();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Stops the Job with the requested ID
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="JobId">Job-ID</param>
|
|
||||||
/// <remarks><h1>NOT IMPLEMENTED</h1></remarks>
|
|
||||||
[HttpPost("{JobId}/Stop")]
|
|
||||||
[ProducesResponseType(Status501NotImplemented)]
|
|
||||||
public IActionResult StopJob(string JobId)
|
|
||||||
{
|
|
||||||
return StatusCode(Status501NotImplemented);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,100 +1,102 @@
|
|||||||
using API.Schema;
|
using API.Controllers.Requests;
|
||||||
using API.Schema.Contexts;
|
using API.Schema.LibraryContext;
|
||||||
using API.Schema.LibraryConnectors;
|
using API.Schema.LibraryContext.LibraryConnectors;
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using log4net;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
using LibraryConnector = API.Controllers.DTOs.LibraryConnector;
|
||||||
|
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
|
|
||||||
[ApiVersion(2)]
|
[ApiVersion(2)]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("v{v:apiVersion}/[controller]")]
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
public class LibraryConnectorController(LibraryContext context, ILog Log) : Controller
|
public class LibraryConnectorController(LibraryContext context) : Controller
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all configured ToLibrary-Connectors
|
/// Gets all configured <see cref="DTOs.LibraryConnector"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType<LibraryConnector[]>(Status200OK, "application/json")]
|
[ProducesResponseType<List<LibraryConnector>>(Status200OK, "application/json")]
|
||||||
public IActionResult GetAllConnectors()
|
public async Task<Results<Ok<List<LibraryConnector>>, InternalServerError>> GetAllConnectors ()
|
||||||
{
|
{
|
||||||
LibraryConnector[] connectors = context.LibraryConnectors.ToArray();
|
if (await context.LibraryConnectors.ToListAsync(HttpContext.RequestAborted) is not { } connectors)
|
||||||
return Ok(connectors);
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
List<LibraryConnector> libraryConnectors = connectors.Select(c => new LibraryConnector(c.Key, c.BaseUrl, c.LibraryType)).ToList();
|
||||||
|
|
||||||
|
return TypedResults.Ok(libraryConnectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns ToLibrary-Connector with requested ID
|
/// Returns <see cref="LibraryConnector"/> with <paramref name="LibraryConnectorId"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="LibraryControllerId">ToLibrary-Connector-ID</param>
|
/// <param name="LibraryConnectorId"><see cref="LibraryConnector"/>.Key</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="404">Connector with ID not found.</response>
|
/// <response code="404"><see cref="LibraryConnector"/> with <paramref name="LibraryConnectorId"/> not found.</response>
|
||||||
[HttpGet("{LibraryControllerId}")]
|
[HttpGet("{LibraryConnectorId}")]
|
||||||
[ProducesResponseType<LibraryConnector>(Status200OK, "application/json")]
|
[ProducesResponseType<LibraryConnector>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
public IActionResult GetConnector(string LibraryControllerId)
|
public async Task<Results<Ok<LibraryConnector>, NotFound<string>>> GetConnector (string LibraryConnectorId)
|
||||||
{
|
{
|
||||||
LibraryConnector? ret = context.LibraryConnectors.Find(LibraryControllerId);
|
if (await context.LibraryConnectors.FirstOrDefaultAsync(l => l.Key == LibraryConnectorId) is not { } connector)
|
||||||
return (ret is not null) switch
|
return TypedResults.NotFound(nameof(LibraryConnectorId));
|
||||||
{
|
|
||||||
true => Ok(ret),
|
return TypedResults.Ok(new LibraryConnector(connector.Key, connector.BaseUrl, connector.LibraryType));
|
||||||
false => NotFound()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new ToLibrary-Connector
|
/// Creates a new <see cref="LibraryConnector"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="libraryConnector">ToLibrary-Connector</param>
|
/// <param name="requestData"></param>
|
||||||
/// <response code="201"></response>
|
/// <response code="201"></response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
[ProducesResponseType(Status201Created)]
|
[ProducesResponseType<string>(Status201Created, "text/plain")]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult CreateConnector([FromBody]LibraryConnector libraryConnector)
|
public async Task<Results<Created<string>, InternalServerError<string>>> CreateConnector ([FromBody]CreateLibraryConnectorRecord requestData)
|
||||||
{
|
{
|
||||||
try
|
//TODO verify data
|
||||||
|
API.Schema.LibraryContext.LibraryConnectors.LibraryConnector connector = requestData.LibraryType switch
|
||||||
{
|
{
|
||||||
context.LibraryConnectors.Add(libraryConnector);
|
LibraryType.Kavita => new Kavita(requestData.Url, requestData.Username, requestData.Password),
|
||||||
context.SaveChanges();
|
LibraryType.Komga => new Komga(requestData.Url, requestData.Username, requestData.Password),
|
||||||
return Created();
|
_ => throw new NotImplementedException()
|
||||||
}
|
};
|
||||||
catch (Exception e)
|
|
||||||
{
|
context.LibraryConnectors.Add(connector);
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
}
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
|
return TypedResults.Created(string.Empty, connector.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes the ToLibrary-Connector with the requested ID
|
/// Deletes <see cref="LibraryConnector"/> with <paramref name="LibraryConnectorId"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="LibraryControllerId">ToLibrary-Connector-ID</param>
|
/// <param name="LibraryConnectorId">ToFileLibrary-Connector-ID</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="404">Connector with ID not found.</response>
|
/// <response code="404"><see cref="LibraryConnector"/> with <paramref name="LibraryConnectorId"/> not found.</response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpDelete("{LibraryControllerId}")]
|
[HttpDelete("{LibraryConnectorId}")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult DeleteConnector(string LibraryControllerId)
|
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> DeleteConnector (string LibraryConnectorId)
|
||||||
{
|
{
|
||||||
try
|
if (await context.LibraryConnectors.FirstOrDefaultAsync(l => l.Key == LibraryConnectorId) is not { } connector)
|
||||||
{
|
return TypedResults.NotFound(nameof(LibraryConnectorId));
|
||||||
LibraryConnector? ret = context.LibraryConnectors.Find(LibraryControllerId);
|
|
||||||
if (ret is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
context.Remove(ret);
|
context.LibraryConnectors.Remove(connector);
|
||||||
context.SaveChanges();
|
|
||||||
return Ok();
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
}
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
catch (Exception e)
|
return TypedResults.Ok();
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,164 +0,0 @@
|
|||||||
using API.APIEndpointRecords;
|
|
||||||
using API.Schema;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
using Asp.Versioning;
|
|
||||||
using log4net;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
|
||||||
|
|
||||||
namespace API.Controllers;
|
|
||||||
|
|
||||||
[ApiVersion(2)]
|
|
||||||
[ApiController]
|
|
||||||
[Route("v{v:apiVersion}/[controller]")]
|
|
||||||
public class LocalLibrariesController(PgsqlContext context, ILog Log) : Controller
|
|
||||||
{
|
|
||||||
[HttpGet]
|
|
||||||
[ProducesResponseType<LocalLibrary[]>(Status200OK, "application/json")]
|
|
||||||
public IActionResult GetLocalLibraries()
|
|
||||||
{
|
|
||||||
return Ok(context.LocalLibraries);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{LibraryId}")]
|
|
||||||
[ProducesResponseType<LocalLibrary>(Status200OK, "application/json")]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
public IActionResult GetLocalLibrary(string LibraryId)
|
|
||||||
{
|
|
||||||
LocalLibrary? library = context.LocalLibraries.Find(LibraryId);
|
|
||||||
if (library is null)
|
|
||||||
return NotFound();
|
|
||||||
return Ok(library);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPatch("{LibraryId}")]
|
|
||||||
[ProducesResponseType(Status200OK)]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult UpdateLocalLibrary(string LibraryId, [FromBody]NewLibraryRecord record)
|
|
||||||
{
|
|
||||||
LocalLibrary? library = context.LocalLibraries.Find(LibraryId);
|
|
||||||
if (library is null)
|
|
||||||
return NotFound();
|
|
||||||
if (record.Validate() == false)
|
|
||||||
return BadRequest();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
library.LibraryName = record.name;
|
|
||||||
library.BasePath = record.path;
|
|
||||||
context.SaveChanges();
|
|
||||||
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPatch("{LibraryId}/ChangeBasePath")]
|
|
||||||
[ProducesResponseType(Status200OK)]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult ChangeLibraryBasePath(string LibraryId, [FromBody] string newBasePath)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
LocalLibrary? library = context.LocalLibraries.Find(LibraryId);
|
|
||||||
if (library is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
if (false) //TODO implement path check
|
|
||||||
return BadRequest();
|
|
||||||
|
|
||||||
library.BasePath = newBasePath;
|
|
||||||
context.SaveChanges();
|
|
||||||
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPatch("{LibraryId}/ChangeName")]
|
|
||||||
[ProducesResponseType(Status200OK)]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult ChangeLibraryName(string LibraryId, [FromBody] string newName)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
LocalLibrary? library = context.LocalLibraries.Find(LibraryId);
|
|
||||||
if (library is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
if(newName.Length < 1)
|
|
||||||
return BadRequest();
|
|
||||||
|
|
||||||
library.LibraryName = newName;
|
|
||||||
context.SaveChanges();
|
|
||||||
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPut]
|
|
||||||
[ProducesResponseType<LocalLibrary>(Status200OK, "application/json")]
|
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult CreateNewLibrary([FromBody]NewLibraryRecord library)
|
|
||||||
{
|
|
||||||
if (library.Validate() == false)
|
|
||||||
return BadRequest();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
LocalLibrary newLibrary = new (library.path, library.name);
|
|
||||||
context.LocalLibraries.Add(newLibrary);
|
|
||||||
context.SaveChanges();
|
|
||||||
|
|
||||||
return Ok(newLibrary);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpDelete("{LibraryId}")]
|
|
||||||
[ProducesResponseType(Status200OK)]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult DeleteLocalLibrary(string LibraryId)
|
|
||||||
{
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
LocalLibrary? library = context.LocalLibraries.Find(LibraryId);
|
|
||||||
if (library is null)
|
|
||||||
return NotFound();
|
|
||||||
context.Remove(library);
|
|
||||||
context.SaveChanges();
|
|
||||||
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
39
API/Controllers/MaintenanceController.cs
Normal file
39
API/Controllers/MaintenanceController.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using API.MangaConnectors;
|
||||||
|
using API.Schema.MangaContext;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
|
public class MaintenanceController(MangaContext mangaContext) : Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes all <see cref="Manga"/> not marked for Download on any <see cref="MangaConnector"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpPost("CleanupNoDownloadManga")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
|
public async Task<Results<Ok, InternalServerError<string>>> CleanupNoDownloadManga()
|
||||||
|
{
|
||||||
|
if (await mangaContext.Mangas
|
||||||
|
.Include(m => m.MangaConnectorIds)
|
||||||
|
.Where(m => !m.MangaConnectorIds.Any(id => id.UseForDownload))
|
||||||
|
.ToArrayAsync(HttpContext.RequestAborted) is not { } noDownloads)
|
||||||
|
return TypedResults.InternalServerError("Could not fetch Manga");
|
||||||
|
|
||||||
|
mangaContext.Mangas.RemoveRange(noDownloads);
|
||||||
|
|
||||||
|
if(await mangaContext.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,82 +1,98 @@
|
|||||||
using API.Schema.Contexts;
|
using API.Controllers.DTOs;
|
||||||
using API.Schema.MangaConnectors;
|
using API.Schema.MangaContext;
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using log4net;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
|
|
||||||
[ApiVersion(2)]
|
[ApiVersion(2)]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("v{v:apiVersion}/[controller]")]
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
public class MangaConnectorController(PgsqlContext context, ILog Log) : Controller
|
public class MangaConnectorController(MangaContext context) : Controller
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all available Connectors (Scanlation-Sites)
|
/// Get all <see cref="API.MangaConnectors.MangaConnector"/> (Scanlation-Sites)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <response code="200"></response>
|
/// <response code="200">Names of <see cref="API.MangaConnectors.MangaConnector"/> (Scanlation-Sites)</response>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType<MangaConnector[]>(Status200OK, "application/json")]
|
[ProducesResponseType<List<MangaConnector>>(Status200OK, "application/json")]
|
||||||
public IActionResult GetConnectors()
|
public Ok<List<MangaConnector>> GetConnectors()
|
||||||
{
|
{
|
||||||
MangaConnector[] connectors = context.MangaConnectors.ToArray();
|
return TypedResults.Ok(Tranga.MangaConnectors
|
||||||
return Ok(connectors);
|
.Select(c => new MangaConnector(c.Name, c.Enabled, c.IconUrl, c.SupportedLanguages))
|
||||||
|
.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all enabled Connectors (Scanlation-Sites)
|
/// Returns the <see cref="API.MangaConnectors.MangaConnector"/> (Scanlation-Sites) with the requested Name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="MangaConnectorName"><see cref="API.MangaConnectors.MangaConnector"/>.Name</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpGet("enabled")]
|
/// <response code="404"><see cref="MangaConnector"/> (Scanlation-Sites) with Name not found.</response>
|
||||||
[ProducesResponseType<MangaConnector[]>(Status200OK, "application/json")]
|
[HttpGet("{MangaConnectorName}")]
|
||||||
public IActionResult GetEnabledConnectors()
|
[ProducesResponseType<MangaConnector>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
public Results<Ok<MangaConnector>, NotFound<string>> GetConnector(string MangaConnectorName)
|
||||||
{
|
{
|
||||||
MangaConnector[] connectors = context.MangaConnectors.Where(c => c.Enabled == true).ToArray();
|
if(Tranga.MangaConnectors.FirstOrDefault(c => c.Name.Equals(MangaConnectorName, StringComparison.InvariantCultureIgnoreCase)) is not { } connector)
|
||||||
return Ok(connectors);
|
return TypedResults.NotFound(nameof(MangaConnectorName));
|
||||||
|
|
||||||
|
return TypedResults.Ok(new MangaConnector(connector.Name, connector.Enabled, connector.IconUrl, connector.SupportedLanguages));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all disabled Connectors (Scanlation-Sites)
|
/// Get all enabled <see cref="API.MangaConnectors.MangaConnector"/> (Scanlation-Sites)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpGet("disabled")]
|
[HttpGet("Enabled")]
|
||||||
[ProducesResponseType<MangaConnector[]>(Status200OK, "application/json")]
|
[ProducesResponseType<List<MangaConnector>>(Status200OK, "application/json")]
|
||||||
public IActionResult GetDisabledConnectors()
|
public Ok<List<MangaConnector>> GetEnabledConnectors()
|
||||||
{
|
{
|
||||||
MangaConnector[] connectors = context.MangaConnectors.Where(c => c.Enabled == false).ToArray();
|
return TypedResults.Ok(Tranga.MangaConnectors
|
||||||
return Ok(connectors);
|
.Where(c => c.Enabled)
|
||||||
|
.Select(c => new MangaConnector(c.Name, c.Enabled, c.IconUrl, c.SupportedLanguages))
|
||||||
|
.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enabled or disables a Connector
|
/// Get all disabled <see cref="API.MangaConnectors.MangaConnector"/> (Scanlation-Sites)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaConnectorName">ID of the connector</param>
|
|
||||||
/// <param name="enabled">Set true to enable</param>
|
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="404">Connector with ID not found.</response>
|
[HttpGet("Disabled")]
|
||||||
|
[ProducesResponseType<List<MangaConnector>>(Status200OK, "application/json")]
|
||||||
|
public Ok<List<MangaConnector>> GetDisabledConnectors()
|
||||||
|
{
|
||||||
|
|
||||||
|
return TypedResults.Ok(Tranga.MangaConnectors
|
||||||
|
.Where(c => c.Enabled == false)
|
||||||
|
.Select(c => new MangaConnector(c.Name, c.Enabled, c.IconUrl, c.SupportedLanguages))
|
||||||
|
.ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enabled or disables <see cref="API.MangaConnectors.MangaConnector"/> (Scanlation-Sites) with Name
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaConnectorName"><see cref="API.MangaConnectors.MangaConnector"/>.Name</param>
|
||||||
|
/// <param name="Enabled">Set true to enable, false to disable</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="API.MangaConnectors.MangaConnector"/> (Scanlation-Sites) with Name not found.</response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPatch("{MangaConnectorName}/SetEnabled/{enabled}")]
|
[HttpPatch("{MangaConnectorName}/SetEnabled/{Enabled}")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult SetEnabled(string MangaConnectorName, bool enabled)
|
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> SetEnabled(string MangaConnectorName, bool Enabled)
|
||||||
{
|
{
|
||||||
try
|
if(Tranga.MangaConnectors.FirstOrDefault(c => c.Name.Equals(MangaConnectorName, StringComparison.InvariantCultureIgnoreCase)) is not { } connector)
|
||||||
{
|
return TypedResults.NotFound(nameof(MangaConnectorName));
|
||||||
MangaConnector? connector = context.MangaConnectors.Find(MangaConnectorName);
|
|
||||||
if (connector is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
connector.Enabled = enabled;
|
connector.Enabled = Enabled;
|
||||||
context.SaveChanges();
|
|
||||||
|
|
||||||
return Ok();
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
}
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
catch (Exception e)
|
return TypedResults.Ok();
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,19 @@
|
|||||||
using API.Schema;
|
using API.Controllers.DTOs;
|
||||||
using API.Schema.Contexts;
|
using API.Schema.MangaContext;
|
||||||
using API.Schema.Jobs;
|
using API.Workers;
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using log4net;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SixLabors.ImageSharp;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
using SixLabors.ImageSharp.Processing;
|
using Microsoft.Net.Http.Headers;
|
||||||
using SixLabors.ImageSharp.Processing.Processors.Transforms;
|
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
using AltTitle = API.Controllers.DTOs.AltTitle;
|
||||||
|
using Author = API.Controllers.DTOs.Author;
|
||||||
|
using Chapter = API.Controllers.DTOs.Chapter;
|
||||||
|
using Link = API.Controllers.DTOs.Link;
|
||||||
|
using Manga = API.Controllers.DTOs.Manga;
|
||||||
|
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
@@ -16,345 +21,559 @@ namespace API.Controllers;
|
|||||||
[ApiVersion(2)]
|
[ApiVersion(2)]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("v{v:apiVersion}/[controller]")]
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
public class MangaController(PgsqlContext context, ILog Log) : Controller
|
public class MangaController(MangaContext context) : Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all cached Manga
|
/// Returns all cached <see cref="DTOs.Manga"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"><see cref="MinimalManga"/> exert of <see cref="Schema.MangaContext.Manga"/>. Use <see cref="GetManga"/> for more information</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
[ProducesResponseType<List<MinimalManga>>(Status200OK, "application/json")]
|
||||||
public IActionResult GetAllManga()
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public async Task<Results<Ok<List<MinimalManga>>, InternalServerError>> GetAllManga ()
|
||||||
{
|
{
|
||||||
Manga[] ret = context.Mangas.ToArray();
|
if (await context.Mangas.Include(m => m.MangaConnectorIds).ToArrayAsync(HttpContext.RequestAborted) is not
|
||||||
return Ok(ret);
|
{ } result)
|
||||||
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
return TypedResults.Ok(result.Select(m =>
|
||||||
|
{
|
||||||
|
IEnumerable<MangaConnectorId> ids = m.MangaConnectorIds.Select(id => new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
|
return new MinimalManga(m.Key, m.Name, m.Description, m.ReleaseStatus, ids);
|
||||||
|
}).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all cached Manga with IDs
|
/// Returns all cached <see cref="Schema.MangaContext.Manga"/>.Keys
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ids">Array of Manga-IDs</param>
|
/// <response code="200"><see cref="Schema.MangaContext.Manga"/> Keys/IDs</response>
|
||||||
/// <response code="200"></response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpGet("Keys")]
|
||||||
|
[ProducesResponseType<string[]>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public async Task<Results<Ok<string[]>, InternalServerError>> GetAllMangaKeys ()
|
||||||
|
{
|
||||||
|
if (await context.Mangas.Select(m => m.Key).ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
return TypedResults.Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all <see cref="Schema.MangaContext.Manga"/> that are being downloaded from at least one <see cref="API.MangaConnectors.MangaConnector"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200"><see cref="MinimalManga"/> exert of <see cref="Schema.MangaContext.Manga"/>. Use <see cref="GetManga"/> for more information</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpGet("Downloading")]
|
||||||
|
[ProducesResponseType<MinimalManga[]>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public async Task<Results<Ok<List<MinimalManga>>, InternalServerError>> GetMangaDownloading()
|
||||||
|
{
|
||||||
|
if (await context.Mangas
|
||||||
|
.Include(m => m.MangaConnectorIds)
|
||||||
|
.Where(m => m.MangaConnectorIds.Any(id => id.UseForDownload))
|
||||||
|
.ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
return TypedResults.Ok(result.Select(m =>
|
||||||
|
{
|
||||||
|
IEnumerable<MangaConnectorId> ids = m.MangaConnectorIds.Select(id => new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
|
return new MinimalManga(m.Key, m.Name, m.Description, m.ReleaseStatus, ids);
|
||||||
|
}).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all cached <see cref="Schema.MangaContext.Manga"/> with <paramref name="MangaIds"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaIds">Array of <see cref="Schema.MangaContext.Manga"/>.Key</param>
|
||||||
|
/// <response code="200"><see cref="DTOs.Manga"/></response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPost("WithIDs")]
|
[HttpPost("WithIDs")]
|
||||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
[ProducesResponseType<List<Manga>>(Status200OK, "application/json")]
|
||||||
public IActionResult GetManga([FromBody]string[] ids)
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public async Task<Results<Ok<List<Manga>>, InternalServerError>> GetMangaWithIds ([FromBody]string[] MangaIds)
|
||||||
{
|
{
|
||||||
Manga[] ret = context.Mangas.Where(m => ids.Contains(m.MangaId)).ToArray();
|
if (await context.MangaIncludeAll()
|
||||||
return Ok(ret);
|
.Where(m => MangaIds.Contains(m.Key))
|
||||||
|
.ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
return TypedResults.Ok(result.Select(m =>
|
||||||
|
{
|
||||||
|
IEnumerable<MangaConnectorId> ids = m.MangaConnectorIds.Select(id => new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
|
IEnumerable<Author> authors = m.Authors.Select(a => new Author(a.Key, a.AuthorName));
|
||||||
|
IEnumerable<string> tags = m.MangaTags.Select(t => t.Tag);
|
||||||
|
IEnumerable<Link> links = m.Links.Select(l => new Link(l.Key, l.LinkProvider, l.LinkUrl));
|
||||||
|
IEnumerable<AltTitle> altTitles = m.AltTitles.Select(a => new AltTitle(a.Language, a.Title));
|
||||||
|
return new Manga(m.Key, m.Name, m.Description, m.ReleaseStatus, ids, m.IgnoreChaptersBefore, m.Year, m.OriginalLanguage, m.ChapterIds, authors, tags, links, altTitles, m.LibraryId);
|
||||||
|
}).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return Manga with ID
|
/// Return <see cref="Schema.MangaContext.Manga"/> with <paramref name="MangaId"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
/// <param name="MangaId"><see cref="Schema.MangaContext.Manga"/>.Key</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="404">Manga with ID not found</response>
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||||
[HttpGet("{MangaId}")]
|
[HttpGet("{MangaId}")]
|
||||||
[ProducesResponseType<Manga>(Status200OK, "application/json")]
|
[ProducesResponseType<Manga>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
public IActionResult GetManga(string MangaId)
|
public async Task<Results<Ok<Manga>, NotFound<string>>> GetManga (string MangaId)
|
||||||
{
|
{
|
||||||
Manga? ret = context.Mangas.Find(MangaId);
|
if (await context.MangaIncludeAll().FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
if (ret is null)
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
return NotFound();
|
|
||||||
return Ok(ret);
|
IEnumerable<MangaConnectorId> ids = manga.MangaConnectorIds.Select(id => new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
|
IEnumerable<Author> authors = manga.Authors.Select(a => new Author(a.Key, a.AuthorName));
|
||||||
|
IEnumerable<string> tags = manga.MangaTags.Select(t => t.Tag);
|
||||||
|
IEnumerable<Link> links = manga.Links.Select(l => new Link(l.Key, l.LinkProvider, l.LinkUrl));
|
||||||
|
IEnumerable<AltTitle> altTitles = manga.AltTitles.Select(a => new AltTitle(a.Language, a.Title));
|
||||||
|
Manga result = new (manga.Key, manga.Name, manga.Description, manga.ReleaseStatus, ids, manga.IgnoreChaptersBefore, manga.Year, manga.OriginalLanguage, manga.ChapterIds, authors, tags, links, altTitles, manga.LibraryId);
|
||||||
|
|
||||||
|
return TypedResults.Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete Manga with ID
|
/// Delete <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="404">Manga with ID not found</response>
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpDelete("{MangaId}")]
|
[HttpDelete("{MangaId}")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult DeleteManga(string MangaId)
|
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> DeleteManga (string MangaId)
|
||||||
{
|
{
|
||||||
try
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
{
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
Manga? ret = context.Mangas.Find(MangaId);
|
|
||||||
if (ret is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
context.Remove(ret);
|
context.Mangas.Remove(manga);
|
||||||
context.SaveChanges();
|
|
||||||
return Ok();
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
}
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
catch (Exception e)
|
return TypedResults.Ok();
|
||||||
{
|
}
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
/// <summary>
|
||||||
|
/// Merge two <see cref="Manga"/> into one. THIS IS NOT REVERSIBLE!
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaIdFrom"><see cref="Manga"/>.Key of <see cref="Manga"/> merging data from (getting deleted)</param>
|
||||||
|
/// <param name="MangaIdInto"><see cref="Manga"/>.Key of <see cref="Manga"/> merging data into</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaIdFrom"/> or <paramref name="MangaIdInto"/> not found</response>
|
||||||
|
[HttpPatch("{MangaIdFrom}/MergeInto/{MangaIdInto}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
public async Task<Results<Ok, NotFound<string>>> MergeIntoManga (string MangaIdFrom, string MangaIdInto)
|
||||||
|
{
|
||||||
|
if (await context.MangaIncludeAll().FirstOrDefaultAsync(m => m.Key == MangaIdFrom, HttpContext.RequestAborted) is not { } from)
|
||||||
|
return TypedResults.NotFound(nameof(MangaIdFrom));
|
||||||
|
if (await context.MangaIncludeAll().FirstOrDefaultAsync(m => m.Key == MangaIdInto, HttpContext.RequestAborted) is not { } into)
|
||||||
|
return TypedResults.NotFound(nameof(MangaIdInto));
|
||||||
|
|
||||||
|
BaseWorker[] newJobs = into.MergeFrom(from, context);
|
||||||
|
Tranga.AddWorkers(newJobs);
|
||||||
|
|
||||||
|
return TypedResults.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns Cover of Manga
|
/// Returns Cover of <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
/// <param name="width">If width is provided, height needs to also be provided</param>
|
/// <param name="CoverSize">Size of the cover returned
|
||||||
/// <param name="height">If height is provided, width needs to also be provided</param>
|
/// <br /> - <see cref="CoverSize.Small"/> <see cref="Constants.ImageSmSize"/>
|
||||||
|
/// <br /> - <see cref="CoverSize.Medium"/> <see cref="Constants.ImageMdSize"/>
|
||||||
|
/// <br /> - <see cref="CoverSize.Large"/> <see cref="Constants.ImageLgSize"/>
|
||||||
|
/// </param>
|
||||||
/// <response code="200">JPEG Image</response>
|
/// <response code="200">JPEG Image</response>
|
||||||
/// <response code="204">Cover not loaded</response>
|
/// <response code="204">Cover not loaded</response>
|
||||||
/// <response code="400">The formatting-request was invalid</response>
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||||
/// <response code="404">Manga with ID not found</response>
|
|
||||||
/// <response code="503">Retry later, downloading cover</response>
|
/// <response code="503">Retry later, downloading cover</response>
|
||||||
[HttpGet("{MangaId}/Cover")]
|
[HttpGet("{MangaId}/Cover/{CoverSize?}")]
|
||||||
[ProducesResponseType<byte[]>(Status200OK,"image/jpeg")]
|
[ProducesResponseType<FileContentResult>(Status200OK,"image/jpeg")]
|
||||||
[ProducesResponseType(Status204NoContent)]
|
[ProducesResponseType(Status204NoContent)]
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType<int>(Status503ServiceUnavailable, "text/plain")]
|
[ProducesResponseType(Status503ServiceUnavailable)]
|
||||||
public IActionResult GetCover(string MangaId, [FromQuery]int? width, [FromQuery]int? height)
|
public async Task<Results<FileContentHttpResult, NoContent, BadRequest, NotFound<string>, StatusCodeHttpResult>> GetCover (string MangaId, CoverSize? CoverSize = null)
|
||||||
{
|
{
|
||||||
DateTime requestStarted = HttpContext.Features.Get<IHttpRequestTimeFeature>()?.RequestTime ?? DateTime.Now;
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
Manga? m = context.Mangas.Find(MangaId);
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
if (m is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
if (!System.IO.File.Exists(m.CoverFileNameInCache))
|
string cache = CoverSize switch
|
||||||
{
|
{
|
||||||
List<Job> coverDownloadJobs = context.Jobs.Where(j => j.JobType == JobType.DownloadMangaCoverJob).ToList();
|
MangaController.CoverSize.Small => TrangaSettings.coverImageCacheSmall,
|
||||||
if (coverDownloadJobs.Any(j => j is DownloadMangaCoverJob dmc && dmc.MangaId == MangaId))
|
MangaController.CoverSize.Medium => TrangaSettings.coverImageCacheMedium,
|
||||||
|
MangaController.CoverSize.Large => TrangaSettings.coverImageCacheLarge,
|
||||||
|
_ => TrangaSettings.coverImageCacheOriginal
|
||||||
|
};
|
||||||
|
|
||||||
|
if (await manga.GetCoverImage(cache, HttpContext.RequestAborted) is not { } data)
|
||||||
|
{
|
||||||
|
if (Tranga.GetRunningWorkers().Any(worker => worker is DownloadCoverFromMangaconnectorWorker w && context.MangaConnectorToManga.Find(w.MangaConnectorIdId)?.ObjId == MangaId))
|
||||||
{
|
{
|
||||||
Response.Headers.Add("Retry-After", $"{TrangaSettings.startNewJobTimeoutMs * coverDownloadJobs.Count() * 2 / 1000:D}");
|
Response.Headers.Append("Retry-After", $"{Tranga.Settings.WorkCycleTimeoutMs * 2 / 1000:D}");
|
||||||
return StatusCode(Status503ServiceUnavailable, TrangaSettings.startNewJobTimeoutMs * coverDownloadJobs.Count() * 2 / 1000);
|
return TypedResults.StatusCode(Status503ServiceUnavailable);
|
||||||
}
|
}
|
||||||
else
|
return TypedResults.NoContent();
|
||||||
return NoContent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Image image = Image.Load(m.CoverFileNameInCache);
|
DateTime lastModified = data.fileInfo.LastWriteTime;
|
||||||
|
EntityTagHeaderValue entityTagHeaderValue = EntityTagHeaderValue.Parse($"\"{lastModified.Ticks}\"");
|
||||||
if (width is { } w && height is { } h)
|
if(HttpContext.Request.Headers.ETag.Equals(entityTagHeaderValue.Tag.Value))
|
||||||
{
|
return TypedResults.StatusCode(Status304NotModified);
|
||||||
if (width < 10 || height < 10 || width > 65535 || height > 65535)
|
HttpContext.Response.Headers.CacheControl = "public";
|
||||||
return BadRequest();
|
return TypedResults.Bytes(data.stream.ToArray(), "image/jpeg", lastModified: new DateTimeOffset(lastModified), entityTag: entityTagHeaderValue);
|
||||||
image.Mutate(i => i.ApplyProcessor(new ResizeProcessor(new ResizeOptions()
|
|
||||||
{
|
|
||||||
Mode = ResizeMode.Max,
|
|
||||||
Size = new Size(w, h)
|
|
||||||
}, image.Size)));
|
|
||||||
}
|
|
||||||
|
|
||||||
using MemoryStream ms = new();
|
|
||||||
image.Save(ms, new JpegEncoder(){Quality = 100});
|
|
||||||
return File(ms.GetBuffer(), "image/jpeg");
|
|
||||||
}
|
}
|
||||||
|
public enum CoverSize { Original, Large, Medium, Small }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all Chapters of Manga
|
/// Returns all <see cref="Chapter"/> of <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="404">Manga with ID not found</response>
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||||
[HttpGet("{MangaId}/Chapters")]
|
[HttpGet("{MangaId}/Chapters")]
|
||||||
[ProducesResponseType<Chapter[]>(Status200OK, "application/json")]
|
[ProducesResponseType<List<Chapter>>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType(Status404NotFound)]
|
||||||
public IActionResult GetChapters(string MangaId)
|
public async Task<Results<Ok<List<Chapter>>, NotFound<string>>> GetChapters(string MangaId)
|
||||||
{
|
{
|
||||||
Manga? m = context.Mangas.Find(MangaId);
|
if (await context.Mangas.Include(m => m.Chapters).ThenInclude(c => c.MangaConnectorIds).FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
if (m is null)
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
Chapter[] ret = context.Chapters.Where(c => c.ParentMangaId == m.MangaId).ToArray();
|
List<Chapter> chapters = manga.Chapters.Select(c =>
|
||||||
return Ok(ret);
|
{
|
||||||
|
IEnumerable<MangaConnectorId> ids = c.MangaConnectorIds.Select(id =>
|
||||||
|
new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
|
return new Chapter(c.Key, c.ParentMangaId, c.VolumeNumber, c.ChapterNumber, c.Title, ids, c.Downloaded);
|
||||||
|
}).ToList();
|
||||||
|
return TypedResults.Ok(chapters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all downloaded Chapters for Manga with ID
|
/// Returns all downloaded <see cref="Chapter"/> for <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="204">No available chapters</response>
|
/// <response code="204">No available chapters</response>
|
||||||
/// <response code="404">Manga with ID not found.</response>
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found.</response>
|
||||||
[HttpGet("{MangaId}/Chapters/Downloaded")]
|
[HttpGet("{MangaId}/Chapters/Downloaded")]
|
||||||
[ProducesResponseType<Chapter[]>(Status200OK, "application/json")]
|
[ProducesResponseType<Chapter[]>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status204NoContent)]
|
[ProducesResponseType(Status204NoContent)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
public IActionResult GetChaptersDownloaded(string MangaId)
|
public async Task<Results<Ok<List<Chapter>>, NoContent, NotFound<string>>> GetChaptersDownloaded(string MangaId)
|
||||||
{
|
{
|
||||||
Manga? m = context.Mangas.Find(MangaId);
|
if (await context.Mangas.Include(m => m.Chapters).FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
if (m is null)
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
List<Chapter> chapters = context.Chapters.Where(c => c.ParentMangaId == m.MangaId && c.Downloaded == true).ToList();
|
List<Chapter> chapters = manga.Chapters.Where(c => c.Downloaded).Select(c =>
|
||||||
|
{
|
||||||
|
IEnumerable<MangaConnectorId> ids = c.MangaConnectorIds.Select(id =>
|
||||||
|
new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
|
return new Chapter(c.Key, c.ParentMangaId, c.VolumeNumber, c.ChapterNumber, c.Title, ids, c.Downloaded);
|
||||||
|
}).ToList();
|
||||||
if (chapters.Count == 0)
|
if (chapters.Count == 0)
|
||||||
return NoContent();
|
return TypedResults.NoContent();
|
||||||
|
|
||||||
return Ok(chapters);
|
return TypedResults.Ok(chapters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all Chapters not downloaded for Manga with ID
|
/// Returns all <see cref="Chapter"/> not downloaded for <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="204">No available chapters</response>
|
/// <response code="204">No available chapters</response>
|
||||||
/// <response code="404">Manga with ID not found.</response>
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found.</response>
|
||||||
[HttpGet("{MangaId}/Chapters/NotDownloaded")]
|
[HttpGet("{MangaId}/Chapters/NotDownloaded")]
|
||||||
[ProducesResponseType<Chapter[]>(Status200OK, "application/json")]
|
[ProducesResponseType<List<Chapter>>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status204NoContent)]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
public IActionResult GetChaptersNotDownloaded(string MangaId)
|
|
||||||
{
|
|
||||||
Manga? m = context.Mangas.Find(MangaId);
|
|
||||||
if (m is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
List<Chapter> chapters = context.Chapters.Where(c => c.ParentMangaId == m.MangaId && c.Downloaded == false).ToList();
|
|
||||||
if (chapters.Count == 0)
|
|
||||||
return NoContent();
|
|
||||||
|
|
||||||
return Ok(chapters);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the latest Chapter of requested Manga available on Website
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
/// <response code="204">No available chapters</response>
|
|
||||||
/// <response code="404">Manga with ID not found.</response>
|
|
||||||
/// <response code="500">Could not retrieve the maximum chapter-number</response>
|
|
||||||
/// <response code="503">Retry after timeout, updating value</response>
|
|
||||||
[HttpGet("{MangaId}/Chapter/LatestAvailable")]
|
|
||||||
[ProducesResponseType<Chapter>(Status200OK, "application/json")]
|
|
||||||
[ProducesResponseType(Status204NoContent)]
|
[ProducesResponseType(Status204NoContent)]
|
||||||
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
public async Task<Results<Ok<List<Chapter>>, NoContent, NotFound<string>>> GetChaptersNotDownloaded(string MangaId)
|
||||||
[ProducesResponseType<int>(Status503ServiceUnavailable, "text/plain")]
|
|
||||||
public IActionResult GetLatestChapter(string MangaId)
|
|
||||||
{
|
{
|
||||||
Manga? m = context.Mangas.Find(MangaId);
|
if (await context.Mangas.Include(m => m.Chapters).FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
if (m is null)
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
List<Chapter> chapters = context.Chapters.Where(c => c.ParentMangaId == m.MangaId).ToList();
|
List<Chapter> chapters = manga.Chapters.Where(c => c.Downloaded == false).Select(c =>
|
||||||
if (chapters.Count == 0)
|
|
||||||
{
|
{
|
||||||
List<Job> retrieveChapterJobs = context.Jobs.Where(j => j.JobType == JobType.RetrieveChaptersJob).ToList();
|
IEnumerable<MangaConnectorId> ids = c.MangaConnectorIds.Select(id =>
|
||||||
if (retrieveChapterJobs.Any(j => j is RetrieveChaptersJob rcj && rcj.MangaId == MangaId))
|
new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
{
|
return new Chapter(c.Key, c.ParentMangaId, c.VolumeNumber, c.ChapterNumber, c.Title, ids, c.Downloaded);
|
||||||
Response.Headers.Add("Retry-After", $"{TrangaSettings.startNewJobTimeoutMs * retrieveChapterJobs.Count() * 2 / 1000:D}");
|
}).ToList();
|
||||||
return StatusCode(Status503ServiceUnavailable, TrangaSettings.startNewJobTimeoutMs * retrieveChapterJobs.Count() * 2/ 1000);
|
if (chapters.Count == 0)
|
||||||
}else
|
return TypedResults.NoContent();
|
||||||
return NoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
Chapter? max = chapters.Max();
|
return TypedResults.Ok(chapters);
|
||||||
if (max is null)
|
|
||||||
return StatusCode(500, "Max chapter could not be found");
|
|
||||||
|
|
||||||
return Ok(max);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the latest Chapter of requested Manga that is downloaded
|
/// Returns the latest <see cref="Chapter"/> of requested <see cref="Manga"/> available on <see cref="API.MangaConnectors.MangaConnector"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="204">No available chapters</response>
|
/// <response code="204">No available chapters</response>
|
||||||
/// <response code="404">Manga with ID not found.</response>
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found.</response>
|
||||||
/// <response code="500">Could not retrieve the maximum chapter-number</response>
|
/// <response code="412">Could not retrieve the maximum chapter-number</response>
|
||||||
|
/// <response code="503">Retry after timeout, updating value</response>
|
||||||
|
[HttpGet("{MangaId}/Chapter/LatestAvailable")]
|
||||||
|
[ProducesResponseType<int>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType(Status204NoContent)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
[ProducesResponseType(Status503ServiceUnavailable)]
|
||||||
|
public async Task<Results<Ok<Chapter>, NoContent, InternalServerError, NotFound<string>, StatusCodeHttpResult>> GetLatestChapter(string MangaId)
|
||||||
|
{
|
||||||
|
if (await context.Mangas.Include(m => m.Chapters).FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
|
|
||||||
|
List<API.Schema.MangaContext.Chapter> chapters = manga.Chapters.ToList();
|
||||||
|
if (chapters.Count == 0)
|
||||||
|
{
|
||||||
|
if (Tranga.GetRunningWorkers().Any(worker =>
|
||||||
|
worker is RetrieveMangaChaptersFromMangaconnectorWorker w &&
|
||||||
|
context.MangaConnectorToManga.Find(w.MangaConnectorIdId)?.ObjId == MangaId &&
|
||||||
|
w.State < WorkerExecutionState.Completed))
|
||||||
|
{
|
||||||
|
Response.Headers.Append("Retry-After", $"{Tranga.Settings.WorkCycleTimeoutMs * 2 / 1000:D}");
|
||||||
|
return TypedResults.StatusCode(Status503ServiceUnavailable);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return TypedResults.NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
API.Schema.MangaContext.Chapter? max = chapters.Max();
|
||||||
|
if (max is null)
|
||||||
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
foreach (CollectionEntry collectionEntry in context.Entry(max).Collections)
|
||||||
|
await collectionEntry.LoadAsync(HttpContext.RequestAborted);
|
||||||
|
|
||||||
|
IEnumerable<MangaConnectorId> ids = max.MangaConnectorIds.Select(id =>
|
||||||
|
new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
|
return TypedResults.Ok(new Chapter(max.Key, max.ParentMangaId, max.VolumeNumber, max.ChapterNumber, max.Title,ids, max.Downloaded));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the latest <see cref="Chapter"/> of requested <see cref="Manga"/> that is downloaded
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="204">No available chapters</response>
|
||||||
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found.</response>
|
||||||
|
/// <response code="412">Could not retrieve the maximum chapter-number</response>
|
||||||
/// <response code="503">Retry after timeout, updating value</response>
|
/// <response code="503">Retry after timeout, updating value</response>
|
||||||
[HttpGet("{MangaId}/Chapter/LatestDownloaded")]
|
[HttpGet("{MangaId}/Chapter/LatestDownloaded")]
|
||||||
[ProducesResponseType<Chapter>(Status200OK, "application/json")]
|
[ProducesResponseType<Chapter>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status204NoContent)]
|
[ProducesResponseType(Status204NoContent)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType(Status412PreconditionFailed)]
|
||||||
[ProducesResponseType<int>(Status503ServiceUnavailable, "text/plain")]
|
[ProducesResponseType(Status503ServiceUnavailable)]
|
||||||
public IActionResult GetLatestChapterDownloaded(string MangaId)
|
public async Task<Results<Ok<Chapter>, NoContent, NotFound<string>, StatusCodeHttpResult>> GetLatestChapterDownloaded(string MangaId)
|
||||||
{
|
{
|
||||||
Manga? m = context.Mangas.Find(MangaId);
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
if (m is null)
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
|
await context.Entry(manga).Collection(m => m.Chapters).LoadAsync(HttpContext.RequestAborted);
|
||||||
|
|
||||||
List<Chapter> chapters = context.Chapters.Where(c => c.ParentMangaId == m.MangaId && c.Downloaded == true).ToList();
|
List<API.Schema.MangaContext.Chapter> chapters = manga.Chapters.ToList();
|
||||||
if (chapters.Count == 0)
|
if (chapters.Count == 0)
|
||||||
{
|
{
|
||||||
List<Job> retrieveChapterJobs = context.Jobs.Where(j => j.JobType == JobType.RetrieveChaptersJob).ToList();
|
if (Tranga.GetRunningWorkers().Any(worker => worker is RetrieveMangaChaptersFromMangaconnectorWorker w && context.MangaConnectorToManga.Find(w.MangaConnectorIdId)?.ObjId == MangaId && w.State < WorkerExecutionState.Completed))
|
||||||
if (retrieveChapterJobs.Any(j => j is RetrieveChaptersJob rcj && rcj.MangaId == MangaId))
|
|
||||||
{
|
{
|
||||||
Response.Headers.Add("Retry-After", $"{TrangaSettings.startNewJobTimeoutMs * retrieveChapterJobs.Count() * 2 / 1000:D}");
|
Response.Headers.Append("Retry-After", $"{Tranga.Settings.WorkCycleTimeoutMs * 2 / 1000:D}");
|
||||||
return StatusCode(Status503ServiceUnavailable, TrangaSettings.startNewJobTimeoutMs * retrieveChapterJobs.Count() * 2 / 1000);
|
return TypedResults.StatusCode(Status503ServiceUnavailable);
|
||||||
}else
|
}else
|
||||||
return NoContent();
|
return TypedResults.NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
Chapter? max = chapters.Max();
|
API.Schema.MangaContext.Chapter? max = chapters.Max();
|
||||||
if (max is null)
|
if (max is null)
|
||||||
return StatusCode(500, "Max chapter could not be found");
|
return TypedResults.StatusCode(Status412PreconditionFailed);
|
||||||
|
|
||||||
return Ok(max);
|
IEnumerable<MangaConnectorId> ids = max.MangaConnectorIds.Select(id =>
|
||||||
|
new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
|
return TypedResults.Ok(new Chapter(max.Key, max.ParentMangaId, max.VolumeNumber, max.ChapterNumber, max.Title,ids, max.Downloaded));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configure the cut-off for Manga
|
/// Configure the <see cref="Chapter"/> cut-off for <see cref="Manga"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
/// <param name="chapterThreshold">Threshold (Chapter Number)</param>
|
/// <param name="chapterThreshold">Threshold (<see cref="Chapter"/> ChapterNumber)</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="202"></response>
|
||||||
/// <response code="404">Manga with ID not found.</response>
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found.</response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPatch("{MangaId}/IgnoreChaptersBefore")]
|
[HttpPatch("{MangaId}/IgnoreChaptersBefore")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult IgnoreChaptersBefore(string MangaId, [FromBody]float chapterThreshold)
|
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> IgnoreChaptersBefore(string MangaId, [FromBody]float chapterThreshold)
|
||||||
{
|
{
|
||||||
Manga? m = context.Mangas.Find(MangaId);
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
if (m is null)
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
try
|
manga.IgnoreChaptersBefore = chapterThreshold;
|
||||||
{
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
m.IgnoreChaptersBefore = chapterThreshold;
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
context.SaveChanges();
|
|
||||||
return Ok();
|
return TypedResults.Ok();
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Move Manga to different ToLibrary
|
/// Move <see cref="Manga"/> to different <see cref="FileLibrary"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
/// <param name="LibraryId">ToLibrary-Id</param>
|
/// <param name="LibraryId"><see cref="FileLibrary"/>.Key</param>
|
||||||
/// <response code="202">Folder is going to be moved</response>
|
/// <response code="202">Folder is going to be moved</response>
|
||||||
/// <response code="404">MangaId or LibraryId not found</response>
|
/// <response code="404"><paramref name="MangaId"/> or <paramref name="LibraryId"/> not found</response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPost("{MangaId}/ChangeLibrary/{LibraryId}")]
|
[HttpPost("{MangaId}/ChangeLibrary/{LibraryId}")]
|
||||||
[ProducesResponseType(Status202Accepted)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
public async Task<Results<Ok, NotFound<string>>> ChangeLibrary(string MangaId, string LibraryId)
|
||||||
public IActionResult MoveFolder(string MangaId, string LibraryId)
|
|
||||||
{
|
{
|
||||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
return NotFound();
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
if(context.LocalLibraries.Find(LibraryId) is not { } library)
|
if (await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == LibraryId, HttpContext.RequestAborted) is not { } library)
|
||||||
return NotFound();
|
return TypedResults.NotFound(nameof(LibraryId));
|
||||||
|
|
||||||
MoveMangaLibraryJob moveLibrary = new(manga, library);
|
if(manga.LibraryId == library.Key)
|
||||||
UpdateFilesDownloadedJob updateDownloadedFiles = new(manga, 0, dependsOnJobs: [moveLibrary]);
|
return TypedResults.Ok();
|
||||||
|
|
||||||
try
|
MoveMangaLibraryWorker moveLibrary = new(manga, library);
|
||||||
|
|
||||||
|
Tranga.AddWorkers([moveLibrary]);
|
||||||
|
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// (Un-)Marks <see cref="Manga"/> as requested for Download from <see cref="API.MangaConnectors.MangaConnector"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaId"><see cref="Manga"/> with <paramref name="MangaId"/></param>
|
||||||
|
/// <param name="MangaConnectorName"><see cref="API.MangaConnectors.MangaConnector"/> with <paramref name="MangaConnectorName"/></param>
|
||||||
|
/// <param name="IsRequested">true to mark as requested, false to mark as not-requested</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><paramref name="MangaId"/> or <paramref name="MangaConnectorName"/> not found</response>
|
||||||
|
/// <response code="412"><see cref="Manga"/> was not linked to <see cref="API.MangaConnectors.MangaConnector"/>, so nothing changed</response>
|
||||||
|
/// <response code="428"><see cref="Manga"/> is not linked to <see cref="API.MangaConnectors.MangaConnector"/> yet. Search for <see cref="Manga"/> on <see cref="API.MangaConnectors.MangaConnector"/> first (to create a <see cref="MangaConnectorId{T}"/>).</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpPost("{MangaId}/SetAsDownloadFrom/{MangaConnectorName}/{IsRequested}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType<string>(Status412PreconditionFailed, "text/plain")]
|
||||||
|
[ProducesResponseType<string>(Status428PreconditionRequired, "text/plain")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
|
public async Task<Results<Ok, NotFound<string>, StatusCodeHttpResult, InternalServerError<string>>> MarkAsRequested(string MangaId, string MangaConnectorName, bool IsRequested)
|
||||||
|
{
|
||||||
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } _)
|
||||||
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
|
if(!Tranga.TryGetMangaConnector(MangaConnectorName, out API.MangaConnectors.MangaConnector? _))
|
||||||
|
return TypedResults.NotFound(nameof(MangaConnectorName));
|
||||||
|
|
||||||
|
if (context.MangaConnectorToManga
|
||||||
|
.FirstOrDefault(id => id.MangaConnectorName == MangaConnectorName && id.ObjId == MangaId)
|
||||||
|
is not { } mcId)
|
||||||
{
|
{
|
||||||
context.Jobs.AddRange(moveLibrary, updateDownloadedFiles);
|
if(IsRequested)
|
||||||
context.SaveChanges();
|
return TypedResults.StatusCode(Status428PreconditionRequired);
|
||||||
return Accepted();
|
else
|
||||||
|
return TypedResults.StatusCode(Status412PreconditionFailed);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
|
mcId.UseForDownload = IsRequested;
|
||||||
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
|
|
||||||
|
DownloadCoverFromMangaconnectorWorker downloadCover = new(mcId);
|
||||||
|
RetrieveMangaChaptersFromMangaconnectorWorker retrieveChapters = new(mcId, Tranga.Settings.DownloadLanguage);
|
||||||
|
Tranga.AddWorkers([downloadCover, retrieveChapters]);
|
||||||
|
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initiate a search for <see cref="API.Schema.MangaContext.Manga"/> on a different <see cref="API.MangaConnectors.MangaConnector"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaId"><see cref="API.Schema.MangaContext.Manga"/> with <paramref name="MangaId"/></param>
|
||||||
|
/// <param name="MangaConnectorName"><see cref="API.MangaConnectors.MangaConnector"/>.Name</param>
|
||||||
|
/// <response code="200"><see cref="MinimalManga"/> exert of <see cref="Schema.MangaContext.Manga"/></response>
|
||||||
|
/// <response code="404"><see cref="API.MangaConnectors.MangaConnector"/> with Name not found</response>
|
||||||
|
/// <response code="412"><see cref="API.MangaConnectors.MangaConnector"/> with Name is disabled</response>
|
||||||
|
[HttpPost("{MangaId}/SearchOn/{MangaConnectorName}")]
|
||||||
|
[ProducesResponseType<List<MinimalManga>>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType(Status406NotAcceptable)]
|
||||||
|
public async Task<Results<Ok<List<MinimalManga>>, NotFound<string>, StatusCodeHttpResult>> SearchOnDifferentConnector (string MangaId, string MangaConnectorName)
|
||||||
|
{
|
||||||
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
|
|
||||||
|
return new SearchController(context).SearchManga(MangaConnectorName, manga.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all <see cref="Manga"/> which where Authored by <see cref="Author"/> with <paramref name="AuthorId"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="AuthorId"><see cref="Author"/>.Key</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="Author"/> with <paramref name="AuthorId"/></response>
|
||||||
|
/// /// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpGet("WithAuthorId/{AuthorId}")]
|
||||||
|
[ProducesResponseType<List<Manga>>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
public async Task<Results<Ok<List<Manga>>, NotFound<string>, InternalServerError>> GetMangaWithAuthorIds (string AuthorId)
|
||||||
|
{
|
||||||
|
if (await context.Authors.FirstOrDefaultAsync(a => a.Key == AuthorId, HttpContext.RequestAborted) is not { } _)
|
||||||
|
return TypedResults.NotFound(nameof(AuthorId));
|
||||||
|
|
||||||
|
if (await context.MangaIncludeAll().Where(m => m.Authors.Any(a => a.Key == AuthorId)).ToListAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
return TypedResults.Ok(result.Select(m =>
|
||||||
{
|
{
|
||||||
Log.Error(e);
|
IEnumerable<MangaConnectorId> ids = m.MangaConnectorIds.Select(id => new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
return StatusCode(500, e.Message);
|
IEnumerable<Author> authors = m.Authors.Select(a => new Author(a.Key, a.AuthorName));
|
||||||
}
|
IEnumerable<string> tags = m.MangaTags.Select(t => t.Tag);
|
||||||
|
IEnumerable<Link> links = m.Links.Select(l => new Link(l.Key, l.LinkProvider, l.LinkUrl));
|
||||||
|
IEnumerable<AltTitle> altTitles = m.AltTitles.Select(a => new AltTitle(a.Language, a.Title));
|
||||||
|
return new Manga(m.Key, m.Name, m.Description, m.ReleaseStatus, ids, m.IgnoreChaptersBefore, m.Year, m.OriginalLanguage, m.ChapterIds, authors, tags, links, altTitles, m.LibraryId);
|
||||||
|
}).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all <see cref="Manga"/> with <see cref="Tag"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Tag"><see cref="Tag"/>.Tag</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="Tag"/> not found</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpGet("WithTag/{Tag}")]
|
||||||
|
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public async Task<Results<Ok<List<Manga>>, NotFound<string>, InternalServerError>> GetMangasWithTag (string Tag)
|
||||||
|
{
|
||||||
|
if (await context.Tags.FirstOrDefaultAsync(t => t.Tag == Tag, HttpContext.RequestAborted) is not { } tag)
|
||||||
|
return TypedResults.NotFound(nameof(Tag));
|
||||||
|
|
||||||
|
|
||||||
|
if (await context.MangaIncludeAll().Where(m => m.MangaTags.Any(t => t.Tag.Equals(tag))) .ToListAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
return TypedResults.Ok(result.Select(m =>
|
||||||
|
{
|
||||||
|
IEnumerable<MangaConnectorId> ids = m.MangaConnectorIds.Select(id => new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
|
IEnumerable<Author> authors = m.Authors.Select(a => new Author(a.Key, a.AuthorName));
|
||||||
|
IEnumerable<string> tags = m.MangaTags.Select(t => t.Tag);
|
||||||
|
IEnumerable<Link> links = m.Links.Select(l => new Link(l.Key, l.LinkProvider, l.LinkUrl));
|
||||||
|
IEnumerable<AltTitle> altTitles = m.AltTitles.Select(a => new AltTitle(a.Language, a.Title));
|
||||||
|
return new Manga(m.Key, m.Name, m.Description, m.ReleaseStatus, ids, m.IgnoreChaptersBefore, m.Year, m.OriginalLanguage, m.ChapterIds, authors, tags, links, altTitles, m.LibraryId);
|
||||||
|
}).ToList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
129
API/Controllers/MetadataFetcherController.cs
Normal file
129
API/Controllers/MetadataFetcherController.cs
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
using API.Schema.MangaContext;
|
||||||
|
using API.Schema.MangaContext.MetadataFetchers;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
|
public class MetadataFetcherController(MangaContext context) : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get all <see cref="MetadataFetcher"/> (Metadata-Sites)
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200">Names of <see cref="MetadataFetcher"/> (Metadata-Sites)</response>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType<List<string>>(Status200OK, "application/json")]
|
||||||
|
public Ok<List<string>> GetConnectors ()
|
||||||
|
{
|
||||||
|
return TypedResults.Ok(Tranga.MetadataFetchers.Select(m => m.Name).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all <see cref="MetadataEntry"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpGet("Links")]
|
||||||
|
[ProducesResponseType<List<MetadataEntry>>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public async Task<Results<Ok<List<MetadataEntry>>, InternalServerError>> GetLinkedEntries ()
|
||||||
|
{
|
||||||
|
if (await context.MetadataEntries.ToListAsync() is not { } result)
|
||||||
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
return TypedResults.Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Searches <see cref="MetadataFetcher"/> (Metadata-Sites) for Manga-Metadata
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
|
/// <param name="MetadataFetcherName"><see cref="MetadataFetcher"/>.Name</param>
|
||||||
|
/// <param name="searchTerm">Instead of using the <paramref name="MangaId"/> for search on Website, use a specific term</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400"><see cref="MetadataFetcher"/> (Metadata-Sites) with <paramref name="MetadataFetcherName"/> does not exist</response>
|
||||||
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||||
|
[HttpPost("{MetadataFetcherName}/SearchManga/{MangaId}")]
|
||||||
|
[ProducesResponseType<MetadataSearchResult[]>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
public async Task<Results<Ok<List<MetadataSearchResult>>, BadRequest, NotFound<string>>> SearchMangaMetadata(string MangaId, string MetadataFetcherName, [FromBody (EmptyBodyBehavior = EmptyBodyBehavior.Allow)]string? searchTerm = null)
|
||||||
|
{
|
||||||
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
|
if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is not { } fetcher)
|
||||||
|
return TypedResults.BadRequest();
|
||||||
|
|
||||||
|
MetadataSearchResult[] searchResults = searchTerm is null ? fetcher.SearchMetadataEntry(manga) : fetcher.SearchMetadataEntry(searchTerm);
|
||||||
|
return TypedResults.Ok(searchResults.ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Links <see cref="MetadataFetcher"/> (Metadata-Sites) using Provider-Specific Identifier to <see cref="Manga"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||||
|
/// <param name="MetadataFetcherName"><see cref="MetadataFetcher"/>.Name</param>
|
||||||
|
/// <param name="Identifier"><see cref="MetadataFetcherName"/>-Specific ID</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400"><see cref="MetadataFetcher"/> (Metadata-Sites) with <paramref name="MetadataFetcherName"/> does not exist</response>
|
||||||
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpPost("{MetadataFetcherName}/Link/{MangaId}")]
|
||||||
|
[ProducesResponseType<MetadataEntry>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
|
public async Task<Results<Ok<MetadataEntry>, BadRequest, NotFound<string>, InternalServerError<string>>> LinkMangaMetadata (string MangaId, string MetadataFetcherName, [FromBody]string Identifier)
|
||||||
|
{
|
||||||
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
|
if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is not { } fetcher)
|
||||||
|
return TypedResults.BadRequest();
|
||||||
|
|
||||||
|
MetadataEntry entry = fetcher.CreateMetadataEntry(manga, Identifier);
|
||||||
|
context.MetadataEntries.Add(entry);
|
||||||
|
|
||||||
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
|
return TypedResults.Ok(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Un-Links <see cref="MetadataFetcher"/> (Metadata-Sites) from <see cref="Manga"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="400"><see cref="MetadataFetcher"/> (Metadata-Sites) with <paramref name="MetadataFetcherName"/> does not exist</response>
|
||||||
|
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||||
|
/// <response code="412">No <see cref="MetadataEntry"/> linking <see cref="Manga"/> and <see cref="MetadataFetcher"/> found</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpPost("{MetadataFetcherName}/Unlink/{MangaId}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType(Status412PreconditionFailed)]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
|
public async Task<Results<Ok, BadRequest, NotFound<string>, InternalServerError<string>, StatusCodeHttpResult>> UnlinkMangaMetadata (string MangaId, string MetadataFetcherName)
|
||||||
|
{
|
||||||
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } _)
|
||||||
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
|
if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is null)
|
||||||
|
return TypedResults.BadRequest();
|
||||||
|
if (context.MetadataEntries.FirstOrDefault(e =>
|
||||||
|
e.MangaId == MangaId && e.MetadataFetcherName == MetadataFetcherName) is not { } entry)
|
||||||
|
return TypedResults.StatusCode(Status412PreconditionFailed);
|
||||||
|
|
||||||
|
context.Remove(entry);
|
||||||
|
|
||||||
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using API.APIEndpointRecords;
|
using API.Controllers.DTOs;
|
||||||
using API.Schema.Contexts;
|
using API.Controllers.Requests;
|
||||||
using API.Schema.NotificationConnectors;
|
using API.Schema.NotificationsContext;
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using log4net;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
|
|
||||||
@@ -13,206 +15,151 @@ namespace API.Controllers;
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
[Route("v{v:apiVersion}/[controller]")]
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
public class NotificationConnectorController(NotificationsContext context, ILog Log) : Controller
|
public class NotificationConnectorController(NotificationsContext context) : Controller
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all configured Notification-Connectors
|
/// Gets all configured <see cref="NotificationConnector"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType<NotificationConnector[]>(Status200OK, "application/json")]
|
[ProducesResponseType<List<NotificationConnector>>(Status200OK, "application/json")]
|
||||||
public IActionResult GetAllConnectors()
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public async Task<Results<Ok<List<NotificationConnector>>, InternalServerError>> GetAllConnectors ()
|
||||||
{
|
{
|
||||||
NotificationConnector[] ret = context.NotificationConnectors.ToArray();
|
if(await context.NotificationConnectors.ToListAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
return Ok(ret);
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
List<NotificationConnector> notificationConnectors = result.Select(n => new NotificationConnector(n.Name, n.Url, n.HttpMethod, n.Body, n.Headers)).ToList();
|
||||||
|
|
||||||
|
return TypedResults.Ok(notificationConnectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns Notification-Connector with requested ID
|
/// Returns <see cref="NotificationConnector"/> with requested Name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="NotificationConnectorId">Notification-Connector-ID</param>
|
/// <param name="Name"><see cref="NotificationConnector"/>.Name</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="404">NotificationConnector with ID not found</response>
|
/// <response code="404"><see cref="NotificationConnector"/> with <paramref name="Name"/> not found</response>
|
||||||
[HttpGet("{NotificationConnectorId}")]
|
[HttpGet("{Name}")]
|
||||||
[ProducesResponseType<NotificationConnector>(Status200OK, "application/json")]
|
[ProducesResponseType<NotificationConnector>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
public IActionResult GetConnector(string NotificationConnectorId)
|
public async Task<Results<Ok<NotificationConnector>, NotFound<string>>> GetConnector (string Name)
|
||||||
{
|
{
|
||||||
NotificationConnector? ret = context.NotificationConnectors.Find(NotificationConnectorId);
|
if (await context.NotificationConnectors.FirstOrDefaultAsync(c => c.Name == Name, HttpContext.RequestAborted) is not { } connector)
|
||||||
return (ret is not null) switch
|
return TypedResults.NotFound(nameof(Name));
|
||||||
{
|
|
||||||
true => Ok(ret),
|
NotificationConnector notificationConnector = new NotificationConnector(connector.Name, connector.Url, connector.HttpMethod, connector.Body, connector.Headers);
|
||||||
false => NotFound()
|
|
||||||
};
|
return TypedResults.Ok(notificationConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new REST-Notification-Connector
|
/// Creates a new <see cref="NotificationConnector"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>Formatting placeholders: "%title" and "%text" can be placed in url, header-values and body and will be replaced when notifications are sent</remarks>
|
/// <remarks>Formatting placeholders: "%title" and "%text" can be placed in url, header-values and body and will be replaced when notifications are sent</remarks>
|
||||||
/// <param name="notificationConnector">Notification-Connector</param>
|
/// <response code="200">ID of the new <see cref="NotificationConnector"/></response>
|
||||||
/// <response code="201">ID of new connector</response>
|
|
||||||
/// <response code="409">A NotificationConnector with name already exists</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
[ProducesResponseType<string>(Status201Created, "application/json")]
|
[ProducesResponseType<string>(Status201Created, "text/plain")]
|
||||||
[ProducesResponseType(Status409Conflict)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult CreateConnector([FromBody]NotificationConnector notificationConnector)
|
public async Task<Results<Created<string>, InternalServerError<string>>> CreateConnector ([FromBody]CreateNotificationConnectorRecord requestData)
|
||||||
{
|
{
|
||||||
if (context.NotificationConnectors.Find(notificationConnector.Name) is not null)
|
// TODO validate data
|
||||||
return Conflict();
|
API.Schema.NotificationsContext.NotificationConnectors.NotificationConnector newConnector =
|
||||||
try
|
new(requestData.Name, requestData.Url, requestData.Headers, requestData.HttpMethod, requestData.Body);
|
||||||
{
|
|
||||||
context.NotificationConnectors.Add(notificationConnector);
|
context.NotificationConnectors.Add(newConnector);
|
||||||
context.SaveChanges();
|
context.Notifications.Add(new ("Added new Notification Connector!", newConnector.Name, NotificationUrgency.High));
|
||||||
return Created(notificationConnector.Name, notificationConnector);
|
|
||||||
}
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
catch (Exception e)
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
{
|
return TypedResults.Created(string.Empty, newConnector.Name);
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new Gotify-Notification-Connector
|
/// Creates a new Gotify-<see cref="NotificationConnector"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>Priority needs to be between 0 and 10</remarks>
|
/// <remarks>Priority needs to be between 0 and 10</remarks>
|
||||||
/// <response code="201">ID of new connector</response>
|
/// <response code="200">ID of the new <see cref="NotificationConnector"/></response>
|
||||||
/// <response code="400"></response>
|
|
||||||
/// <response code="409">A NotificationConnector with name already exists</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPut("Gotify")]
|
[HttpPut("Gotify")]
|
||||||
[ProducesResponseType<string>(Status201Created, "application/json")]
|
[ProducesResponseType<string>(Status201Created, "text/plain")]
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType(Status409Conflict)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult CreateGotifyConnector([FromBody]GotifyRecord gotifyData)
|
public async Task<Results<Created<string>, InternalServerError<string>>> CreateGotifyConnector ([FromBody]CreateGotifyConnectorRecord createGotifyConnectorData)
|
||||||
{
|
{
|
||||||
if(!gotifyData.Validate())
|
//TODO Validate Data
|
||||||
return BadRequest();
|
CreateNotificationConnectorRecord gotifyConnector = new (createGotifyConnectorData.Name,
|
||||||
|
createGotifyConnectorData.Url,
|
||||||
NotificationConnector gotifyConnector = new NotificationConnector(TokenGen.CreateToken("Gotify"),
|
|
||||||
gotifyData.endpoint,
|
|
||||||
new Dictionary<string, string>() { { "X-Gotify-Key", gotifyData.appToken } },
|
|
||||||
"POST",
|
"POST",
|
||||||
$"{{\"message\": \"%text\", \"title\": \"%title\", \"priority\": {gotifyData.priority}}}");
|
$"{{\"message\": \"%text\", \"title\": \"%title\", \"Priority\": {createGotifyConnectorData.Priority}}}",
|
||||||
return CreateConnector(gotifyConnector);
|
new () { { "X-Gotify-Key", createGotifyConnectorData.AppToken } });
|
||||||
|
return await CreateConnector(gotifyConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new Ntfy-Notification-Connector
|
/// Creates a new Ntfy-<see cref="NotificationConnector"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>Priority needs to be between 1 and 5</remarks>
|
/// <remarks>Priority needs to be between 1 and 5</remarks>
|
||||||
/// <response code="201">ID of new connector</response>
|
/// <response code="200">ID of the new <see cref="NotificationConnector"/></response>
|
||||||
/// <response code="400"></response>
|
|
||||||
/// <response code="409">A NotificationConnector with name already exists</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPut("Ntfy")]
|
[HttpPut("Ntfy")]
|
||||||
[ProducesResponseType<string>(Status201Created, "application/json")]
|
[ProducesResponseType<string>(Status201Created, "text/plain")]
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType(Status409Conflict)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult CreateNtfyConnector([FromBody]NtfyRecord ntfyRecord)
|
public async Task<Results<Created<string>, InternalServerError<string>>> CreateNtfyConnector ([FromBody]CreateNtfyConnectorRecord createNtfyConnectorRecord)
|
||||||
{
|
{
|
||||||
if(!ntfyRecord.Validate())
|
//TODO Validate Data
|
||||||
return BadRequest();
|
string authHeader = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{createNtfyConnectorRecord.Username}:{createNtfyConnectorRecord.Password}"));
|
||||||
|
|
||||||
string authHeader = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{ntfyRecord.username}:{ntfyRecord.password}"));
|
|
||||||
string auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(authHeader)).Replace("=","");
|
string auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(authHeader)).Replace("=","");
|
||||||
|
|
||||||
NotificationConnector ntfyConnector = new (TokenGen.CreateToken("Ntfy"),
|
CreateNotificationConnectorRecord ntfyConnector = new (createNtfyConnectorRecord.Name,
|
||||||
$"{ntfyRecord.endpoint}?auth={auth}",
|
$"{createNtfyConnectorRecord.Url}?auth={auth}",
|
||||||
new Dictionary<string, string>()
|
|
||||||
{
|
|
||||||
{"Title", "%title"},
|
|
||||||
{"Priority", ntfyRecord.priority.ToString()},
|
|
||||||
},
|
|
||||||
"POST",
|
"POST",
|
||||||
"%text");
|
$"{{\"message\": \"%text\", \"title\": \"%title\", \"Priority\": {createNtfyConnectorRecord.Priority} \"Topic\": \"{createNtfyConnectorRecord.Topic}\"}}",
|
||||||
return CreateConnector(ntfyConnector);
|
new () {{"Authorization", auth}});
|
||||||
|
return await CreateConnector(ntfyConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new Lunasea-Notification-Connector
|
/// Creates a new Pushover-<see cref="NotificationConnector"/>
|
||||||
/// </summary>
|
|
||||||
/// <remarks>https://docs.lunasea.app/lunasea/notifications/custom-notifications for id. Either device/:device_id or user/:user_id</remarks>
|
|
||||||
/// <response code="201">ID of new connector</response>
|
|
||||||
/// <response code="400"></response>
|
|
||||||
/// <response code="409">A NotificationConnector with name already exists</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPut("Lunasea")]
|
|
||||||
[ProducesResponseType<string>(Status201Created, "application/json")]
|
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType(Status409Conflict)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
|
||||||
public IActionResult CreateLunaseaConnector([FromBody]LunaseaRecord lunaseaRecord)
|
|
||||||
{
|
|
||||||
if(!lunaseaRecord.Validate())
|
|
||||||
return BadRequest();
|
|
||||||
|
|
||||||
NotificationConnector lunaseaConnector = new (TokenGen.CreateToken("Lunasea"),
|
|
||||||
$"https://notify.lunasea.app/v1/custom/{lunaseaRecord.id}",
|
|
||||||
new Dictionary<string, string>(),
|
|
||||||
"POST",
|
|
||||||
"{\"title\": \"%title\", \"body\": \"%text\"}");
|
|
||||||
return CreateConnector(lunaseaConnector);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new Pushover-Notification-Connector
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>https://pushover.net/api</remarks>
|
/// <remarks>https://pushover.net/api</remarks>
|
||||||
/// <response code="201">ID of new connector</response>
|
/// <response code="200">ID of the new <see cref="NotificationConnector"/></response>
|
||||||
/// <response code="400"></response>
|
|
||||||
/// <response code="409">A NotificationConnector with name already exists</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPut("Pushover")]
|
[HttpPut("Pushover")]
|
||||||
[ProducesResponseType<string>(Status201Created, "application/json")]
|
[ProducesResponseType<string>(Status201Created, "text/plain")]
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType(Status409Conflict)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult CreatePushoverConnector([FromBody]PushoverRecord pushoverRecord)
|
public async Task<Results<Created<string>, InternalServerError<string>>> CreatePushoverConnector ([FromBody]CreatePushoverConnectorRecord createPushoverConnectorRecord)
|
||||||
{
|
{
|
||||||
if(!pushoverRecord.Validate())
|
//TODO Validate Data
|
||||||
return BadRequest();
|
CreateNotificationConnectorRecord pushoverConnector = new (createPushoverConnectorRecord.Name,
|
||||||
|
|
||||||
NotificationConnector pushoverConnector = new (TokenGen.CreateToken("Pushover"),
|
|
||||||
$"https://api.pushover.net/1/messages.json",
|
$"https://api.pushover.net/1/messages.json",
|
||||||
new Dictionary<string, string>(),
|
|
||||||
"POST",
|
"POST",
|
||||||
$"{{\"token\": \"{pushoverRecord.apptoken}\", \"user\": \"{pushoverRecord.user}\", \"message:\":\"%text\", \"%title\" }}");
|
$"{{\"token\": \"{createPushoverConnectorRecord.AppToken}\", \"user\": \"{createPushoverConnectorRecord.Username}\", \"message:\":\"%text\", \"%title\" }}",
|
||||||
return CreateConnector(pushoverConnector);
|
new ());
|
||||||
|
return await CreateConnector(pushoverConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes the Notification-Connector with the requested ID
|
/// Deletes the <see cref="NotificationConnector"/> with the requested Name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="NotificationConnectorId">Notification-Connector-ID</param>
|
/// <param name="Name"><see cref="NotificationConnector"/>.Name</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="404">NotificationConnector with ID not found</response>
|
/// <response code="404"><see cref="NotificationConnector"/> with Name not found</response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpDelete("{NotificationConnectorId}")]
|
[HttpDelete("{Name}")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult DeleteConnector(string NotificationConnectorId)
|
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> DeleteConnector (string Name)
|
||||||
{
|
{
|
||||||
try
|
if (await context.NotificationConnectors.FirstOrDefaultAsync(c => c.Name == Name, HttpContext.RequestAborted) is not { } connector)
|
||||||
{
|
return TypedResults.NotFound(nameof(Name));
|
||||||
NotificationConnector? ret = context.NotificationConnectors.Find(NotificationConnectorId);
|
|
||||||
if(ret is null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
context.Remove(ret);
|
context.NotificationConnectors.Remove(connector);
|
||||||
context.SaveChanges();
|
|
||||||
return Ok();
|
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
|
||||||
}
|
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||||
catch (Exception e)
|
return TypedResults.Ok();
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
using API.Schema;
|
using API.Controllers.DTOs;
|
||||||
using API.Schema.Contexts;
|
using API.Schema.MangaContext;
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using log4net;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Soenneker.Utils.String.NeedlemanWunsch;
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
using Author = API.Controllers.DTOs.Author;
|
||||||
|
using Chapter = API.Controllers.DTOs.Chapter;
|
||||||
|
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
@@ -11,102 +16,109 @@ namespace API.Controllers;
|
|||||||
[ApiVersion(2)]
|
[ApiVersion(2)]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("v{v:apiVersion}/[controller]")]
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
public class QueryController(PgsqlContext context, ILog Log) : Controller
|
public class QueryController(MangaContext context) : Controller
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the Author-Information for Author-ID
|
/// Returns the <see cref="Author"/> with <paramref name="AuthorId"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="AuthorId">Author-Id</param>
|
/// <param name="AuthorId"><see cref="Author"/>.Key</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="404">Author with ID not found</response>
|
/// <response code="404"><see cref="Author"/> with <paramref name="AuthorId"/> not found</response>
|
||||||
[HttpGet("Author/{AuthorId}")]
|
[HttpGet("Author/{AuthorId}")]
|
||||||
[ProducesResponseType<Author>(Status200OK, "application/json")]
|
[ProducesResponseType<Author>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
public IActionResult GetAuthor(string AuthorId)
|
public async Task<Results<Ok<Author>, NotFound<string>>> GetAuthor (string AuthorId)
|
||||||
{
|
{
|
||||||
Author? ret = context.Authors.Find(AuthorId);
|
if (await context.Authors.FirstOrDefaultAsync(a => a.Key == AuthorId, HttpContext.RequestAborted) is not { } author)
|
||||||
if (ret is null)
|
return TypedResults.NotFound(nameof(AuthorId));
|
||||||
return NotFound();
|
|
||||||
return Ok(ret);
|
return TypedResults.Ok(new Author(author.Key, author.AuthorName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all Mangas which where Authored by Author with AuthorId
|
/// Returns <see cref="Chapter"/> with <paramref name="ChapterId"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="AuthorId">Author-ID</param>
|
/// <param name="ChapterId"><see cref="Chapter"/>.Key</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="404">Author not found</response>
|
/// <response code="404"><see cref="Chapter"/> with <paramref name="ChapterId"/> not found</response>
|
||||||
[HttpGet("Mangas/WithAuthorId/{AuthorId}")]
|
|
||||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
|
||||||
public IActionResult GetMangaWithAuthorIds(string AuthorId)
|
|
||||||
{
|
|
||||||
if(context.Authors.Find(AuthorId) is not { } a)
|
|
||||||
return NotFound();
|
|
||||||
return Ok(context.Mangas.Where(m => m.Authors.Contains(a)));
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
/// <summary>
|
|
||||||
/// Returns Link-Information for Link-Id
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="LinkId"></param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
/// <response code="404">Link with ID not found</response>
|
|
||||||
[HttpGet("Link/{LinkId}")]
|
|
||||||
[ProducesResponseType<Link>(Status200OK, "application/json")]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
public IActionResult GetLink(string LinkId)
|
|
||||||
{
|
|
||||||
Link? ret = context.Links.Find(LinkId);
|
|
||||||
if (ret is null)
|
|
||||||
return NotFound();
|
|
||||||
return Ok(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns AltTitle-Information for AltTitle-Id
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="AltTitleId"></param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
/// <response code="404">AltTitle with ID not found</response>
|
|
||||||
[HttpGet("AltTitle/{AltTitleId}")]
|
|
||||||
[ProducesResponseType<MangaAltTitle>(Status200OK, "application/json")]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
public IActionResult GetAltTitle(string AltTitleId)
|
|
||||||
{
|
|
||||||
MangaAltTitle? ret = context.AltTitles.Find(AltTitleId);
|
|
||||||
if (ret is null)
|
|
||||||
return NotFound();
|
|
||||||
return Ok(ret);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns all Manga with Tag
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="Tag"></param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
/// <response code="404">Tag not found</response>
|
|
||||||
[HttpGet("Mangas/WithTag/{Tag}")]
|
|
||||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
|
||||||
public IActionResult GetMangasWithTag(string Tag)
|
|
||||||
{
|
|
||||||
if(context.Tags.Find(Tag) is not { } t)
|
|
||||||
return NotFound();
|
|
||||||
return Ok(context.Mangas.Where(m => m.MangaTags.Contains(t)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns Chapter-Information for Chapter-Id
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ChapterId"></param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
/// <response code="404">Chapter with ID not found</response>
|
|
||||||
[HttpGet("Chapter/{ChapterId}")]
|
[HttpGet("Chapter/{ChapterId}")]
|
||||||
[ProducesResponseType<Chapter>(Status200OK, "application/json")]
|
[ProducesResponseType<Chapter>(Status200OK, "application/json")]
|
||||||
public IActionResult GetChapter(string ChapterId)
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
public async Task<Results<Ok<Chapter>, NotFound<string>>> GetChapter (string ChapterId)
|
||||||
{
|
{
|
||||||
Chapter? ret = context.Chapters.Find(ChapterId);
|
if (await context.Chapters.FirstOrDefaultAsync(c => c.Key == ChapterId, HttpContext.RequestAborted) is not { } chapter)
|
||||||
if (ret is null)
|
return TypedResults.NotFound(nameof(ChapterId));
|
||||||
return NotFound();
|
|
||||||
return Ok(ret);
|
IEnumerable<MangaConnectorId> ids = chapter.MangaConnectorIds.Select(id =>
|
||||||
|
new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
|
return TypedResults.Ok(new Chapter(chapter.Key, chapter.ParentMangaId, chapter.VolumeNumber, chapter.ChapterNumber, chapter.Title,ids, chapter.Downloaded));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the <see cref="MangaConnectorId{Manga}"/> with <see cref="MangaConnectorId{Manga}"/>.Key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaConnectorIdId">Key of <see cref="MangaConnectorId{Manga}"/></param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="MangaConnectorId{Manga}"/> with <paramref name="MangaConnectorIdId"/> not found</response>
|
||||||
|
[HttpGet("Manga/MangaConnectorId/{MangaConnectorIdId}")]
|
||||||
|
[ProducesResponseType<MangaConnectorId>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
public async Task<Results<Ok<MangaConnectorId>, NotFound<string>>> GetMangaMangaConnectorId (string MangaConnectorIdId)
|
||||||
|
{
|
||||||
|
if (await context.MangaConnectorToManga.FirstOrDefaultAsync(c => c.Key == MangaConnectorIdId, HttpContext.RequestAborted) is not { } mcIdManga)
|
||||||
|
return TypedResults.NotFound(nameof(MangaConnectorIdId));
|
||||||
|
|
||||||
|
MangaConnectorId result = new (mcIdManga.Key, mcIdManga.MangaConnectorName, mcIdManga.ObjId, mcIdManga.WebsiteUrl, mcIdManga.UseForDownload);
|
||||||
|
|
||||||
|
return TypedResults.Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns <see cref="Schema.MangaContext.Manga"/> with names similar to <see cref="Schema.MangaContext.Manga"/> (identified by <paramref name="MangaId"/>)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaId">Key of <see cref="Schema.MangaContext.Manga"/></param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="Schema.MangaContext.Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||||
|
/// <response code="500">Error during Database Operation</response>
|
||||||
|
[HttpGet("Manga/{MangaId}/SimilarName")]
|
||||||
|
[ProducesResponseType<List<string>>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public async Task<Results<Ok<List<string>>, NotFound<string>, InternalServerError>> GetSimilarManga (string MangaId)
|
||||||
|
{
|
||||||
|
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||||
|
return TypedResults.NotFound(nameof(MangaId));
|
||||||
|
|
||||||
|
string name = manga.Name;
|
||||||
|
|
||||||
|
if (await context.Mangas.Where(m => m.Key != MangaId)
|
||||||
|
.ToDictionaryAsync(m => m.Key, m => m.Name, HttpContext.RequestAborted) is not { } mangaNames)
|
||||||
|
return TypedResults.InternalServerError();
|
||||||
|
|
||||||
|
List<string> similarIds = mangaNames
|
||||||
|
.Where(kv => NeedlemanWunschStringUtil.CalculateSimilarityPercentage(name, kv.Value) > 0.8)
|
||||||
|
.Select(kv => kv.Key)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return TypedResults.Ok(similarIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the <see cref="MangaConnectorId{Chapter}"/> with <see cref="MangaConnectorId{Chapter}"/>.Key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MangaConnectorIdId">Key of <see cref="MangaConnectorId{Manga}"/></param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="MangaConnectorId{Chapter}"/> with <paramref name="MangaConnectorIdId"/> not found</response>
|
||||||
|
[HttpGet("Chapter/MangaConnectorId/{MangaConnectorIdId}")]
|
||||||
|
[ProducesResponseType<MangaConnectorId>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
public async Task<Results<Ok<MangaConnectorId>, NotFound<string>>> GetChapterMangaConnectorId (string MangaConnectorIdId)
|
||||||
|
{
|
||||||
|
if (await context.MangaConnectorToManga.FirstOrDefaultAsync(c => c.Key == MangaConnectorIdId, HttpContext.RequestAborted) is not { } mcIdChapter)
|
||||||
|
return TypedResults.NotFound(nameof(MangaConnectorIdId));
|
||||||
|
|
||||||
|
MangaConnectorId result = new(mcIdChapter.Key, mcIdChapter.MangaConnectorName, mcIdChapter.ObjId, mcIdChapter.WebsiteUrl, mcIdChapter.UseForDownload);
|
||||||
|
|
||||||
|
return TypedResults.Ok(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
37
API/Controllers/Requests/CreateGotifyConnectorRecord.cs
Normal file
37
API/Controllers/Requests/CreateGotifyConnectorRecord.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.Requests;
|
||||||
|
|
||||||
|
public record CreateGotifyConnectorRecord(string Name, string Url, string AppToken, int Priority)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Name of the Notification Connector
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Name of the Notification Connector")]
|
||||||
|
public string Name { get; init; } = Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Url of the Instance
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Formatting placeholders: "%title" and "%text" will be replaced when notifications are sent</remarks>
|
||||||
|
[Required]
|
||||||
|
[Url]
|
||||||
|
[Description("The Url of the Instance")]
|
||||||
|
public string Url { get; internal set; } = Url;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Apptoken used for authentication
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Apptoken used for authentication")]
|
||||||
|
public string AppToken { get; init; } = AppToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Priority of Notifications
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Priority of Notifications")]
|
||||||
|
public int Priority { get; init; } = Priority;
|
||||||
|
}
|
||||||
37
API/Controllers/Requests/CreateLibraryConnectorRecord.cs
Normal file
37
API/Controllers/Requests/CreateLibraryConnectorRecord.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using API.Schema.LibraryContext.LibraryConnectors;
|
||||||
|
|
||||||
|
namespace API.Controllers.Requests;
|
||||||
|
|
||||||
|
public sealed record CreateLibraryConnectorRecord(LibraryType LibraryType, string Url, string Username, string Password)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="LibraryType"/>
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Library Type")]
|
||||||
|
public LibraryType LibraryType { get; init; } = LibraryType;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Url of the Library instance
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Url]
|
||||||
|
[Description("The Url of the Library instance")]
|
||||||
|
public string Url { get; init; } = Url;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Username to authenticate to the Library instance
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Username to authenticate to the Library instance")]
|
||||||
|
public string Username { get; init; } = Username;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Password to authenticate to the Library instance
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Password to authenticate to the Library instance")]
|
||||||
|
public string Password { get; init; } = Password;
|
||||||
|
}
|
||||||
21
API/Controllers/Requests/CreateLibraryRecord.cs
Normal file
21
API/Controllers/Requests/CreateLibraryRecord.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.Requests;
|
||||||
|
|
||||||
|
public sealed record CreateLibraryRecord(string BasePath, string LibraryName)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The directory Path of the library
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The directory Path of the library")]
|
||||||
|
public string BasePath { get; init; } = BasePath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Name of the library
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Name of the library")]
|
||||||
|
public string LibraryName { get; init; } = LibraryName;
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.Requests;
|
||||||
|
|
||||||
|
public record CreateNotificationConnectorRecord(string Name, string Url, string HttpMethod, string Body, Dictionary<string, string> Headers)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Name of the Notification Connector
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Name of the Notification Connector")]
|
||||||
|
public string Name { get; init; } = Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Url of the Instance
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Formatting placeholders: "%title" and "%text" will be replaced when notifications are sent</remarks>
|
||||||
|
[Required]
|
||||||
|
[Url]
|
||||||
|
[Description("The Url of the Instance")]
|
||||||
|
public string Url { get; internal set; } = Url;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The HTTP Request Method to use for notifications
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The HTTP Request Method to use for notifications")]
|
||||||
|
public string HttpMethod { get; internal set; } = HttpMethod;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Request Body to use to send notifications
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Formatting placeholders: "%title" and "%text" will be replaced when notifications are sent</remarks>
|
||||||
|
[Required]
|
||||||
|
[Description("The Request Body to use to send notifications")]
|
||||||
|
public string Body { get; internal set; } = Body;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Request Headers to use to send notifications
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Formatting placeholders: "%title" and "%text" will be replaced when notifications are sent</remarks>
|
||||||
|
[Required]
|
||||||
|
[Description("The Request Headers to use to send notifications")]
|
||||||
|
public Dictionary<string, string> Headers { get; internal set; } = Headers;
|
||||||
|
}
|
||||||
51
API/Controllers/Requests/CreateNtfyConnectorRecord.cs
Normal file
51
API/Controllers/Requests/CreateNtfyConnectorRecord.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.Requests;
|
||||||
|
|
||||||
|
public record CreateNtfyConnectorRecord(string Name, string Url, string Username, string Password, string Topic, int Priority)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Name of the Notification Connector
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Name of the Notification Connector")]
|
||||||
|
public string Name { get; init; } = Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Url of the Instance
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Formatting placeholders: "%title" and "%text" will be replaced when notifications are sent</remarks>
|
||||||
|
[Required]
|
||||||
|
[Url]
|
||||||
|
[Description("The Url of the Instance")]
|
||||||
|
public string Url { get; internal set; } = Url;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Priority of Notifications
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Priority of Notifications")]
|
||||||
|
public int Priority { get; init; } = Priority;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Username used for authentication
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Username used for authentication")]
|
||||||
|
public string Username { get; init; } = Username;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Password used for authentication
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Password used for authentication")]
|
||||||
|
public string Password { get; init; } = Password;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Topic of Notifications
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Topic of Notifications")]
|
||||||
|
public string Topic { get; init; } = Topic;
|
||||||
|
}
|
||||||
28
API/Controllers/Requests/CreatePushoverConnectorRecord.cs
Normal file
28
API/Controllers/Requests/CreatePushoverConnectorRecord.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Controllers.Requests;
|
||||||
|
|
||||||
|
public record CreatePushoverConnectorRecord(string Name, string AppToken, string Username)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Name of the Notification Connector
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Name of the Notification Connector")]
|
||||||
|
public string Name { get; init; } = Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Apptoken used for authentication
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Apptoken used for authentication")]
|
||||||
|
public string AppToken { get; init; } = AppToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Username used for authentication
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[Description("The Username used for authentication")]
|
||||||
|
public string Username { get; init; } = Username;
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
using API.Schema;
|
using API.Controllers.DTOs;
|
||||||
using API.Schema.Contexts;
|
using API.Schema.MangaContext;
|
||||||
using API.Schema.Jobs;
|
|
||||||
using API.Schema.MangaConnectors;
|
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using log4net;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
using Manga = API.Schema.MangaContext.Manga;
|
||||||
|
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
@@ -14,136 +13,67 @@ namespace API.Controllers;
|
|||||||
[ApiVersion(2)]
|
[ApiVersion(2)]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("v{v:apiVersion}/[controller]")]
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
public class SearchController(PgsqlContext context, ILog Log) : Controller
|
public class SearchController(MangaContext context) : Controller
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initiate a search for a Manga on a specific Connector
|
/// Initiate a search for a <see cref="Schema.MangaContext.Manga"/> on <see cref="MangaConnector"/> with searchTerm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaConnectorName"></param>
|
/// <param name="MangaConnectorName"><see cref="MangaConnector"/>.Name</param>
|
||||||
/// <param name="Query"></param>
|
/// <param name="Query">searchTerm</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"><see cref="MinimalManga"/> exert of <see cref="Schema.MangaContext.Manga"/></response>
|
||||||
/// <response code="404">MangaConnector with ID not found</response>
|
/// <response code="404"><see cref="MangaConnector"/> with Name not found</response>
|
||||||
/// <response code="406">MangaConnector with ID is disabled</response>
|
/// <response code="412"><see cref="MangaConnector"/> with Name is disabled</response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
[HttpGet("{MangaConnectorName}/{Query}")]
|
||||||
[HttpPost("{MangaConnectorName}/{Query}")]
|
[ProducesResponseType<List<MinimalManga>>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType(Status406NotAcceptable)]
|
[ProducesResponseType(Status406NotAcceptable)]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
public Results<Ok<List<MinimalManga>>, NotFound<string>, StatusCodeHttpResult> SearchManga (string MangaConnectorName, string Query)
|
||||||
public IActionResult SearchManga(string MangaConnectorName, string Query)
|
|
||||||
{
|
{
|
||||||
if(context.MangaConnectors.Find(MangaConnectorName) is not { } connector)
|
if(Tranga.MangaConnectors.FirstOrDefault(c => c.Name.Equals(MangaConnectorName, StringComparison.InvariantCultureIgnoreCase)) is not { } connector)
|
||||||
return NotFound();
|
return TypedResults.NotFound(nameof(MangaConnectorName));
|
||||||
else if (connector.Enabled is false)
|
if (connector.Enabled is false)
|
||||||
return StatusCode(Status406NotAcceptable);
|
return TypedResults.StatusCode(Status412PreconditionFailed);
|
||||||
|
|
||||||
Manga[] mangas = connector.SearchManga(Query);
|
(Manga manga, MangaConnectorId<Manga> id)[] mangas = connector.SearchManga(Query);
|
||||||
List<Manga> retMangas = new();
|
|
||||||
foreach (Manga manga in mangas)
|
IEnumerable<(Manga manga, MangaConnectorId<Manga> id)> addedManga = mangas.Where(kv => context.AddMangaToContext(kv, HttpContext.RequestAborted).GetAwaiter().GetResult());
|
||||||
|
|
||||||
|
IEnumerable<MinimalManga> result = addedManga.Select(manga => manga.manga).Select(m =>
|
||||||
{
|
{
|
||||||
try
|
IEnumerable<MangaConnectorId> ids = m.MangaConnectorIds.Select(id =>
|
||||||
{
|
new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
if(AddMangaToContext(manga) is { } add)
|
return new MinimalManga(m.Key, m.Name, m.Description, m.ReleaseStatus, ids);
|
||||||
retMangas.Add(add);
|
});
|
||||||
}
|
|
||||||
catch (DbUpdateException e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(Status500InternalServerError, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(retMangas.ToArray());
|
return TypedResults.Ok(result.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns Manga from MangaConnector associated with URL
|
/// Returns <see cref="Schema.MangaContext.Manga"/> from the <see cref="MangaConnector"/> associated with <paramref name="url"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url">Manga-Page URL</param>
|
/// <param name="url"></param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"><see cref="MinimalManga"/> exert of <see cref="Schema.MangaContext.Manga"/>.</response>
|
||||||
/// <response code="300">Multiple connectors found for URL</response>
|
/// <response code="404"><see cref="Manga"/> not found</response>
|
||||||
/// <response code="400">No Manga at URL</response>
|
|
||||||
/// <response code="404">No connector found for URL</response>
|
|
||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPost("Url")]
|
[HttpPost("Url")]
|
||||||
[ProducesResponseType<Manga>(Status200OK, "application/json")]
|
[ProducesResponseType<MinimalManga>(Status200OK, "application/json")]
|
||||||
[ProducesResponseType(Status300MultipleChoices)]
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
|
||||||
[ProducesResponseType(Status404NotFound)]
|
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult GetMangaFromUrl([FromBody]string url)
|
public async Task<Results<Ok<MinimalManga>, NotFound<string>, InternalServerError<string>>> GetMangaFromUrl ([FromBody]string url)
|
||||||
{
|
{
|
||||||
List<MangaConnector> connectors = context.MangaConnectors.AsEnumerable().Where(c => c.UrlMatchesConnector(url)).ToList();
|
if(Tranga.MangaConnectors.FirstOrDefault(c => c.Name.Equals("Global", StringComparison.InvariantCultureIgnoreCase)) is not { } connector)
|
||||||
if (connectors.Count == 0)
|
return TypedResults.InternalServerError("Could not find Global Connector.");
|
||||||
return NotFound();
|
|
||||||
else if (connectors.Count > 1)
|
|
||||||
return StatusCode(Status300MultipleChoices);
|
|
||||||
|
|
||||||
if(connectors.First().GetMangaFromUrl(url) is not { } manga)
|
if(connector.GetMangaFromUrl(url) is not ({ } m, not null) manga)
|
||||||
return BadRequest();
|
return TypedResults.NotFound("Could not retrieve Manga");
|
||||||
try
|
|
||||||
{
|
|
||||||
if(AddMangaToContext(manga) is { } add)
|
|
||||||
return Ok(add);
|
|
||||||
return StatusCode(500);
|
|
||||||
}
|
|
||||||
catch (DbUpdateException e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return StatusCode(500, e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Manga? AddMangaToContext(Manga manga)
|
if(await context.AddMangaToContext(manga, HttpContext.RequestAborted) == false)
|
||||||
{
|
return TypedResults.InternalServerError("Could not add Manga to context");
|
||||||
Manga? existing = context.Mangas.Find(manga.MangaId);
|
|
||||||
|
|
||||||
IEnumerable<MangaTag> mergedTags = manga.MangaTags.Select(mt =>
|
IEnumerable<MangaConnectorId> ids = m.MangaConnectorIds.Select(id =>
|
||||||
{
|
new MangaConnectorId(id.Key, id.MangaConnectorName, id.ObjId, id.WebsiteUrl, id.UseForDownload));
|
||||||
MangaTag? inDb = context.Tags.Find(mt.Tag);
|
MinimalManga result = new (m.Key, m.Name, m.Description, m.ReleaseStatus, ids);
|
||||||
return inDb ?? mt;
|
|
||||||
});
|
|
||||||
manga.MangaTags = mergedTags.ToList();
|
|
||||||
|
|
||||||
IEnumerable<Author> mergedAuthors = manga.Authors.Select(ma =>
|
return TypedResults.Ok(result);
|
||||||
{
|
|
||||||
Author? inDb = context.Authors.Find(ma.AuthorId);
|
|
||||||
return inDb ?? ma;
|
|
||||||
});
|
|
||||||
manga.Authors = mergedAuthors.ToList();
|
|
||||||
|
|
||||||
/*
|
|
||||||
IEnumerable<Link> mergedLinks = manga.Links.Select(ml =>
|
|
||||||
{
|
|
||||||
Link? inDb = context.Links.Find(ml.LinkId);
|
|
||||||
return inDb ?? ml;
|
|
||||||
});
|
|
||||||
manga.Links = mergedLinks.ToList();
|
|
||||||
|
|
||||||
IEnumerable<MangaAltTitle> mergedAltTitles = manga.AltTitles.Select(mat =>
|
|
||||||
{
|
|
||||||
MangaAltTitle? inDb = context.AltTitles.Find(mat.AltTitleId);
|
|
||||||
return inDb ?? mat;
|
|
||||||
});
|
|
||||||
manga.AltTitles = mergedAltTitles.ToList();
|
|
||||||
*/
|
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
if (context.Mangas.Find(manga.MangaId) is { } r)
|
|
||||||
{
|
|
||||||
context.Mangas.Remove(r);
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
context.Mangas.Add(manga);
|
|
||||||
context.Jobs.Add(new DownloadMangaCoverJob(manga));
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
catch (DbUpdateException e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return manga;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,29 +1,26 @@
|
|||||||
using API.MangaDownloadClients;
|
using API.MangaDownloadClients;
|
||||||
using API.Schema;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
using API.Schema.Jobs;
|
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using log4net;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
|
|
||||||
[ApiVersion(2)]
|
[ApiVersion(2)]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("v{v:apiVersion}/[controller]")]
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
public class SettingsController() : Controller
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all Settings
|
/// Get all <see cref="Tranga.Settings"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType<JObject>(Status200OK, "application/json")]
|
[ProducesResponseType<TrangaSettings>(Status200OK, "application/json")]
|
||||||
public IActionResult GetSettings()
|
public Ok<TrangaSettings> GetSettings()
|
||||||
{
|
{
|
||||||
return Ok(JObject.Parse(TrangaSettings.Serialize()));
|
return TypedResults.Ok(Tranga.Settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -32,9 +29,9 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpGet("UserAgent")]
|
[HttpGet("UserAgent")]
|
||||||
[ProducesResponseType<string>(Status200OK, "text/plain")]
|
[ProducesResponseType<string>(Status200OK, "text/plain")]
|
||||||
public IActionResult GetUserAgent()
|
public Ok<string> GetUserAgent()
|
||||||
{
|
{
|
||||||
return Ok(TrangaSettings.userAgent);
|
return TypedResults.Ok(Tranga.Settings.UserAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -43,10 +40,11 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpPatch("UserAgent")]
|
[HttpPatch("UserAgent")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
public IActionResult SetUserAgent([FromBody]string userAgent)
|
public Ok SetUserAgent([FromBody]string userAgent)
|
||||||
{
|
{
|
||||||
TrangaSettings.UpdateUserAgent(userAgent);
|
//TODO Validate
|
||||||
return Ok();
|
Tranga.Settings.SetUserAgent(userAgent);
|
||||||
|
return TypedResults.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -55,10 +53,10 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpDelete("UserAgent")]
|
[HttpDelete("UserAgent")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
public IActionResult ResetUserAgent()
|
public Ok ResetUserAgent()
|
||||||
{
|
{
|
||||||
TrangaSettings.UpdateUserAgent(TrangaSettings.DefaultUserAgent);
|
Tranga.Settings.SetUserAgent(TrangaSettings.DefaultUserAgent);
|
||||||
return Ok();
|
return TypedResults.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -67,9 +65,9 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpGet("RequestLimits")]
|
[HttpGet("RequestLimits")]
|
||||||
[ProducesResponseType<Dictionary<RequestType,int>>(Status200OK, "application/json")]
|
[ProducesResponseType<Dictionary<RequestType,int>>(Status200OK, "application/json")]
|
||||||
public IActionResult GetRequestLimits()
|
public Ok<Dictionary<RequestType,int>> GetRequestLimits()
|
||||||
{
|
{
|
||||||
return Ok(TrangaSettings.requestLimits);
|
return TypedResults.Ok(Tranga.Settings.RequestLimits);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -78,9 +76,9 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// <remarks><h1>NOT IMPLEMENTED</h1></remarks>
|
/// <remarks><h1>NOT IMPLEMENTED</h1></remarks>
|
||||||
[HttpPatch("RequestLimits")]
|
[HttpPatch("RequestLimits")]
|
||||||
[ProducesResponseType(Status501NotImplemented)]
|
[ProducesResponseType(Status501NotImplemented)]
|
||||||
public IActionResult SetRequestLimits()
|
public StatusCodeHttpResult SetRequestLimits()
|
||||||
{
|
{
|
||||||
return StatusCode(501);
|
return TypedResults.StatusCode(Status501NotImplemented);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -93,12 +91,12 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
[HttpPatch("RequestLimits/{RequestType}")]
|
[HttpPatch("RequestLimits/{RequestType}")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
public IActionResult SetRequestLimit(RequestType RequestType, [FromBody]int requestLimit)
|
public Results<Ok, BadRequest> SetRequestLimit(RequestType RequestType, [FromBody]int requestLimit)
|
||||||
{
|
{
|
||||||
if (requestLimit <= 0)
|
if (requestLimit <= 0)
|
||||||
return BadRequest();
|
return TypedResults.BadRequest();
|
||||||
TrangaSettings.UpdateRequestLimit(RequestType, requestLimit);
|
Tranga.Settings.SetRequestLimit(RequestType, requestLimit);
|
||||||
return Ok();
|
return TypedResults.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -107,10 +105,10 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpDelete("RequestLimits/{RequestType}")]
|
[HttpDelete("RequestLimits/{RequestType}")]
|
||||||
[ProducesResponseType<string>(Status200OK)]
|
[ProducesResponseType<string>(Status200OK)]
|
||||||
public IActionResult ResetRequestLimits(RequestType RequestType)
|
public Ok ResetRequestLimits(RequestType RequestType)
|
||||||
{
|
{
|
||||||
TrangaSettings.UpdateRequestLimit(RequestType, TrangaSettings.DefaultRequestLimits[RequestType]);
|
Tranga.Settings.SetRequestLimit(RequestType, TrangaSettings.DefaultRequestLimits[RequestType]);
|
||||||
return Ok();
|
return TypedResults.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -119,38 +117,38 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpDelete("RequestLimits")]
|
[HttpDelete("RequestLimits")]
|
||||||
[ProducesResponseType<string>(Status200OK)]
|
[ProducesResponseType<string>(Status200OK)]
|
||||||
public IActionResult ResetRequestLimits()
|
public Ok ResetRequestLimits()
|
||||||
{
|
{
|
||||||
TrangaSettings.ResetRequestLimits();
|
Tranga.Settings.ResetRequestLimits();
|
||||||
return Ok();
|
return TypedResults.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns Level of Image-Compression for Images
|
/// Returns Level of Image-Compression for Images
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <response code="200">JPEG compression-level as Integer</response>
|
/// <response code="200">JPEG ImageCompression-level as Integer</response>
|
||||||
[HttpGet("ImageCompression")]
|
[HttpGet("ImageCompressionLevel")]
|
||||||
[ProducesResponseType<int>(Status200OK, "text/plain")]
|
[ProducesResponseType<int>(Status200OK, "text/plain")]
|
||||||
public IActionResult GetImageCompression()
|
public Ok<int> GetImageCompression()
|
||||||
{
|
{
|
||||||
return Ok(TrangaSettings.compression);
|
return TypedResults.Ok(Tranga.Settings.ImageCompression);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the Image-Compression-Level for Images
|
/// Set the Image-Compression-Level for Images
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="level">100 to disable, 0-99 for JPEG compression-Level</param>
|
/// <param name="level">100 to disable, 0-99 for JPEG ImageCompression-Level</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="400">Level outside permitted range</response>
|
/// <response code="400">Level outside permitted range</response>
|
||||||
[HttpPatch("ImageCompression")]
|
[HttpPatch("ImageCompressionLevel/{level}")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
public IActionResult SetImageCompression([FromBody]int level)
|
public Results<Ok, BadRequest> SetImageCompression(int level)
|
||||||
{
|
{
|
||||||
if (level < 1 || level > 100)
|
if (level < 1 || level > 100)
|
||||||
return BadRequest();
|
return TypedResults.BadRequest();
|
||||||
TrangaSettings.UpdateCompressImages(level);
|
Tranga.Settings.UpdateImageCompression(level);
|
||||||
return Ok();
|
return TypedResults.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -159,9 +157,9 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// <response code="200">True if enabled</response>
|
/// <response code="200">True if enabled</response>
|
||||||
[HttpGet("BWImages")]
|
[HttpGet("BWImages")]
|
||||||
[ProducesResponseType<bool>(Status200OK, "text/plain")]
|
[ProducesResponseType<bool>(Status200OK, "text/plain")]
|
||||||
public IActionResult GetBwImagesToggle()
|
public Ok<bool> GetBwImagesToggle()
|
||||||
{
|
{
|
||||||
return Ok(TrangaSettings.bwImages);
|
return TypedResults.Ok(Tranga.Settings.BlackWhiteImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -169,38 +167,12 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="enabled">true to enable</param>
|
/// <param name="enabled">true to enable</param>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpPatch("BWImages")]
|
[HttpPatch("BWImages/{enabled}")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
public IActionResult SetBwImagesToggle([FromBody]bool enabled)
|
public Ok SetBwImagesToggle(bool enabled)
|
||||||
{
|
{
|
||||||
TrangaSettings.UpdateBwImages(enabled);
|
Tranga.Settings.SetBlackWhiteImageEnabled(enabled);
|
||||||
return Ok();
|
return TypedResults.Ok();
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get state of April Fools Mode
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>April Fools Mode disables all downloads on April 1st</remarks>
|
|
||||||
/// <response code="200">True if enabled</response>
|
|
||||||
[HttpGet("AprilFoolsMode")]
|
|
||||||
[ProducesResponseType<bool>(Status200OK, "text/plain")]
|
|
||||||
public IActionResult GetAprilFoolsMode()
|
|
||||||
{
|
|
||||||
return Ok(TrangaSettings.aprilFoolsMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Enable/Disable April Fools Mode
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>April Fools Mode disables all downloads on April 1st</remarks>
|
|
||||||
/// <param name="enabled">true to enable</param>
|
|
||||||
/// <response code="200"></response>
|
|
||||||
[HttpPatch("AprilFoolsMode")]
|
|
||||||
[ProducesResponseType(Status200OK)]
|
|
||||||
public IActionResult SetAprilFoolsMode([FromBody]bool enabled)
|
|
||||||
{
|
|
||||||
TrangaSettings.UpdateAprilFoolsMode(enabled);
|
|
||||||
return Ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -208,14 +180,14 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Placeholders:
|
/// Placeholders:
|
||||||
/// %M Manga Name
|
/// %M Obj Name
|
||||||
/// %V Volume
|
/// %V Volume
|
||||||
/// %C Chapter
|
/// %C Chapter
|
||||||
/// %T Title
|
/// %T Title
|
||||||
/// %A Author (first in list)
|
/// %A Author (first in list)
|
||||||
/// %I Chapter Internal ID
|
/// %I Chapter Internal ID
|
||||||
/// %i Manga Internal ID
|
/// %i Obj Internal ID
|
||||||
/// %Y Year (Manga)
|
/// %Y Year (Obj)
|
||||||
///
|
///
|
||||||
/// ?_(...) replace _ with a value from above:
|
/// ?_(...) replace _ with a value from above:
|
||||||
/// Everything inside the braces will only be added if the value of %_ is not null
|
/// Everything inside the braces will only be added if the value of %_ is not null
|
||||||
@@ -223,9 +195,9 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
[HttpGet("ChapterNamingScheme")]
|
[HttpGet("ChapterNamingScheme")]
|
||||||
[ProducesResponseType<string>(Status200OK, "text/plain")]
|
[ProducesResponseType<string>(Status200OK, "text/plain")]
|
||||||
public IActionResult GetCustomNamingScheme()
|
public Ok<string> GetCustomNamingScheme()
|
||||||
{
|
{
|
||||||
return Ok(TrangaSettings.chapterNamingScheme);
|
return TypedResults.Ok(Tranga.Settings.ChapterNamingScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -233,38 +205,89 @@ public class SettingsController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Placeholders:
|
/// Placeholders:
|
||||||
/// %M Manga Name
|
/// %M Obj Name
|
||||||
/// %V Volume
|
/// %V Volume
|
||||||
/// %C Chapter
|
/// %C Chapter
|
||||||
/// %T Title
|
/// %T Title
|
||||||
/// %A Author (first in list)
|
/// %A Author (first in list)
|
||||||
/// %I Chapter Internal ID
|
/// %Y Year (Obj)
|
||||||
/// %i Manga Internal ID
|
|
||||||
/// %Y Year (Manga)
|
|
||||||
///
|
///
|
||||||
/// ?_(...) replace _ with a value from above:
|
/// ?_(...) replace _ with a value from above:
|
||||||
/// Everything inside the braces will only be added if the value of %_ is not null
|
/// Everything inside the braces will only be added if the value of %_ is not null
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <response code="200"></response>
|
/// <response code="200"></response>
|
||||||
/// <response code="500">Error during Database Operation</response>
|
|
||||||
[HttpPatch("ChapterNamingScheme")]
|
[HttpPatch("ChapterNamingScheme")]
|
||||||
[ProducesResponseType(Status200OK)]
|
[ProducesResponseType(Status200OK)]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
public Ok SetCustomNamingScheme([FromBody]string namingScheme)
|
||||||
public IActionResult SetCustomNamingScheme([FromBody]string namingScheme)
|
|
||||||
{
|
{
|
||||||
try
|
//TODO Move old Chapters
|
||||||
{
|
Tranga.Settings.SetChapterNamingScheme(namingScheme);
|
||||||
Dictionary<Chapter, string> oldPaths = context.Chapters.ToDictionary(c => c, c => c.FullArchiveFilePath);
|
|
||||||
TrangaSettings.UpdateChapterNamingScheme(namingScheme);
|
return TypedResults.Ok();
|
||||||
MoveFileOrFolderJob[] newJobs = oldPaths
|
}
|
||||||
.Select(kv => new MoveFileOrFolderJob(kv.Value, kv.Key.FullArchiveFilePath)).ToArray();
|
|
||||||
context.Jobs.AddRange(newJobs);
|
/// <summary>
|
||||||
return Ok();
|
/// Sets the FlareSolverr-URL
|
||||||
}
|
/// </summary>
|
||||||
catch (Exception e)
|
/// <param name="flareSolverrUrl">URL of FlareSolverr-Instance</param>
|
||||||
{
|
/// <response code="200"></response>
|
||||||
Log.Error(e);
|
[HttpPost("FlareSolverr/Url")]
|
||||||
return StatusCode(500, e);
|
[ProducesResponseType(Status200OK)]
|
||||||
}
|
public Ok SetFlareSolverrUrl([FromBody]string flareSolverrUrl)
|
||||||
|
{
|
||||||
|
Tranga.Settings.SetFlareSolverrUrl(flareSolverrUrl);
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resets the FlareSolverr-URL (HttpClient does not use FlareSolverr anymore)
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
[HttpDelete("FlareSolverr/Url")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
public Ok ClearFlareSolverrUrl()
|
||||||
|
{
|
||||||
|
Tranga.Settings.SetFlareSolverrUrl(string.Empty);
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test FlareSolverr
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200">FlareSolverr is working!</response>
|
||||||
|
/// <response code="500">FlareSolverr is not working</response>
|
||||||
|
[HttpPost("FlareSolverr/Test")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public Results<Ok, InternalServerError> TestFlareSolverrReachable()
|
||||||
|
{
|
||||||
|
const string knownProtectedUrl = "https://prowlarr.servarr.com/v1/ping";
|
||||||
|
FlareSolverrDownloadClient client = new();
|
||||||
|
RequestResult result = client.MakeRequestInternal(knownProtectedUrl);
|
||||||
|
return (int)result.statusCode >= 200 && (int)result.statusCode < 300 ? TypedResults.Ok() : TypedResults.InternalServerError();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the language in which Manga are downloaded
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
[HttpGet("DownloadLanguage")]
|
||||||
|
[ProducesResponseType<string>(Status200OK, "text/plain")]
|
||||||
|
public Ok<string> GetDownloadLanguage()
|
||||||
|
{
|
||||||
|
return TypedResults.Ok(Tranga.Settings.DownloadLanguage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the language in which Manga are downloaded
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
[HttpPatch("DownloadLanguage/{Language}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
public Ok SetDownloadLanguage(string Language)
|
||||||
|
{
|
||||||
|
//TODO Validation
|
||||||
|
Tranga.Settings.SetDownloadLanguage(Language);
|
||||||
|
return TypedResults.Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
135
API/Controllers/WorkerController.cs
Normal file
135
API/Controllers/WorkerController.cs
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
using API.Controllers.DTOs;
|
||||||
|
using API.Workers;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Route("v{version:apiVersion}/[controller]")]
|
||||||
|
public class WorkerController : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all <see cref="BaseWorker"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200"><see cref="Worker"/></response>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType<List<Worker>>(Status200OK, "application/json")]
|
||||||
|
public Ok<List<Worker>> GetWorkers()
|
||||||
|
{
|
||||||
|
IEnumerable<Worker> result = Tranga.GetRunningWorkers().Select(w =>
|
||||||
|
new Worker(w.Key, w.AllDependencies.Select(d => d.Key), w.MissingDependencies.Select(d => d.Key), w.AllDependenciesFulfilled, w.State));
|
||||||
|
return TypedResults.Ok(result.ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all <see cref="BaseWorker"/>.Keys
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
[HttpGet("Keys")]
|
||||||
|
[ProducesResponseType<string[]>(Status200OK, "application/json")]
|
||||||
|
public Ok<List<string>> GetWorkerIds()
|
||||||
|
{
|
||||||
|
return TypedResults.Ok(Tranga.GetRunningWorkers().Select(w => w.Key).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all <see cref="BaseWorker"/> in requested <see cref="WorkerExecutionState"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="State">Requested <see cref="WorkerExecutionState"/></param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
[HttpGet("State/{State}")]
|
||||||
|
[ProducesResponseType<List<Worker>>(Status200OK, "application/json")]
|
||||||
|
public Ok<List<Worker>> GetWorkersInState(WorkerExecutionState State)
|
||||||
|
{
|
||||||
|
IEnumerable<Worker> result = Tranga.GetRunningWorkers().Where(worker => worker.State == State).Select(w =>
|
||||||
|
new Worker(w.Key, w.AllDependencies.Select(d => d.Key), w.MissingDependencies.Select(d => d.Key), w.AllDependenciesFulfilled, w.State));
|
||||||
|
return TypedResults.Ok(result.ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return <see cref="BaseWorker"/> with <paramref name="WorkerId"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="WorkerId"><see cref="BaseWorker"/>.Key</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="BaseWorker"/> with <paramref name="WorkerId"/> could not be found</response>
|
||||||
|
[HttpGet("{WorkerId}")]
|
||||||
|
[ProducesResponseType<Worker>(Status200OK, "application/json")]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
public Results<Ok<Worker>, NotFound<string>> GetWorker(string WorkerId)
|
||||||
|
{
|
||||||
|
if(Tranga.GetRunningWorkers().FirstOrDefault(w => w.Key == WorkerId) is not { } w)
|
||||||
|
return TypedResults.NotFound(nameof(WorkerId));
|
||||||
|
|
||||||
|
Worker result = new (w.Key, w.AllDependencies.Select(d => d.Key), w.MissingDependencies.Select(d => d.Key), w.AllDependenciesFulfilled, w.State);
|
||||||
|
|
||||||
|
return TypedResults.Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete <see cref="BaseWorker"/> with <paramref name="WorkerId"/> and all child-<see cref="BaseWorker"/>s
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="WorkerId"><see cref="BaseWorker"/>.Key</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="BaseWorker"/> with <paramref name="WorkerId"/> could not be found</response>
|
||||||
|
[HttpDelete("{WorkerId}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
public Results<Ok, NotFound<string>> DeleteWorker(string WorkerId)
|
||||||
|
{
|
||||||
|
if(Tranga.GetRunningWorkers().FirstOrDefault(w => w.Key == WorkerId) is not { } worker)
|
||||||
|
return TypedResults.NotFound(nameof(WorkerId));
|
||||||
|
Tranga.StopWorker(worker);
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts <see cref="BaseWorker"/> with <paramref name="WorkerId"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="WorkerId"><see cref="BaseWorker"/>.Key</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="BaseWorker"/> with <paramref name="WorkerId"/> could not be found</response>
|
||||||
|
/// <response code="412"><see cref="BaseWorker"/> was already running</response>
|
||||||
|
[HttpPost("{WorkerId}/Start")]
|
||||||
|
[ProducesResponseType(Status202Accepted)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType(Status412PreconditionFailed)]
|
||||||
|
public Results<Ok, NotFound<string>, StatusCodeHttpResult> StartWorker(string WorkerId)
|
||||||
|
{
|
||||||
|
if(Tranga.GetRunningWorkers().FirstOrDefault(w => w.Key == WorkerId) is not { } worker)
|
||||||
|
return TypedResults.NotFound(nameof(WorkerId));
|
||||||
|
|
||||||
|
if (worker.State >= WorkerExecutionState.Waiting)
|
||||||
|
return TypedResults.StatusCode(Status412PreconditionFailed);
|
||||||
|
|
||||||
|
Tranga.StartWorker(worker);
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stops <see cref="BaseWorker"/> with <paramref name="WorkerId"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="WorkerId"><see cref="BaseWorker"/>.Key</param>
|
||||||
|
/// <response code="200"></response>
|
||||||
|
/// <response code="404"><see cref="BaseWorker"/> with <paramref name="WorkerId"/> could not be found</response>
|
||||||
|
/// <response code="412"><see cref="BaseWorker"/> was already not running</response>
|
||||||
|
[HttpPost("{WorkerId}/Stop")]
|
||||||
|
[ProducesResponseType(Status202Accepted)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||||
|
[ProducesResponseType(Status412PreconditionFailed)]
|
||||||
|
public Results<Ok, NotFound<string>, StatusCodeHttpResult> StopWorker(string WorkerId)
|
||||||
|
{
|
||||||
|
if(Tranga.GetRunningWorkers().FirstOrDefault(w => w.Key == WorkerId) is not { } worker)
|
||||||
|
return TypedResults.NotFound(nameof(WorkerId));
|
||||||
|
|
||||||
|
if(worker.State is < WorkerExecutionState.Running or >= WorkerExecutionState.Completed)
|
||||||
|
return TypedResults.StatusCode(Status412PreconditionFailed);
|
||||||
|
|
||||||
|
Tranga.StopWorker(worker);
|
||||||
|
return TypedResults.Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
23
API/Log4Net.config.xml
Normal file
23
API/Log4Net.config.xml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<log4net>
|
||||||
|
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
|
||||||
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
|
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
|
||||||
|
<file value="/usr/share/tranga-api/log/Tranga.log" />
|
||||||
|
<appendToFile value="true" />
|
||||||
|
<rollingStyle value="Composite" />
|
||||||
|
<datePattern value="yyyyMMdd" />
|
||||||
|
<maxSizeRollBackups value="4" />
|
||||||
|
<maximumFileSize value="256MB" />
|
||||||
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
|
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
<root>
|
||||||
|
<level value="DEBUG" />
|
||||||
|
<appender-ref ref="ConsoleAppender" />
|
||||||
|
<appender-ref ref="RollingLogFileAppender" />
|
||||||
|
</root>
|
||||||
|
</log4net>
|
||||||
262
API/MangaConnectors/ComickIo.cs
Normal file
262
API/MangaConnectors/ComickIo.cs
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using API.Schema.MangaContext;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace API.MangaConnectors;
|
||||||
|
|
||||||
|
public class ComickIo : MangaConnector
|
||||||
|
{
|
||||||
|
//https://api.comick.io/docs/
|
||||||
|
//https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
|
||||||
|
|
||||||
|
public ComickIo() : base("ComickIo",
|
||||||
|
["en","pt","pt-br","it","de","ru","aa","ab","ae","af","ak","am","an","ar-ae","ar-bh","ar-dz","ar-eg","ar-iq","ar-jo","ar-kw","ar-lb","ar-ly","ar-ma","ar-om","ar-qa","ar-sa","ar-sy","ar-tn","ar-ye","ar","as","av","ay","az","ba","be","bg","bh","bi","bm","bn","bo","br","bs","ca","ce","ch","co","cr","cs","cu","cv","cy","da","de-at","de-ch","de-de","de-li","de-lu","div","dv","dz","ee","el","en-au","en-bz","en-ca","en-cb","en-gb","en-ie","en-jm","en-nz","en-ph","en-tt","en-us","en-za","en-zw","eo","es-ar","es-bo","es-cl","es-co","es-cr","es-do","es-ec","es-es","es-gt","es-hn","es-la","es-mx","es-ni","es-pa","es-pe","es-pr","es-py","es-sv","es-us","es-uy","es-ve","es","et","eu","fa","ff","fi","fj","fo","fr-be","fr-ca","fr-ch","fr-fr","fr-lu","fr-mc","fr","fy","ga","gd","gl","gn","gu","gv","ha","he","hi","ho","hr-ba","hr-hr","hr","ht","hu","hy","hz","ia","id","ie","ig","ii","ik","in","io","is","it-ch","it-it","iu","iw","ja","ja-ro","ji","jv","jw","ka","kg","ki","kj","kk","kl","km","kn","ko","ko-ro","kr","ks","ku","kv","kw","ky","kz","la","lb","lg","li","ln","lo","ls","lt","lu","lv","mg","mh","mi","mk","ml","mn","mo","mr","ms-bn","ms-my","ms","mt","my","na","nb","nd","ne","ng","nl-be","nl-nl","nl","nn","no","nr","ns","nv","ny","oc","oj","om","or","os","pa","pi","pl","ps","pt-pt","qu-bo","qu-ec","qu-pe","qu","rm","rn","ro","rw","sa","sb","sc","sd","se-fi","se-no","se-se","se","sg","sh","si","sk","sl","sm","sn","so","sq","sr-ba","sr-sp","sr","ss","st","su","sv-fi","sv-se","sv","sw","sx","syr","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ty","ug","uk","ur","us","uz","ve","vi","vo","wa","wo","xh","yi","yo","za","zh-cn","zh-hk","zh-mo","zh-ro","zh-sg","zh-tw","zh","zu"],
|
||||||
|
["comick.io"],
|
||||||
|
"https://comick.io/static/icons/unicorn-64.png")
|
||||||
|
{
|
||||||
|
this.downloadClient = new HttpDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, MangaConnectorId<Manga>)[] SearchManga(string mangaSearchName)
|
||||||
|
{
|
||||||
|
Log.Info($"Searching Obj: {mangaSearchName}");
|
||||||
|
|
||||||
|
List<string> slugs = new();
|
||||||
|
int page = 1;
|
||||||
|
while(page < 50)
|
||||||
|
{
|
||||||
|
string requestUrl = $"https://api.comick.fun/v1.0/search/?type=comic&t=false&limit=100&showall=true&" +
|
||||||
|
$"page={page}&q={mangaSearchName}";
|
||||||
|
|
||||||
|
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||||
|
{
|
||||||
|
Log.Error("Request failed");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
using StreamReader sr = new (result.result);
|
||||||
|
JArray data = JArray.Parse(sr.ReadToEnd());
|
||||||
|
|
||||||
|
if (data.Count < 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
slugs.AddRange(data.Select(token => token.Value<string>("slug")!));
|
||||||
|
page++;
|
||||||
|
}
|
||||||
|
Log.Debug($"Search {mangaSearchName} yielded {slugs.Count} slugs. Requesting mangas now...");
|
||||||
|
|
||||||
|
|
||||||
|
List<(Manga, MangaConnectorId<Manga>)> mangas = new ();
|
||||||
|
foreach (string slug in slugs)
|
||||||
|
{
|
||||||
|
if(GetMangaFromId(slug) is { } entry)
|
||||||
|
mangas.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Info($"Search {mangaSearchName} yielded {mangas.Count} results.");
|
||||||
|
return mangas.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Regex _getSlugFromTitleRex = new(@"https?:\/\/comick\.io\/comic\/(.+)(?:\/.*)*");
|
||||||
|
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
Match m = _getSlugFromTitleRex.Match(url);
|
||||||
|
return m.Groups[1].Success ? GetMangaFromId(m.Groups[1].Value) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromId(string mangaIdOnSite)
|
||||||
|
{
|
||||||
|
string requestUrl = $"https://api.comick.fun/comic/{mangaIdOnSite}";
|
||||||
|
|
||||||
|
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.MangaInfo);
|
||||||
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||||
|
{
|
||||||
|
Log.Error("Request failed");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using StreamReader sr = new (result.result);
|
||||||
|
JToken data = JToken.Parse(sr.ReadToEnd());
|
||||||
|
|
||||||
|
return ParseMangaFromJToken(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Chapter, MangaConnectorId<Chapter>)[] GetChapters(MangaConnectorId<Manga> mangaConnectorId,
|
||||||
|
string? language = null)
|
||||||
|
{
|
||||||
|
Log.Info($"Getting Chapters: {mangaConnectorId.IdOnConnectorSite}");
|
||||||
|
List<(Chapter, MangaConnectorId<Chapter>)> chapters = new();
|
||||||
|
int page = 1;
|
||||||
|
while(page < 50)
|
||||||
|
{
|
||||||
|
string requestUrl = $"https://api.comick.fun/comic/{mangaConnectorId.IdOnConnectorSite}/chapters?limit=100&page={page}&lang={language}";
|
||||||
|
|
||||||
|
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.MangaInfo);
|
||||||
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||||
|
{
|
||||||
|
Log.Error("Request failed");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
using StreamReader sr = new (result.result);
|
||||||
|
JToken data = JToken.Parse(sr.ReadToEnd());
|
||||||
|
JArray? chaptersArray = data["chapters"] as JArray;
|
||||||
|
|
||||||
|
if (chaptersArray is null || chaptersArray.Count < 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
chapters.AddRange(ParseChapters(mangaConnectorId, chaptersArray));
|
||||||
|
|
||||||
|
page++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return chapters.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Regex _hidFromUrl = new(@"https?:\/\/comick\.io\/comic\/.+\/([^-]+).*");
|
||||||
|
internal override string[] GetChapterImageUrls(MangaConnectorId<Chapter> chapterId)
|
||||||
|
{
|
||||||
|
|
||||||
|
Log.Info($"Getting Chapter Image-Urls: {chapterId.Obj}");
|
||||||
|
if (chapterId.WebsiteUrl is null || !UrlMatchesConnector(chapterId.WebsiteUrl))
|
||||||
|
{
|
||||||
|
Log.Debug($"Url is not for Connector. {chapterId.WebsiteUrl}");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
Match m = _hidFromUrl.Match(chapterId.WebsiteUrl);
|
||||||
|
if (!m.Groups[1].Success)
|
||||||
|
{
|
||||||
|
Log.Debug($"Could not parse hid from url. {chapterId.WebsiteUrl}");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
string hid = m.Groups[1].Value;
|
||||||
|
|
||||||
|
string requestUrl = $"https://api.comick.fun/chapter/{hid}/get_images";
|
||||||
|
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.MangaInfo);
|
||||||
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||||
|
{
|
||||||
|
Log.Error("Request failed");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
using StreamReader sr = new (result.result);
|
||||||
|
JArray data = JArray.Parse(sr.ReadToEnd());
|
||||||
|
|
||||||
|
return data.Select(token =>
|
||||||
|
{
|
||||||
|
string url = $"https://meo.comick.pictures/{token.Value<string>("b2key")}";
|
||||||
|
return url;
|
||||||
|
}).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga manga, MangaConnectorId<Manga> id) ParseMangaFromJToken(JToken json)
|
||||||
|
{
|
||||||
|
string? hid = json["comic"]?.Value<string>("hid");
|
||||||
|
string? slug = json["comic"]?.Value<string>("slug");
|
||||||
|
string? name = json["comic"]?.Value<string>("title");
|
||||||
|
string? description = json["comic"]?.Value<string>("desc");
|
||||||
|
string? originalLanguage = json["comic"]?.Value<string>("country");
|
||||||
|
string url = $"https://comick.io/comic/{slug}";
|
||||||
|
string? coverName = json["comic"]?["md_covers"]?.First?.Value<string>("b2key");
|
||||||
|
string coverUrl = $"https://meo.comick.pictures/{coverName}";
|
||||||
|
int? releaseStatusStr = json["comic"]?.Value<int>("status");
|
||||||
|
MangaReleaseStatus status = releaseStatusStr switch
|
||||||
|
{
|
||||||
|
1 => MangaReleaseStatus.Continuing,
|
||||||
|
2 => MangaReleaseStatus.Completed,
|
||||||
|
3 => MangaReleaseStatus.Cancelled,
|
||||||
|
4 => MangaReleaseStatus.OnHiatus,
|
||||||
|
_ => MangaReleaseStatus.Unreleased
|
||||||
|
};
|
||||||
|
uint? year = json["comic"]?.Value<uint?>("year");
|
||||||
|
JArray? altTitlesArray = json["comic"]?["md_titles"] as JArray;
|
||||||
|
//Cant let language be null, so fill with whatever.
|
||||||
|
byte whatever = 0;
|
||||||
|
List<AltTitle> altTitles = altTitlesArray?
|
||||||
|
.Select(token => new AltTitle(token.Value<string>("lang")??whatever++.ToString(), token.Value<string>("title")!))
|
||||||
|
.ToList()??[];
|
||||||
|
|
||||||
|
JArray? authorsArray = json["authors"] as JArray;
|
||||||
|
JArray? artistsArray = json["artists"] as JArray;
|
||||||
|
List<Author> authors = authorsArray?.Concat(artistsArray!)
|
||||||
|
.Select(token => new Author(token.Value<string>("name")!))
|
||||||
|
.DistinctBy(a => a.Key)
|
||||||
|
.ToList()??[];
|
||||||
|
|
||||||
|
JArray? genreArray = json["comic"]?["md_comic_md_genres"] as JArray;
|
||||||
|
List<MangaTag> tags = genreArray?
|
||||||
|
.Select(token => new MangaTag(token["md_genres"]?.Value<string>("name")!))
|
||||||
|
.ToList()??[];
|
||||||
|
|
||||||
|
JArray? linksArray = json["comic"]?["links"] as JArray;
|
||||||
|
List<Link> links = linksArray?
|
||||||
|
.ToObject<Dictionary<string,string>>()?
|
||||||
|
.Select(kv =>
|
||||||
|
{
|
||||||
|
string fullUrl = kv.Key switch
|
||||||
|
{
|
||||||
|
"al" => $"https://anilist.co/manga/{kv.Value}",
|
||||||
|
"ap" => $"https://www.anime-planet.com/manga/{kv.Value}",
|
||||||
|
"bw" => $"https://bookwalker.jp/{kv.Value}",
|
||||||
|
"mu" => $"https://www.mangaupdates.com/series.html?id={kv.Value}",
|
||||||
|
"nu" => $"https://www.novelupdates.com/series/{kv.Value}",
|
||||||
|
"mal" => $"https://myanimelist.net/manga/{kv.Value}",
|
||||||
|
_ => kv.Value
|
||||||
|
};
|
||||||
|
string key = kv.Key switch
|
||||||
|
{
|
||||||
|
"al" => "AniList",
|
||||||
|
"ap" => "Anime Planet",
|
||||||
|
"bw" => "BookWalker",
|
||||||
|
"mu" => "Obj Updates",
|
||||||
|
"nu" => "Novel Updates",
|
||||||
|
"kt" => "Kitsu.io",
|
||||||
|
"amz" => "Amazon",
|
||||||
|
"ebj" => "eBookJapan",
|
||||||
|
"mal" => "MyAnimeList",
|
||||||
|
"cdj" => "CDJapan",
|
||||||
|
_ => kv.Key
|
||||||
|
};
|
||||||
|
return new Link(key, fullUrl);
|
||||||
|
}).ToList()??[];
|
||||||
|
|
||||||
|
if(hid is null)
|
||||||
|
throw new Exception("hid is null");
|
||||||
|
if(slug is null)
|
||||||
|
throw new Exception("slug is null");
|
||||||
|
if(name is null)
|
||||||
|
throw new Exception("name is null");
|
||||||
|
|
||||||
|
Manga manga = new (name, description??"", coverUrl, status, authors, tags, links, altTitles,
|
||||||
|
year: year, originalLanguage: originalLanguage);
|
||||||
|
MangaConnectorId<Manga> mcId = new (manga, this, hid, url);
|
||||||
|
manga.MangaConnectorIds.Add(mcId);
|
||||||
|
return (manga, mcId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<(Chapter, MangaConnectorId<Chapter>)> ParseChapters(MangaConnectorId<Manga> mcIdManga, JArray chaptersArray)
|
||||||
|
{
|
||||||
|
List<(Chapter, MangaConnectorId<Chapter>)> chapters = new ();
|
||||||
|
foreach (JToken chapter in chaptersArray)
|
||||||
|
{
|
||||||
|
string? chapterNum = chapter.Value<string>("chap");
|
||||||
|
string? volumeNumStr = chapter.Value<string>("vol");
|
||||||
|
int? volumeNum = volumeNumStr is null ? null : int.Parse(volumeNumStr);
|
||||||
|
string? title = chapter.Value<string>("title");
|
||||||
|
string? hid = chapter.Value<string>("hid");
|
||||||
|
string url = $"https://comick.io/comic/{mcIdManga.IdOnConnectorSite}/{hid}";
|
||||||
|
|
||||||
|
if(chapterNum is null || hid is null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Chapter ch = new (mcIdManga.Obj, chapterNum, volumeNum, title);
|
||||||
|
MangaConnectorId<Chapter> mcId = new(ch, this, hid, url);
|
||||||
|
ch.MangaConnectorIds.Add(mcId);
|
||||||
|
chapters.Add((ch, mcId));
|
||||||
|
}
|
||||||
|
return chapters;
|
||||||
|
}
|
||||||
|
}
|
||||||
58
API/MangaConnectors/Global.cs
Normal file
58
API/MangaConnectors/Global.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using API.Schema.MangaContext;
|
||||||
|
|
||||||
|
namespace API.MangaConnectors;
|
||||||
|
|
||||||
|
public class Global : MangaConnector
|
||||||
|
{
|
||||||
|
public Global() : base("Global", ["all"], [""], "https://avatars.githubusercontent.com/u/13404778")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, MangaConnectorId<Manga>)[] SearchManga(string mangaSearchName)
|
||||||
|
{
|
||||||
|
//Get all enabled Connectors
|
||||||
|
MangaConnector[] enabledConnectors = Tranga.MangaConnectors.Where(c => c.Enabled && c.Name != "Global").ToArray();
|
||||||
|
|
||||||
|
//Create Task for each MangaConnector to search simultaneously
|
||||||
|
Task<(Manga, MangaConnectorId<Manga>)[]>[] tasks =
|
||||||
|
enabledConnectors.Select(c => new Task<(Manga, MangaConnectorId<Manga>)[]>(() => c.SearchManga(mangaSearchName))).ToArray();
|
||||||
|
foreach (var task in tasks)
|
||||||
|
task.Start();
|
||||||
|
|
||||||
|
//Wait for all tasks to finish
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Thread.Sleep(50);
|
||||||
|
}while(tasks.Any(t => t.Status < TaskStatus.RanToCompletion));
|
||||||
|
|
||||||
|
//Concatenate all results into one
|
||||||
|
(Manga, MangaConnectorId<Manga>)[] ret = tasks.Select(t => t.IsCompletedSuccessfully ? t.Result : []).ToArray().SelectMany(i => i).ToArray();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
MangaConnector? mc = Tranga.MangaConnectors.FirstOrDefault(c => c.UrlMatchesConnector(url));
|
||||||
|
return mc?.GetMangaFromUrl(url) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromId(string mangaIdOnSite)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Chapter, MangaConnectorId<Chapter>)[] GetChapters(MangaConnectorId<Manga> manga,
|
||||||
|
string? language = null)
|
||||||
|
{
|
||||||
|
if (!Tranga.TryGetMangaConnector(manga.MangaConnectorName, out MangaConnector? mangaConnector))
|
||||||
|
return [];
|
||||||
|
return mangaConnector.GetChapters(manga, language);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(MangaConnectorId<Chapter> chapterId)
|
||||||
|
{
|
||||||
|
if (!Tranga.TryGetMangaConnector(chapterId.MangaConnectorName, out MangaConnector? mangaConnector))
|
||||||
|
return [];
|
||||||
|
return mangaConnector.GetChapterImageUrls(chapterId);
|
||||||
|
}
|
||||||
|
}
|
||||||
91
API/MangaConnectors/MangaConnector.cs
Normal file
91
API/MangaConnectors/MangaConnector.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using API.Schema.MangaContext;
|
||||||
|
using log4net;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using SixLabors.ImageSharp;
|
||||||
|
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||||
|
using SixLabors.ImageSharp.Processing;
|
||||||
|
|
||||||
|
namespace API.MangaConnectors;
|
||||||
|
|
||||||
|
[PrimaryKey("Name")]
|
||||||
|
public abstract class MangaConnector(string name, string[] supportedLanguages, string[] baseUris, string iconUrl)
|
||||||
|
{
|
||||||
|
[NotMapped] internal DownloadClient downloadClient { get; init; } = null!;
|
||||||
|
|
||||||
|
[NotMapped] protected ILog Log { get; init; } = LogManager.GetLogger(name);
|
||||||
|
|
||||||
|
[StringLength(32)] public string Name { get; init; } = name;
|
||||||
|
[StringLength(8)] public string[] SupportedLanguages { get; init; } = supportedLanguages;
|
||||||
|
[StringLength(2048)] public string IconUrl { get; init; } = iconUrl;
|
||||||
|
[StringLength(256)] public string[] BaseUris { get; init; } = baseUris;
|
||||||
|
public bool Enabled { get; internal set; } = true;
|
||||||
|
|
||||||
|
public abstract (Manga, MangaConnectorId<Manga>)[] SearchManga(string mangaSearchName);
|
||||||
|
|
||||||
|
public abstract (Manga, MangaConnectorId<Manga>)? GetMangaFromUrl(string url);
|
||||||
|
|
||||||
|
public abstract (Manga, MangaConnectorId<Manga>)? GetMangaFromId(string mangaIdOnSite);
|
||||||
|
|
||||||
|
public abstract (Chapter, MangaConnectorId<Chapter>)[] GetChapters(MangaConnectorId<Manga> mangaId,
|
||||||
|
string? language = null);
|
||||||
|
|
||||||
|
internal abstract string[] GetChapterImageUrls(MangaConnectorId<Chapter> chapterId);
|
||||||
|
|
||||||
|
public bool UrlMatchesConnector(string url) => BaseUris.Any(baseUri => Regex.IsMatch(url, "https?://" + baseUri + "/.*"));
|
||||||
|
|
||||||
|
internal string? SaveCoverImageToCache(MangaConnectorId<Manga> mangaId, int retries = 3)
|
||||||
|
{
|
||||||
|
if(retries < 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Regex urlRex = new (@"https?:\/\/((?:[a-zA-Z0-9-]+\.)+[a-zA-Z0-9]+)\/(?:.+\/)*(.+\.([a-zA-Z]+))");
|
||||||
|
//https?:\/\/[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.[a-zA-Z0-9]+)\/(?:.+\/)*(.+\.([a-zA-Z]+)) for only second level domains
|
||||||
|
Match match = urlRex.Match(mangaId.Obj.CoverUrl);
|
||||||
|
string filename = $"{match.Groups[1].Value}-{mangaId.ObjId}.{mangaId.MangaConnectorName}.{match.Groups[3].Value}";
|
||||||
|
string saveImagePath = Path.Join(TrangaSettings.coverImageCacheOriginal, filename);
|
||||||
|
|
||||||
|
if (File.Exists(saveImagePath))
|
||||||
|
return filename;
|
||||||
|
|
||||||
|
RequestResult coverResult = downloadClient.MakeRequest(mangaId.Obj.CoverUrl, RequestType.MangaCover, $"https://{match.Groups[1].Value}");
|
||||||
|
if ((int)coverResult.statusCode < 200 || (int)coverResult.statusCode >= 300)
|
||||||
|
return SaveCoverImageToCache(mangaId, --retries);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
coverResult.result.CopyTo(ms);
|
||||||
|
byte[] imageBytes = ms.ToArray();
|
||||||
|
Directory.CreateDirectory(TrangaSettings.coverImageCacheOriginal);
|
||||||
|
File.WriteAllBytes(saveImagePath, imageBytes);
|
||||||
|
|
||||||
|
using Image image = Image.Load(imageBytes);
|
||||||
|
Directory.CreateDirectory(TrangaSettings.coverImageCacheLarge);
|
||||||
|
using Image large = image.Clone(x => x.Resize(new ResizeOptions
|
||||||
|
{ Size = Constants.ImageLgSize, Mode = ResizeMode.Max }));
|
||||||
|
large.SaveAsJpeg(Path.Join(TrangaSettings.coverImageCacheLarge, filename), new (){ Quality = 40 });
|
||||||
|
|
||||||
|
Directory.CreateDirectory(TrangaSettings.coverImageCacheMedium);
|
||||||
|
using Image medium = image.Clone(x => x.Resize(new ResizeOptions
|
||||||
|
{ Size = Constants.ImageMdSize, Mode = ResizeMode.Max }));
|
||||||
|
medium.SaveAsJpeg(Path.Join(TrangaSettings.coverImageCacheMedium, filename), new (){ Quality = 40 });
|
||||||
|
|
||||||
|
Directory.CreateDirectory(TrangaSettings.coverImageCacheSmall);
|
||||||
|
using Image small = image.Clone(x => x.Resize(new ResizeOptions
|
||||||
|
{ Size = Constants.ImageSmSize, Mode = ResizeMode.Max }));
|
||||||
|
small.SaveAsJpeg(Path.Join(TrangaSettings.coverImageCacheSmall, filename), new (){ Quality = 40 });
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using API.MangaDownloadClients;
|
using API.MangaDownloadClients;
|
||||||
|
using API.Schema.MangaContext;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace API.Schema.MangaConnectors;
|
namespace API.MangaConnectors;
|
||||||
|
|
||||||
public class MangaDex : MangaConnector
|
public class MangaDex : MangaConnector
|
||||||
{
|
{
|
||||||
@@ -18,10 +19,10 @@ public class MangaDex : MangaConnector
|
|||||||
}
|
}
|
||||||
|
|
||||||
private const int Limit = 100;
|
private const int Limit = 100;
|
||||||
public override Manga[] SearchManga(string mangaSearchName)
|
public override (Manga, MangaConnectorId<Manga>)[] SearchManga(string mangaSearchName)
|
||||||
{
|
{
|
||||||
Log.Info($"Searching Manga: {mangaSearchName}");
|
Log.Info($"Searching Obj: {mangaSearchName}");
|
||||||
List<Manga> mangas = new ();
|
List<(Manga, MangaConnectorId<Manga>)> mangas = new ();
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int total = int.MaxValue;
|
int total = int.MaxValue;
|
||||||
@@ -67,9 +68,9 @@ public class MangaDex : MangaConnector
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Regex GetMangaIdFromUrl = new(@"https?:\/\/mangadex\.org\/title\/([a-z0-9-]+)\/?.*");
|
private static readonly Regex GetMangaIdFromUrl = new(@"https?:\/\/mangadex\.org\/title\/([a-z0-9-]+)\/?.*");
|
||||||
public override Manga? GetMangaFromUrl(string url)
|
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromUrl(string url)
|
||||||
{
|
{
|
||||||
Log.Info($"Getting Manga: {url}");
|
Log.Info($"Getting Obj: {url}");
|
||||||
if (!UrlMatchesConnector(url))
|
if (!UrlMatchesConnector(url))
|
||||||
{
|
{
|
||||||
Log.Debug($"Url is not for Connector. {url}");
|
Log.Debug($"Url is not for Connector. {url}");
|
||||||
@@ -87,9 +88,9 @@ public class MangaDex : MangaConnector
|
|||||||
return GetMangaFromId(id);
|
return GetMangaFromId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Manga? GetMangaFromId(string mangaIdOnSite)
|
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromId(string mangaIdOnSite)
|
||||||
{
|
{
|
||||||
Log.Info($"Getting Manga: {mangaIdOnSite}");
|
Log.Info($"Getting Obj: {mangaIdOnSite}");
|
||||||
string requestUrl =
|
string requestUrl =
|
||||||
$"https://api.mangadex.org/manga/{mangaIdOnSite}" +
|
$"https://api.mangadex.org/manga/{mangaIdOnSite}" +
|
||||||
$"?includes%5B%5D=manga&includes%5B%5D=cover_art&includes%5B%5D=author&includes%5B%5D=artist&includes%5B%5D=tag'";
|
$"?includes%5B%5D=manga&includes%5B%5D=cover_art&includes%5B%5D=author&includes%5B%5D=artist&includes%5B%5D=tag'";
|
||||||
@@ -118,14 +119,13 @@ public class MangaDex : MangaConnector
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Manga manga = ParseMangaFromJToken(data);
|
return ParseMangaFromJToken(data);
|
||||||
return manga;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Chapter[] GetChapters(Manga manga, string? language = null)
|
public override (Chapter, MangaConnectorId<Chapter>)[] GetChapters(MangaConnectorId<Manga> manga, string? language = null)
|
||||||
{
|
{
|
||||||
Log.Info($"Getting Chapters: {manga.IdOnConnectorSite}");
|
Log.Info($"Getting Chapters: {manga.IdOnConnectorSite}");
|
||||||
List<Chapter> chapters = new ();
|
List<(Chapter, MangaConnectorId<Chapter>)> chapters = new ();
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int total = int.MaxValue;
|
int total = int.MaxValue;
|
||||||
@@ -166,24 +166,24 @@ public class MangaDex : MangaConnector
|
|||||||
chapters.AddRange(data.Select(d => ParseChapterFromJToken(manga, d)));
|
chapters.AddRange(data.Select(d => ParseChapterFromJToken(manga, d)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Info($"Request for chapters for {manga.Name} yielded {chapters.Count} results.");
|
Log.Info($"Request for chapters for {manga.Obj.Name} yielded {chapters.Count} results.");
|
||||||
return chapters.ToArray();
|
return chapters.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Regex GetChapterIdFromUrl = new(@"https?:\/\/mangadex\.org\/chapter\/([a-z0-9-]+)\/?.*");
|
private static readonly Regex GetChapterIdFromUrl = new(@"https?:\/\/mangadex\.org\/chapter\/([a-z0-9-]+)\/?.*");
|
||||||
internal override string[] GetChapterImageUrls(Chapter chapter)
|
internal override string[] GetChapterImageUrls(MangaConnectorId<Chapter> chapterId)
|
||||||
{
|
{
|
||||||
Log.Info($"Getting Chapter Image-Urls: {chapter.Url}");
|
Log.Info($"Getting Chapter Image-Urls: {chapterId.Obj}");
|
||||||
if (!UrlMatchesConnector(chapter.Url))
|
if (chapterId.WebsiteUrl is null || !UrlMatchesConnector(chapterId.WebsiteUrl))
|
||||||
{
|
{
|
||||||
Log.Debug($"Url is not for Connector. {chapter.Url}");
|
Log.Debug($"Url is not for Connector. {chapterId.WebsiteUrl}");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
Match match = GetChapterIdFromUrl.Match(chapter.Url);
|
Match match = GetChapterIdFromUrl.Match(chapterId.WebsiteUrl);
|
||||||
if (!match.Success || !match.Groups[1].Success)
|
if (!match.Success || !match.Groups[1].Success)
|
||||||
{
|
{
|
||||||
Log.Debug($"Url is not for Connector (Could not retrieve id). {chapter.Url}");
|
Log.Debug($"Url is not for Connector (Could not retrieve id). {chapterId.WebsiteUrl}");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,25 +223,28 @@ public class MangaDex : MangaConnector
|
|||||||
return urls.ToArray();
|
return urls.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Manga ParseMangaFromJToken(JToken jToken)
|
private (Manga manga, MangaConnectorId<Manga> id) ParseMangaFromJToken(JToken jToken)
|
||||||
{
|
{
|
||||||
string? id = jToken.Value<string>("id");
|
string? id = jToken.Value<string>("id");
|
||||||
|
if(id is null)
|
||||||
|
throw new Exception("jToken was not in expected format");
|
||||||
|
|
||||||
JObject? attributes = jToken["attributes"] as JObject;
|
JObject? attributes = jToken["attributes"] as JObject;
|
||||||
string? name = attributes?["title"]?.Value<string>("en");
|
if(attributes is null)
|
||||||
string? description = attributes?["description"]?.Value<string>("en");
|
throw new Exception("jToken was not in expected format");
|
||||||
string? status = attributes?["status"]?.Value<string>();
|
string? name = attributes["title"]?.Value<string>("en") ?? attributes["title"]?.First?.First?.Value<string>();
|
||||||
uint? year = attributes?["year"]?.Value<uint>();
|
string description = attributes["description"]?.Value<string>("en")??attributes["description"]?.First?.First?.Value<string>()??"";
|
||||||
string? originalLanguage = attributes?["originalLanguage"]?.Value<string>();
|
string? status = attributes["status"]?.Value<string>();
|
||||||
JArray? altTitlesJArray = attributes?["altTitles"] as JArray;
|
uint? year = attributes["year"]?.Value<uint?>();
|
||||||
JArray? tagsJArray = attributes?["tags"] as JArray;
|
string? originalLanguage = attributes["originalLanguage"]?.Value<string>();
|
||||||
|
JArray? altTitlesJArray = attributes.TryGetValue("altTitles", out JToken? altTitlesArray) ? altTitlesArray as JArray : null;
|
||||||
|
JArray? tagsJArray = attributes.TryGetValue("tags", out JToken? tagsArray) ? tagsArray as JArray : null;
|
||||||
JArray? relationships = jToken["relationships"] as JArray;
|
JArray? relationships = jToken["relationships"] as JArray;
|
||||||
string? coverFileName =
|
if (name is null || status is null || relationships is null)
|
||||||
relationships?.FirstOrDefault(r => r["type"]?.Value<string>() == "cover_art")?["attributes"]?.Value<string>("fileName");
|
throw new Exception("jToken was not in expected format");
|
||||||
|
|
||||||
if (id is null || attributes is null || name is null || description is null || status is null ||
|
string? coverFileName = relationships.FirstOrDefault(r => r["type"]?.Value<string>() == "cover_art")?["attributes"]?.Value<string>("fileName");
|
||||||
altTitlesJArray is null || tagsJArray is null || relationships is null || coverFileName is null)
|
if(coverFileName is null)
|
||||||
throw new Exception("jToken was not in expected format");
|
throw new Exception("jToken was not in expected format");
|
||||||
|
|
||||||
List<Link> links = attributes["links"]?
|
List<Link> links = attributes["links"]?
|
||||||
@@ -264,7 +267,7 @@ public class MangaDex : MangaConnector
|
|||||||
"al" => "AniList",
|
"al" => "AniList",
|
||||||
"ap" => "Anime Planet",
|
"ap" => "Anime Planet",
|
||||||
"bw" => "BookWalker",
|
"bw" => "BookWalker",
|
||||||
"mu" => "Manga Updates",
|
"mu" => "Obj Updates",
|
||||||
"nu" => "Novel Updates",
|
"nu" => "Novel Updates",
|
||||||
"kt" => "Kitsu.io",
|
"kt" => "Kitsu.io",
|
||||||
"amz" => "Amazon",
|
"amz" => "Amazon",
|
||||||
@@ -274,29 +277,29 @@ public class MangaDex : MangaConnector
|
|||||||
_ => kv.Key
|
_ => kv.Key
|
||||||
};
|
};
|
||||||
return new Link(key, url);
|
return new Link(key, url);
|
||||||
}).ToList()!;
|
}).ToList()??[];
|
||||||
|
|
||||||
List<MangaAltTitle> altTitles = altTitlesJArray
|
List<AltTitle> altTitles = altTitlesJArray?
|
||||||
.Select(t =>
|
.Select(t =>
|
||||||
{
|
{
|
||||||
JObject? j = t as JObject;
|
JObject? j = t as JObject;
|
||||||
JProperty? p = j?.Properties().First();
|
JProperty? p = j?.Properties().First();
|
||||||
if (p is null)
|
if (p is null)
|
||||||
return null;
|
return null;
|
||||||
return new MangaAltTitle(p.Name, p.Value.ToString());
|
return new AltTitle(p.Name, p.Value.ToString());
|
||||||
}).Where(x => x is not null).ToList()!;
|
}).Where(x => x is not null).Cast<AltTitle>().ToList()??[];
|
||||||
|
|
||||||
List<MangaTag> tags = tagsJArray
|
List<MangaTag> tags = tagsJArray?
|
||||||
.Where(t => t.Value<string>("type") == "tag")
|
.Where(t => t.Value<string>("type") == "tag")
|
||||||
.Select(t => t["attributes"]?["name"]?.Value<string>("en"))
|
.Select(t => t["attributes"]?["name"]?.Value<string>("en")??t["attributes"]?["name"]?.First?.First?.Value<string>())
|
||||||
.Select(str => str is not null ? new MangaTag(str) : null)
|
.Select(str => str is not null ? new MangaTag(str) : null)
|
||||||
.Where(x => x is not null).ToList()!;
|
.Where(x => x is not null).Cast<MangaTag>().ToList()??[];
|
||||||
|
|
||||||
List<Author> authors = relationships
|
List<Author> authors = relationships
|
||||||
.Where(r => r["type"]?.Value<string>() == "author")
|
.Where(r => r["type"]?.Value<string>() == "author")
|
||||||
.Select(t => t["attributes"]?.Value<string>("name"))
|
.Select(t => t["attributes"]?.Value<string>("name"))
|
||||||
.Select(str => str is not null ? new Author(str) : null)
|
.Select(str => str is not null ? new Author(str) : null)
|
||||||
.Where(x => x is not null).ToList()!;
|
.Where(x => x is not null).Cast<Author>().ToList();
|
||||||
|
|
||||||
|
|
||||||
MangaReleaseStatus releaseStatus = status switch
|
MangaReleaseStatus releaseStatus = status switch
|
||||||
@@ -310,26 +313,31 @@ public class MangaDex : MangaConnector
|
|||||||
string websiteUrl = $"https://mangadex.org/title/{id}";
|
string websiteUrl = $"https://mangadex.org/title/{id}";
|
||||||
string coverUrl = $"https://uploads.mangadex.org/covers/{id}/{coverFileName}";
|
string coverUrl = $"https://uploads.mangadex.org/covers/{id}/{coverFileName}";
|
||||||
|
|
||||||
return new Manga(id, name, description, websiteUrl, coverUrl, releaseStatus, this,
|
Manga manga = new (name, description, coverUrl, releaseStatus, authors, tags, links,altTitles,
|
||||||
authors, tags, links,altTitles,
|
|
||||||
null, 0f, year, originalLanguage);
|
null, 0f, year, originalLanguage);
|
||||||
|
MangaConnectorId<Manga> mcId = new (manga, this, id, websiteUrl);
|
||||||
|
manga.MangaConnectorIds.Add(mcId);
|
||||||
|
return (manga, mcId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Chapter ParseChapterFromJToken(Manga parentManga, JToken jToken)
|
private (Chapter chapter, MangaConnectorId<Chapter> id) ParseChapterFromJToken(MangaConnectorId<Manga> mcIdManga, JToken jToken)
|
||||||
{
|
{
|
||||||
string? id = jToken.Value<string>("id");
|
string? id = jToken.Value<string>("id");
|
||||||
JToken? attributes = jToken["attributes"];
|
JToken? attributes = jToken["attributes"];
|
||||||
string? chapter = attributes?.Value<string>("chapter");
|
string? chapterStr = attributes?.Value<string>("chapter") ?? "0";
|
||||||
string? volumeStr = attributes?.Value<string>("volume");
|
string? volumeStr = attributes?.Value<string>("volume");
|
||||||
int? volume = null;
|
int? volumeNumber = null;
|
||||||
string? title = attributes?.Value<string>("title");
|
string? title = attributes?.Value<string>("title");
|
||||||
|
|
||||||
if(id is null || chapter is null)
|
if(id is null || chapterStr is null)
|
||||||
throw new Exception("jToken was not in expected format");
|
throw new Exception("jToken was not in expected format");
|
||||||
if(volumeStr is not null)
|
if(volumeStr is not null)
|
||||||
volume = int.Parse(volumeStr);
|
volumeNumber = int.Parse(volumeStr);
|
||||||
|
|
||||||
string url = $"https://mangadex.org/chapter/{id}";
|
string websiteUrl = $"https://mangadex.org/chapter/{id}";
|
||||||
return new Chapter(parentManga, url, chapter, volume, title);
|
Chapter chapter = new (mcIdManga.Obj, chapterStr, volumeNumber, title);
|
||||||
|
MangaConnectorId<Chapter> mcId = new(chapter, this, id, websiteUrl);
|
||||||
|
chapter.MangaConnectorIds.Add(mcId);
|
||||||
|
return (chapter, mcId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using HtmlAgilityPack;
|
|
||||||
using log4net;
|
|
||||||
using PuppeteerSharp;
|
|
||||||
|
|
||||||
namespace API.MangaDownloadClients;
|
|
||||||
|
|
||||||
internal class ChromiumDownloadClient : DownloadClient
|
|
||||||
{
|
|
||||||
private static IBrowser? _browser;
|
|
||||||
private readonly HttpDownloadClient _httpDownloadClient;
|
|
||||||
private readonly Thread _closeStalePagesThread;
|
|
||||||
private readonly List<KeyValuePair<IPage, DateTime>> _openPages = new ();
|
|
||||||
|
|
||||||
private static async Task<IBrowser> StartBrowser(ILog log)
|
|
||||||
{
|
|
||||||
return await Puppeteer.LaunchAsync(new LaunchOptions
|
|
||||||
{
|
|
||||||
Headless = true,
|
|
||||||
Args = new [] {
|
|
||||||
"--disable-gpu",
|
|
||||||
"--disable-dev-shm-usage",
|
|
||||||
"--disable-setuid-sandbox",
|
|
||||||
"--no-sandbox"},
|
|
||||||
Timeout = 30000
|
|
||||||
}, new LoggerFactory([new Provider(log)]));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChromiumDownloadClient()
|
|
||||||
{
|
|
||||||
_httpDownloadClient = new();
|
|
||||||
if(_browser is null)
|
|
||||||
_browser = StartBrowser(Log).Result;
|
|
||||||
_closeStalePagesThread = new Thread(CheckStalePages);
|
|
||||||
_closeStalePagesThread.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckStalePages()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
Thread.Sleep(TimeSpan.FromHours(1));
|
|
||||||
Log.Debug("Removing stale pages");
|
|
||||||
foreach ((IPage? key, DateTime value) in _openPages.Where(kv => kv.Value.Subtract(DateTime.Now) > TimeSpan.FromHours(1)))
|
|
||||||
{
|
|
||||||
Log.Debug($"Closing {key.Url}");
|
|
||||||
key.CloseAsync().Wait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Regex _imageUrlRex = new(@"https?:\/\/.*\.(?:p?jpe?g|gif|a?png|bmp|avif|webp)(\?.*)?");
|
|
||||||
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
|
||||||
{
|
|
||||||
Log.Debug($"Requesting {url}");
|
|
||||||
return _imageUrlRex.IsMatch(url)
|
|
||||||
? _httpDownloadClient.MakeRequestInternal(url, referrer)
|
|
||||||
: MakeRequestBrowser(url, referrer, clickButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RequestResult MakeRequestBrowser(string url, string? referrer = null, string? clickButton = null)
|
|
||||||
{
|
|
||||||
if (_browser is null)
|
|
||||||
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
|
||||||
IPage page = _browser.NewPageAsync().Result;
|
|
||||||
_openPages.Add(new(page, DateTime.Now));
|
|
||||||
page.SetExtraHttpHeadersAsync(new() { { "Referer", referrer } });
|
|
||||||
page.DefaultTimeout = 30000;
|
|
||||||
IResponse response;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
response = page.GoToAsync(url, WaitUntilNavigation.Networkidle0).Result;
|
|
||||||
Log.Debug($"Page loaded. {url}");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Info($"Could not load Page {url}\n{e.Message}");
|
|
||||||
page.CloseAsync();
|
|
||||||
_openPages.Remove(_openPages.Find(i => i.Key == page));
|
|
||||||
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
|
||||||
}
|
|
||||||
|
|
||||||
Stream stream = Stream.Null;
|
|
||||||
HtmlDocument? document = null;
|
|
||||||
|
|
||||||
if (response.Headers.TryGetValue("Content-Type", out string? content))
|
|
||||||
{
|
|
||||||
if (content.Contains("text/html"))
|
|
||||||
{
|
|
||||||
if (clickButton is not null && page.QuerySelectorAsync(clickButton).Result is not null)
|
|
||||||
page.ClickAsync(clickButton).Wait();
|
|
||||||
string htmlString = page.GetContentAsync().Result;
|
|
||||||
stream = new MemoryStream(Encoding.Default.GetBytes(htmlString));
|
|
||||||
document = new ();
|
|
||||||
document.LoadHtml(htmlString);
|
|
||||||
}else if (content.Contains("image"))
|
|
||||||
{
|
|
||||||
stream = new MemoryStream(response.BufferAsync().Result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
page.CloseAsync().Wait();
|
|
||||||
_openPages.Remove(_openPages.Find(i => i.Key == page));
|
|
||||||
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
|
||||||
}
|
|
||||||
|
|
||||||
page.CloseAsync().Wait();
|
|
||||||
_openPages.Remove(_openPages.Find(i => i.Key == page));
|
|
||||||
return new RequestResult(response.Status, document, stream, false, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Provider(ILog log) : ILoggerProvider
|
|
||||||
{
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ILogger CreateLogger(string categoryName)
|
|
||||||
{
|
|
||||||
return new ChromiumLogger(log);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ChromiumLogger(ILog log) : ILogger
|
|
||||||
{
|
|
||||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
|
|
||||||
{
|
|
||||||
string message = formatter.Invoke(state, exception);
|
|
||||||
switch(logLevel)
|
|
||||||
{
|
|
||||||
case LogLevel.Critical: log.Fatal(message); break;
|
|
||||||
case LogLevel.Error: log.Error(message); break;
|
|
||||||
case LogLevel.Warning: log.Warn(message); break;
|
|
||||||
case LogLevel.Information: log.Info(message); break;
|
|
||||||
case LogLevel.Debug: log.Debug(message); break;
|
|
||||||
default: log.Info(message); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsEnabled(LogLevel logLevel) => true;
|
|
||||||
|
|
||||||
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
using System.Net;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Net;
|
||||||
using log4net;
|
using log4net;
|
||||||
|
|
||||||
namespace API.MangaDownloadClients;
|
namespace API.MangaDownloadClients;
|
||||||
|
|
||||||
internal abstract class DownloadClient
|
public abstract class DownloadClient
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<RequestType, DateTime> LastExecutedRateLimit = new();
|
private static readonly ConcurrentDictionary<RequestType, DateTime> LastExecutedRateLimit = new();
|
||||||
protected ILog Log { get; init; }
|
protected ILog Log { get; init; }
|
||||||
|
|
||||||
protected DownloadClient()
|
protected DownloadClient()
|
||||||
@@ -13,32 +14,38 @@ internal abstract class DownloadClient
|
|||||||
this.Log = LogManager.GetLogger(GetType());
|
this.Log = LogManager.GetLogger(GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Requests still go too fast across threads!
|
||||||
public RequestResult MakeRequest(string url, RequestType requestType, string? referrer = null, string? clickButton = null)
|
public RequestResult MakeRequest(string url, RequestType requestType, string? referrer = null, string? clickButton = null)
|
||||||
{
|
{
|
||||||
Log.Debug($"Requesting {url}");
|
Log.Debug($"Requesting {requestType} {url}");
|
||||||
if (!TrangaSettings.requestLimits.ContainsKey(requestType))
|
|
||||||
{
|
|
||||||
return new RequestResult(HttpStatusCode.NotAcceptable, null, Stream.Null);
|
|
||||||
}
|
|
||||||
|
|
||||||
int rateLimit = TrangaSettings.userAgent == TrangaSettings.DefaultUserAgent
|
// If we don't have a RequestLimit set for a Type, use the default one
|
||||||
? TrangaSettings.DefaultRequestLimits[requestType]
|
if (!Tranga.Settings.RequestLimits.ContainsKey(requestType))
|
||||||
: TrangaSettings.requestLimits[requestType];
|
requestType = RequestType.Default;
|
||||||
|
|
||||||
|
int rateLimit = Tranga.Settings.RequestLimits[requestType];
|
||||||
|
// TODO this probably needs a better check whether the useragent matches...
|
||||||
|
// If the UserAgent is the default one, do not exceed the default request-limits.
|
||||||
|
if (Tranga.Settings.UserAgent == TrangaSettings.DefaultUserAgent && rateLimit > TrangaSettings.DefaultRequestLimits[requestType])
|
||||||
|
rateLimit = TrangaSettings.DefaultRequestLimits[requestType];
|
||||||
|
|
||||||
|
// Apply the delay
|
||||||
TimeSpan timeBetweenRequests = TimeSpan.FromMinutes(1).Divide(rateLimit);
|
TimeSpan timeBetweenRequests = TimeSpan.FromMinutes(1).Divide(rateLimit);
|
||||||
DateTime now = DateTime.Now;
|
DateTime now = DateTime.Now;
|
||||||
LastExecutedRateLimit.TryAdd(requestType, now.Subtract(timeBetweenRequests));
|
LastExecutedRateLimit.TryAdd(requestType, now.Subtract(timeBetweenRequests));
|
||||||
|
|
||||||
TimeSpan rateLimitTimeout = timeBetweenRequests.Subtract(now.Subtract(LastExecutedRateLimit[requestType]));
|
TimeSpan rateLimitTimeout = timeBetweenRequests.Subtract(now.Subtract(LastExecutedRateLimit[requestType]));
|
||||||
Log.Debug($"Request limit {rateLimit}/Minute timeBetweenRequests: {timeBetweenRequests:ss'.'fffff} Timeout: {rateLimitTimeout:ss'.'fffff}");
|
Log.Debug($"Request limit {requestType} {rateLimit}/Minute timeBetweenRequests: {timeBetweenRequests:ss'.'fffff} Timeout: {rateLimitTimeout:ss'.'fffff}");
|
||||||
|
|
||||||
if (rateLimitTimeout > TimeSpan.Zero)
|
if (rateLimitTimeout > TimeSpan.Zero)
|
||||||
{
|
|
||||||
Thread.Sleep(rateLimitTimeout);
|
Thread.Sleep(rateLimitTimeout);
|
||||||
}
|
|
||||||
|
|
||||||
|
// Make the request
|
||||||
RequestResult result = MakeRequestInternal(url, referrer, clickButton);
|
RequestResult result = MakeRequestInternal(url, referrer, clickButton);
|
||||||
|
|
||||||
|
// Update the time the last request was made
|
||||||
LastExecutedRateLimit[requestType] = DateTime.UtcNow;
|
LastExecutedRateLimit[requestType] = DateTime.UtcNow;
|
||||||
|
Log.Debug($"Result {url}: {result}");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
178
API/MangaDownloadClients/FlareSolverrDownloadClient.cs
Normal file
178
API/MangaDownloadClients/FlareSolverrDownloadClient.cs
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace API.MangaDownloadClients;
|
||||||
|
|
||||||
|
public class FlareSolverrDownloadClient : DownloadClient
|
||||||
|
{
|
||||||
|
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||||
|
{
|
||||||
|
if (clickButton is not null)
|
||||||
|
Log.Warn("Client can not click button");
|
||||||
|
if(referrer is not null)
|
||||||
|
Log.Warn("Client can not set referrer");
|
||||||
|
if (Tranga.Settings.FlareSolverrUrl == string.Empty)
|
||||||
|
{
|
||||||
|
Log.Error("FlareSolverr URL is empty");
|
||||||
|
return new(HttpStatusCode.InternalServerError, null, Stream.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Uri flareSolverrUri = new (Tranga.Settings.FlareSolverrUrl);
|
||||||
|
if (flareSolverrUri.Segments.Last() != "v1")
|
||||||
|
flareSolverrUri = new UriBuilder(flareSolverrUri)
|
||||||
|
{
|
||||||
|
Path = "v1"
|
||||||
|
}.Uri;
|
||||||
|
|
||||||
|
HttpClient client = new()
|
||||||
|
{
|
||||||
|
Timeout = TimeSpan.FromSeconds(10),
|
||||||
|
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher,
|
||||||
|
DefaultRequestHeaders = { { "User-Agent", Tranga.Settings.UserAgent } }
|
||||||
|
};
|
||||||
|
|
||||||
|
JObject requestObj = new()
|
||||||
|
{
|
||||||
|
["cmd"] = "request.get",
|
||||||
|
["url"] = url
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpRequestMessage requestMessage = new(HttpMethod.Post, flareSolverrUri)
|
||||||
|
{
|
||||||
|
Content = new StringContent(JsonConvert.SerializeObject(requestObj)),
|
||||||
|
};
|
||||||
|
requestMessage.Content.Headers.ContentType = new ("application/json");
|
||||||
|
Log.Debug($"Requesting {url}");
|
||||||
|
|
||||||
|
HttpResponseMessage? response;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = client.Send(requestMessage);
|
||||||
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
Log.Error(e);
|
||||||
|
return new (HttpStatusCode.Unused, null, Stream.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
Log.Debug($"Request returned status code {(int)response.StatusCode} {response.StatusCode}:\n" +
|
||||||
|
$"=====\n" +
|
||||||
|
$"Request:\n" +
|
||||||
|
$"{requestMessage.Method} {requestMessage.RequestUri}\n" +
|
||||||
|
$"{requestMessage.Version} {requestMessage.VersionPolicy}\n" +
|
||||||
|
$"Headers:\n\t{string.Join("\n\t", requestMessage.Headers.Select(h => $"{h.Key}: <{string.Join(">, <", h.Value)}"))}>\n" +
|
||||||
|
$"{requestMessage.Content?.ReadAsStringAsync().Result}" +
|
||||||
|
$"=====\n" +
|
||||||
|
$"Response:\n" +
|
||||||
|
$"{response.Version}\n" +
|
||||||
|
$"Headers:\n\t{string.Join("\n\t", response.Headers.Select(h => $"{h.Key}: <{string.Join(">, <", h.Value)}"))}>\n" +
|
||||||
|
$"{response.Content.ReadAsStringAsync().Result}");
|
||||||
|
return new (response.StatusCode, null, Stream.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
string responseString = response.Content.ReadAsStringAsync().Result;
|
||||||
|
JObject responseObj = JObject.Parse(responseString);
|
||||||
|
if (!IsInCorrectFormat(responseObj, out string? reason))
|
||||||
|
{
|
||||||
|
Log.Error($"Wrong format: {reason}");
|
||||||
|
return new(HttpStatusCode.Unused, null, Stream.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
string statusResponse = responseObj["status"]!.Value<string>()!;
|
||||||
|
if (statusResponse != "ok")
|
||||||
|
{
|
||||||
|
Log.Debug($"Status is not ok: {statusResponse}");
|
||||||
|
return new(HttpStatusCode.Unused, null, Stream.Null);
|
||||||
|
}
|
||||||
|
JObject solution = (responseObj["solution"] as JObject)!;
|
||||||
|
|
||||||
|
if (!Enum.TryParse(solution["status"]!.Value<int>().ToString(), out HttpStatusCode statusCode))
|
||||||
|
{
|
||||||
|
Log.Error($"Wrong format: Cant parse status code: {solution["status"]!.Value<int>()}");
|
||||||
|
return new(HttpStatusCode.Unused, null, Stream.Null);
|
||||||
|
}
|
||||||
|
if (statusCode < HttpStatusCode.OK || statusCode >= HttpStatusCode.MultipleChoices)
|
||||||
|
{
|
||||||
|
Log.Debug($"Status is: {statusCode}");
|
||||||
|
return new(statusCode, null, Stream.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (solution["response"]!.Value<string>() is not { } htmlString)
|
||||||
|
{
|
||||||
|
Log.Error("Wrong format: Cant find response in solution");
|
||||||
|
return new(HttpStatusCode.Unused, null, Stream.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsJson(htmlString, out HtmlDocument document, out string? json))
|
||||||
|
{
|
||||||
|
MemoryStream ms = new();
|
||||||
|
ms.Write(Encoding.UTF8.GetBytes(json));
|
||||||
|
ms.Position = 0;
|
||||||
|
return new(statusCode, document, ms);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MemoryStream ms = new();
|
||||||
|
ms.Write(Encoding.UTF8.GetBytes(htmlString));
|
||||||
|
ms.Position = 0;
|
||||||
|
return new(statusCode, document, ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsInCorrectFormat(JObject responseObj, [NotNullWhen(false)]out string? reason)
|
||||||
|
{
|
||||||
|
reason = null;
|
||||||
|
if (!responseObj.ContainsKey("status"))
|
||||||
|
{
|
||||||
|
reason = "Cant find status on response";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responseObj["solution"] is not JObject solution)
|
||||||
|
{
|
||||||
|
reason = "Cant find solution";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!solution.ContainsKey("status"))
|
||||||
|
{
|
||||||
|
reason = "Wrong format: Cant find status in solution";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!solution.ContainsKey("response"))
|
||||||
|
{
|
||||||
|
|
||||||
|
reason = "Wrong format: Cant find response in solution";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsJson(string htmlString, out HtmlDocument document, [NotNullWhen(true)]out string? jsonString)
|
||||||
|
{
|
||||||
|
jsonString = null;
|
||||||
|
document = new();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
|
||||||
|
HtmlNode pre = document.DocumentNode.SelectSingleNode("//pre");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using JsonDocument _ = JsonDocument.Parse(pre.InnerText);
|
||||||
|
jsonString = pre.InnerText;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,46 +5,55 @@ namespace API.MangaDownloadClients;
|
|||||||
|
|
||||||
internal class HttpDownloadClient : DownloadClient
|
internal class HttpDownloadClient : DownloadClient
|
||||||
{
|
{
|
||||||
private static readonly HttpClient Client = new()
|
private static readonly FlareSolverrDownloadClient FlareSolverrDownloadClient = new();
|
||||||
{
|
|
||||||
Timeout = TimeSpan.FromSeconds(10)
|
|
||||||
};
|
|
||||||
|
|
||||||
public HttpDownloadClient()
|
|
||||||
{
|
|
||||||
Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", TrangaSettings.userAgent);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||||
{
|
{
|
||||||
if (clickButton is not null)
|
if (clickButton is not null)
|
||||||
Log.Warn("Can not click button on static site.");
|
Log.Warn("Client can not click button");
|
||||||
HttpResponseMessage? response = null;
|
HttpClient client = new();
|
||||||
while (response is null)
|
client.Timeout = TimeSpan.FromSeconds(10);
|
||||||
|
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
|
||||||
|
client.DefaultRequestHeaders.Add("User-Agent", Tranga.Settings.UserAgent);
|
||||||
|
HttpResponseMessage? response;
|
||||||
|
Uri uri = new(url);
|
||||||
|
HttpRequestMessage requestMessage = new(HttpMethod.Get, uri);
|
||||||
|
if (referrer is not null)
|
||||||
|
requestMessage.Headers.Referrer = new (referrer);
|
||||||
|
Log.Debug($"Requesting {url}");
|
||||||
|
try
|
||||||
{
|
{
|
||||||
HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
|
response = client.Send(requestMessage);
|
||||||
if (referrer is not null)
|
}
|
||||||
requestMessage.Headers.Referrer = new Uri(referrer);
|
catch (HttpRequestException e)
|
||||||
Log.Debug($"Requesting {url}");
|
{
|
||||||
try
|
Log.Error(e);
|
||||||
{
|
return new (HttpStatusCode.Unused, null, Stream.Null);
|
||||||
response = Client.Send(requestMessage);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
switch (e)
|
|
||||||
{
|
|
||||||
case TaskCanceledException:
|
|
||||||
return new RequestResult(HttpStatusCode.RequestTimeout, null, Stream.Null);
|
|
||||||
case HttpRequestException:
|
|
||||||
return new RequestResult(HttpStatusCode.BadRequest, null, Stream.Null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
return new RequestResult(response.StatusCode, null, Stream.Null);
|
Log.Debug($"Request returned status code {(int)response.StatusCode} {response.StatusCode}");
|
||||||
|
if (response.Headers.Server.Any(s =>
|
||||||
|
(s.Product?.Name ?? "").Contains("cloudflare", StringComparison.InvariantCultureIgnoreCase)))
|
||||||
|
{
|
||||||
|
Log.Debug("Retrying with FlareSolverr!");
|
||||||
|
return FlareSolverrDownloadClient.MakeRequestInternal(url, referrer, clickButton);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Debug($"Request returned status code {(int)response.StatusCode} {response.StatusCode}:\n" +
|
||||||
|
$"=====\n" +
|
||||||
|
$"Request:\n" +
|
||||||
|
$"{requestMessage.Method} {requestMessage.RequestUri}\n" +
|
||||||
|
$"{requestMessage.Version} {requestMessage.VersionPolicy}\n" +
|
||||||
|
$"Headers:\n\t{string.Join("\n\t", requestMessage.Headers.Select(h => $"{h.Key}: <{string.Join(">, <", h.Value)}"))}>\n" +
|
||||||
|
$"{requestMessage.Content?.ReadAsStringAsync().Result}" +
|
||||||
|
$"=====\n" +
|
||||||
|
$"Response:\n" +
|
||||||
|
$"{response.Version}\n" +
|
||||||
|
$"Headers:\n\t{string.Join("\n\t", response.Headers.Select(h => $"{h.Key}: <{string.Join(">, <", h.Value)}"))}>\n" +
|
||||||
|
$"{response.Content.ReadAsStringAsync().Result}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream stream;
|
Stream stream;
|
||||||
@@ -55,7 +64,7 @@ internal class HttpDownloadClient : DownloadClient
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(e);
|
Log.Error(e);
|
||||||
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
return new (HttpStatusCode.Unused, null, Stream.Null);
|
||||||
}
|
}
|
||||||
|
|
||||||
HtmlDocument? document = null;
|
HtmlDocument? document = null;
|
||||||
@@ -69,12 +78,11 @@ internal class HttpDownloadClient : DownloadClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Request has been redirected to another page. For example, it redirects directly to the results when there is only 1 result
|
// Request has been redirected to another page. For example, it redirects directly to the results when there is only 1 result
|
||||||
if (response.RequestMessage is not null && response.RequestMessage.RequestUri is not null)
|
if (response.RequestMessage is not null && response.RequestMessage.RequestUri is not null && response.RequestMessage.RequestUri != uri)
|
||||||
{
|
{
|
||||||
return new RequestResult(response.StatusCode, document, stream, true,
|
return new (response.StatusCode, document, stream, true, response.RequestMessage.RequestUri.AbsoluteUri);
|
||||||
response.RequestMessage.RequestUri.AbsoluteUri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RequestResult(response.StatusCode, document, stream);
|
return new (response.StatusCode, document, stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,4 +24,10 @@ public struct RequestResult
|
|||||||
this.hasBeenRedirected = hasBeenRedirected;
|
this.hasBeenRedirected = hasBeenRedirected;
|
||||||
redirectedToUrl = redirectedTo;
|
redirectedToUrl = redirectedTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
$"{(int)statusCode} {statusCode.ToString()} {(hasBeenRedirected ? "Redirected: " : "")} {redirectedToUrl}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
70
API/Migrations/Library/20250703191925_Initial.Designer.cs
generated
Normal file
70
API/Migrations/Library/20250703191925_Initial.Designer.cs
generated
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using API.Schema.LibraryContext;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace API.Migrations.Library
|
||||||
|
{
|
||||||
|
[DbContext(typeof(LibraryContext))]
|
||||||
|
[Migration("20250703191925_Initial")]
|
||||||
|
partial class Initial
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.5")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Auth")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("BaseUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<byte>("LibraryType")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.ToTable("LibraryConnectors");
|
||||||
|
|
||||||
|
b.HasDiscriminator<byte>("LibraryType");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.Kavita", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)1);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.Komga", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)0);
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace API.Migrations.library
|
namespace API.Migrations.Library
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class Initial : Migration
|
public partial class Initial : Migration
|
||||||
@@ -14,14 +14,14 @@ namespace API.Migrations.library
|
|||||||
name: "LibraryConnectors",
|
name: "LibraryConnectors",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
LibraryConnectorId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
Key = table.Column<string>(type: "text", nullable: false),
|
||||||
LibraryType = table.Column<byte>(type: "smallint", nullable: false),
|
LibraryType = table.Column<byte>(type: "smallint", nullable: false),
|
||||||
BaseUrl = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
BaseUrl = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
Auth = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false)
|
Auth = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_LibraryConnectors", x => x.LibraryConnectorId);
|
table.PrimaryKey("PK_LibraryConnectors", x => x.Key);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using API.Schema.Contexts;
|
using API.Schema.LibraryContext;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
@@ -8,25 +8,25 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace API.Migrations.library
|
namespace API.Migrations.Library
|
||||||
{
|
{
|
||||||
[DbContext(typeof(LibraryContext))]
|
[DbContext(typeof(LibraryContext))]
|
||||||
[Migration("20250515120732_Initial")]
|
[Migration("20250901194308_KeyLengthChange")]
|
||||||
partial class Initial
|
partial class KeyLengthChange
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "9.0.3")
|
.HasAnnotation("ProductVersion", "9.0.8")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.LibraryConnectors.LibraryConnector", b =>
|
modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("LibraryConnectorId")
|
b.Property<string>("Key")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
.HasColumnType("character varying(64)");
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ namespace API.Migrations.library
|
|||||||
b.Property<byte>("LibraryType")
|
b.Property<byte>("LibraryType")
|
||||||
.HasColumnType("smallint");
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
b.HasKey("LibraryConnectorId");
|
b.HasKey("Key");
|
||||||
|
|
||||||
b.ToTable("LibraryConnectors");
|
b.ToTable("LibraryConnectors");
|
||||||
|
|
||||||
@@ -52,16 +52,16 @@ namespace API.Migrations.library
|
|||||||
b.UseTphMappingStrategy();
|
b.UseTphMappingStrategy();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.LibraryConnectors.Kavita", b =>
|
modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.Kavita", b =>
|
||||||
{
|
{
|
||||||
b.HasBaseType("API.Schema.LibraryConnectors.LibraryConnector");
|
b.HasBaseType("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector");
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)1);
|
b.HasDiscriminator().HasValue((byte)1);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.LibraryConnectors.Komga", b =>
|
modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.Komga", b =>
|
||||||
{
|
{
|
||||||
b.HasBaseType("API.Schema.LibraryConnectors.LibraryConnector");
|
b.HasBaseType("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector");
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)0);
|
b.HasDiscriminator().HasValue((byte)0);
|
||||||
});
|
});
|
||||||
36
API/Migrations/Library/20250901194308_KeyLengthChange.cs
Normal file
36
API/Migrations/Library/20250901194308_KeyLengthChange.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace API.Migrations.Library
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class KeyLengthChange : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "LibraryConnectors",
|
||||||
|
type: "character varying(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "LibraryConnectors",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)",
|
||||||
|
oldMaxLength: 64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using API.Schema.Contexts;
|
using API.Schema.LibraryContext;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
@@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace API.Migrations.library
|
namespace API.Migrations.Library
|
||||||
{
|
{
|
||||||
[DbContext(typeof(LibraryContext))]
|
[DbContext(typeof(LibraryContext))]
|
||||||
partial class LibraryContextModelSnapshot : ModelSnapshot
|
partial class LibraryContextModelSnapshot : ModelSnapshot
|
||||||
@@ -16,14 +16,14 @@ namespace API.Migrations.library
|
|||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "9.0.3")
|
.HasAnnotation("ProductVersion", "9.0.8")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.LibraryConnectors.LibraryConnector", b =>
|
modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("LibraryConnectorId")
|
b.Property<string>("Key")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
.HasColumnType("character varying(64)");
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ namespace API.Migrations.library
|
|||||||
b.Property<byte>("LibraryType")
|
b.Property<byte>("LibraryType")
|
||||||
.HasColumnType("smallint");
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
b.HasKey("LibraryConnectorId");
|
b.HasKey("Key");
|
||||||
|
|
||||||
b.ToTable("LibraryConnectors");
|
b.ToTable("LibraryConnectors");
|
||||||
|
|
||||||
@@ -49,16 +49,16 @@ namespace API.Migrations.library
|
|||||||
b.UseTphMappingStrategy();
|
b.UseTphMappingStrategy();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.LibraryConnectors.Kavita", b =>
|
modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.Kavita", b =>
|
||||||
{
|
{
|
||||||
b.HasBaseType("API.Schema.LibraryConnectors.LibraryConnector");
|
b.HasBaseType("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector");
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)1);
|
b.HasDiscriminator().HasValue((byte)1);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.LibraryConnectors.Komga", b =>
|
modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.Komga", b =>
|
||||||
{
|
{
|
||||||
b.HasBaseType("API.Schema.LibraryConnectors.LibraryConnector");
|
b.HasBaseType("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector");
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)0);
|
b.HasDiscriminator().HasValue((byte)0);
|
||||||
});
|
});
|
||||||
527
API/Migrations/Manga/20250722203315_Initial.Designer.cs
generated
Normal file
527
API/Migrations/Manga/20250722203315_Initial.Designer.cs
generated
Normal file
@@ -0,0 +1,527 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using API.Schema.MangaContext;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace API.Migrations.Manga
|
||||||
|
{
|
||||||
|
[DbContext(typeof(MangaContext))]
|
||||||
|
[Migration("20250722203315_Initial")]
|
||||||
|
partial class Initial
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.5")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.MangaConnectors.MangaConnector", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("BaseUris")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<bool>("Enabled")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("IconUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(2048)
|
||||||
|
.HasColumnType("character varying(2048)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("SupportedLanguages")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.HasKey("Name");
|
||||||
|
|
||||||
|
b.ToTable("MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator<string>("Name").HasValue("MangaConnector");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Author", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("AuthorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.ToTable("Authors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ChapterNumber")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(10)
|
||||||
|
.HasColumnType("character varying(10)");
|
||||||
|
|
||||||
|
b.Property<bool>("Downloaded")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("FileName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("ParentMangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<int?>("VolumeNumber")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("ParentMangaId");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.FileLibrary", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("BasePath")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("LibraryName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.ToTable("FileLibraries");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Manga", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("CoverFileNameInCache")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("CoverUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("DirectoryName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(1024)
|
||||||
|
.HasColumnType("character varying(1024)");
|
||||||
|
|
||||||
|
b.Property<float>("IgnoreChaptersBefore")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b.Property<string>("LibraryId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("OriginalLanguage")
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<byte>("ReleaseStatus")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.Property<long?>("Year")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("LibraryId");
|
||||||
|
|
||||||
|
b.ToTable("Mangas");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Chapter>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("IdOnConnectorSite")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaConnectorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("ObjId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<bool>("UseForDownload")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("WebsiteUrl")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("ObjId");
|
||||||
|
|
||||||
|
b.ToTable("MangaConnectorToChapter");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Manga>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("IdOnConnectorSite")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaConnectorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("ObjId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<bool>("UseForDownload")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("WebsiteUrl")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("ObjId");
|
||||||
|
|
||||||
|
b.ToTable("MangaConnectorToManga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Tag")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasKey("Tag");
|
||||||
|
|
||||||
|
b.ToTable("Tags");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataEntry", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MetadataFetcherName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Identifier")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("MetadataFetcherName", "Identifier");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.ToTable("MetadataEntries");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MetadataEntry")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(21)
|
||||||
|
.HasColumnType("character varying(21)");
|
||||||
|
|
||||||
|
b.HasKey("Name");
|
||||||
|
|
||||||
|
b.ToTable("MetadataFetcher");
|
||||||
|
|
||||||
|
b.HasDiscriminator<string>("MetadataEntry").HasValue("MetadataFetcher");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AuthorToManga", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("AuthorIds")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MangaIds")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("AuthorIds", "MangaIds");
|
||||||
|
|
||||||
|
b.HasIndex("MangaIds");
|
||||||
|
|
||||||
|
b.ToTable("AuthorToManga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MangaTagToManga", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MangaTagIds")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaIds")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("MangaTagIds", "MangaIds");
|
||||||
|
|
||||||
|
b.HasIndex("MangaIds");
|
||||||
|
|
||||||
|
b.ToTable("MangaTagToManga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.MangaConnectors.ComickIo", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("ComickIo");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.MangaConnectors.Global", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("Global");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.MangaConnectors.MangaDex", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("MangaDex");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MyAnimeList", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("MyAnimeList");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", "ParentManga")
|
||||||
|
.WithMany("Chapters")
|
||||||
|
.HasForeignKey("ParentMangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("ParentManga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Manga", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.FileLibrary", "Library")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("LibraryId")
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
|
b.OwnsMany("API.Schema.MangaContext.AltTitle", "AltTitles", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<string>("Key")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("Language")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b1.Property<string>("MangaKey")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b1.HasKey("Key");
|
||||||
|
|
||||||
|
b1.HasIndex("MangaKey");
|
||||||
|
|
||||||
|
b1.ToTable("AltTitle");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("MangaKey");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.OwnsMany("API.Schema.MangaContext.Link", "Links", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<string>("Key")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("LinkProvider")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b1.Property<string>("LinkUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(2048)
|
||||||
|
.HasColumnType("character varying(2048)");
|
||||||
|
|
||||||
|
b1.Property<string>("MangaKey")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.HasKey("Key");
|
||||||
|
|
||||||
|
b1.HasIndex("MangaKey");
|
||||||
|
|
||||||
|
b1.ToTable("Link");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("MangaKey");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("AltTitles");
|
||||||
|
|
||||||
|
b.Navigation("Library");
|
||||||
|
|
||||||
|
b.Navigation("Links");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Chapter>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Chapter", "Obj")
|
||||||
|
.WithMany("MangaConnectorIds")
|
||||||
|
.HasForeignKey("ObjId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Obj");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Manga>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", "Obj")
|
||||||
|
.WithMany("MangaConnectorIds")
|
||||||
|
.HasForeignKey("ObjId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Obj");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataEntry", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", "Manga")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher", "MetadataFetcher")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MetadataFetcherName")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Manga");
|
||||||
|
|
||||||
|
b.Navigation("MetadataFetcher");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AuthorToManga", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Author", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("AuthorIds")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaIds")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MangaTagToManga", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaIds")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.MangaContext.MangaTag", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaTagIds")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("MangaConnectorIds");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Manga", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Chapters");
|
||||||
|
|
||||||
|
b.Navigation("MangaConnectorIds");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
using System;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace API.Migrations.pgsql
|
namespace API.Migrations.Manga
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class Initial1 : Migration
|
public partial class Initial : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
@@ -15,29 +14,29 @@ namespace API.Migrations.pgsql
|
|||||||
name: "Authors",
|
name: "Authors",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
AuthorId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
Key = table.Column<string>(type: "text", nullable: false),
|
||||||
AuthorName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false)
|
AuthorName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_Authors", x => x.AuthorId);
|
table.PrimaryKey("PK_Authors", x => x.Key);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "LocalLibraries",
|
name: "FileLibraries",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
LocalLibraryId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
Key = table.Column<string>(type: "text", nullable: false),
|
||||||
BasePath = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
BasePath = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
LibraryName = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false)
|
LibraryName = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_LocalLibraries", x => x.LocalLibraryId);
|
table.PrimaryKey("PK_FileLibraries", x => x.Key);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "MangaConnectors",
|
name: "MangaConnector",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Name = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
Name = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||||
@@ -48,7 +47,19 @@ namespace API.Migrations.pgsql
|
|||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_MangaConnectors", x => x.Name);
|
table.PrimaryKey("PK_MangaConnector", x => x.Name);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MetadataFetcher",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false),
|
||||||
|
MetadataEntry = table.Column<string>(type: "character varying(21)", maxLength: 21, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MetadataFetcher", x => x.Name);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
@@ -66,35 +77,46 @@ namespace API.Migrations.pgsql
|
|||||||
name: "Mangas",
|
name: "Mangas",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
MangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
Key = table.Column<string>(type: "text", nullable: false),
|
||||||
IdOnConnectorSite = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
|
||||||
Name = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
|
Name = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
|
||||||
Description = table.Column<string>(type: "text", nullable: false),
|
Description = table.Column<string>(type: "text", nullable: false),
|
||||||
WebsiteUrl = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
|
|
||||||
CoverUrl = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
|
CoverUrl = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
|
||||||
ReleaseStatus = table.Column<byte>(type: "smallint", nullable: false),
|
ReleaseStatus = table.Column<byte>(type: "smallint", nullable: false),
|
||||||
LibraryId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
LibraryId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
||||||
MangaConnectorName = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
||||||
IgnoreChaptersBefore = table.Column<float>(type: "real", nullable: false),
|
IgnoreChaptersBefore = table.Column<float>(type: "real", nullable: false),
|
||||||
DirectoryName = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false),
|
DirectoryName = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false),
|
||||||
CoverFileNameInCache = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
CoverFileNameInCache = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
||||||
Year = table.Column<long>(type: "bigint", nullable: false),
|
Year = table.Column<long>(type: "bigint", nullable: true),
|
||||||
OriginalLanguage = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: true)
|
OriginalLanguage = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: true)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_Mangas", x => x.MangaId);
|
table.PrimaryKey("PK_Mangas", x => x.Key);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Mangas_LocalLibraries_LibraryId",
|
name: "FK_Mangas_FileLibraries_LibraryId",
|
||||||
column: x => x.LibraryId,
|
column: x => x.LibraryId,
|
||||||
principalTable: "LocalLibraries",
|
principalTable: "FileLibraries",
|
||||||
principalColumn: "LocalLibraryId",
|
principalColumn: "Key",
|
||||||
onDelete: ReferentialAction.SetNull);
|
onDelete: ReferentialAction.SetNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "AltTitle",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Key = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Language = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: false),
|
||||||
|
Title = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
MangaKey = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_AltTitle", x => x.Key);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Mangas_MangaConnectors_MangaConnectorName",
|
name: "FK_AltTitle_Mangas_MangaKey",
|
||||||
column: x => x.MangaConnectorName,
|
column: x => x.MangaKey,
|
||||||
principalTable: "MangaConnectors",
|
principalTable: "Mangas",
|
||||||
principalColumn: "Name",
|
principalColumn: "Key",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -102,8 +124,8 @@ namespace API.Migrations.pgsql
|
|||||||
name: "AuthorToManga",
|
name: "AuthorToManga",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
AuthorIds = table.Column<string>(type: "character varying(64)", nullable: false),
|
AuthorIds = table.Column<string>(type: "text", nullable: false),
|
||||||
MangaIds = table.Column<string>(type: "character varying(64)", nullable: false)
|
MangaIds = table.Column<string>(type: "text", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
@@ -112,13 +134,13 @@ namespace API.Migrations.pgsql
|
|||||||
name: "FK_AuthorToManga_Authors_AuthorIds",
|
name: "FK_AuthorToManga_Authors_AuthorIds",
|
||||||
column: x => x.AuthorIds,
|
column: x => x.AuthorIds,
|
||||||
principalTable: "Authors",
|
principalTable: "Authors",
|
||||||
principalColumn: "AuthorId",
|
principalColumn: "Key",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_AuthorToManga_Mangas_MangaIds",
|
name: "FK_AuthorToManga_Mangas_MangaIds",
|
||||||
column: x => x.MangaIds,
|
column: x => x.MangaIds,
|
||||||
principalTable: "Mangas",
|
principalTable: "Mangas",
|
||||||
principalColumn: "MangaId",
|
principalColumn: "Key",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -126,23 +148,22 @@ namespace API.Migrations.pgsql
|
|||||||
name: "Chapters",
|
name: "Chapters",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
ChapterId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
Key = table.Column<string>(type: "text", nullable: false),
|
||||||
ParentMangaId = table.Column<string>(type: "character varying(64)", nullable: false),
|
ParentMangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
VolumeNumber = table.Column<int>(type: "integer", nullable: true),
|
VolumeNumber = table.Column<int>(type: "integer", nullable: true),
|
||||||
ChapterNumber = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: false),
|
ChapterNumber = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: false),
|
||||||
Url = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: false),
|
|
||||||
Title = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
Title = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
||||||
FileName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
FileName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
Downloaded = table.Column<bool>(type: "boolean", nullable: false)
|
Downloaded = table.Column<bool>(type: "boolean", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_Chapters", x => x.ChapterId);
|
table.PrimaryKey("PK_Chapters", x => x.Key);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Chapters_Mangas_ParentMangaId",
|
name: "FK_Chapters_Mangas_ParentMangaId",
|
||||||
column: x => x.ParentMangaId,
|
column: x => x.ParentMangaId,
|
||||||
principalTable: "Mangas",
|
principalTable: "Mangas",
|
||||||
principalColumn: "MangaId",
|
principalColumn: "Key",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -150,39 +171,41 @@ namespace API.Migrations.pgsql
|
|||||||
name: "Link",
|
name: "Link",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
LinkId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
Key = table.Column<string>(type: "text", nullable: false),
|
||||||
LinkProvider = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
LinkProvider = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
LinkUrl = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: false),
|
LinkUrl = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: false),
|
||||||
MangaId = table.Column<string>(type: "character varying(64)", nullable: false)
|
MangaKey = table.Column<string>(type: "text", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_Link", x => x.LinkId);
|
table.PrimaryKey("PK_Link", x => x.Key);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Link_Mangas_MangaId",
|
name: "FK_Link_Mangas_MangaKey",
|
||||||
column: x => x.MangaId,
|
column: x => x.MangaKey,
|
||||||
principalTable: "Mangas",
|
principalTable: "Mangas",
|
||||||
principalColumn: "MangaId",
|
principalColumn: "Key",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "MangaAltTitle",
|
name: "MangaConnectorToManga",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
AltTitleId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
Key = table.Column<string>(type: "text", nullable: false),
|
||||||
Language = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: false),
|
ObjId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
Title = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
MangaConnectorName = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||||
MangaId = table.Column<string>(type: "character varying(64)", nullable: false)
|
IdOnConnectorSite = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
WebsiteUrl = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
||||||
|
UseForDownload = table.Column<bool>(type: "boolean", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_MangaAltTitle", x => x.AltTitleId);
|
table.PrimaryKey("PK_MangaConnectorToManga", x => x.Key);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_MangaAltTitle_Mangas_MangaId",
|
name: "FK_MangaConnectorToManga_Mangas_ObjId",
|
||||||
column: x => x.MangaId,
|
column: x => x.ObjId,
|
||||||
principalTable: "Mangas",
|
principalTable: "Mangas",
|
||||||
principalColumn: "MangaId",
|
principalColumn: "Key",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -191,7 +214,7 @@ namespace API.Migrations.pgsql
|
|||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
MangaTagIds = table.Column<string>(type: "character varying(64)", nullable: false),
|
MangaTagIds = table.Column<string>(type: "character varying(64)", nullable: false),
|
||||||
MangaIds = table.Column<string>(type: "character varying(64)", nullable: false)
|
MangaIds = table.Column<string>(type: "text", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
@@ -200,7 +223,7 @@ namespace API.Migrations.pgsql
|
|||||||
name: "FK_MangaTagToManga_Mangas_MangaIds",
|
name: "FK_MangaTagToManga_Mangas_MangaIds",
|
||||||
column: x => x.MangaIds,
|
column: x => x.MangaIds,
|
||||||
principalTable: "Mangas",
|
principalTable: "Mangas",
|
||||||
principalColumn: "MangaId",
|
principalColumn: "Key",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_MangaTagToManga_Tags_MangaTagIds",
|
name: "FK_MangaTagToManga_Tags_MangaTagIds",
|
||||||
@@ -211,104 +234,57 @@ namespace API.Migrations.pgsql
|
|||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Jobs",
|
name: "MetadataEntries",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
JobId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
MetadataFetcherName = table.Column<string>(type: "text", nullable: false),
|
||||||
ParentJobId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
Identifier = table.Column<string>(type: "text", nullable: false),
|
||||||
JobType = table.Column<byte>(type: "smallint", nullable: false),
|
MangaId = table.Column<string>(type: "text", nullable: false)
|
||||||
RecurrenceMs = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
|
|
||||||
LastExecution = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
||||||
state = table.Column<byte>(type: "smallint", nullable: false),
|
|
||||||
Enabled = table.Column<bool>(type: "boolean", nullable: false),
|
|
||||||
DownloadAvailableChaptersJob_MangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
||||||
MangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
||||||
ChapterId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
||||||
FromLocation = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
||||||
ToLocation = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
||||||
MoveMangaLibraryJob_MangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
||||||
ToLibraryId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
||||||
RetrieveChaptersJob_MangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
||||||
Language = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: true),
|
|
||||||
UpdateFilesDownloadedJob_MangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true)
|
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_Jobs", x => x.JobId);
|
table.PrimaryKey("PK_MetadataEntries", x => new { x.MetadataFetcherName, x.Identifier });
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Jobs_Chapters_ChapterId",
|
name: "FK_MetadataEntries_Mangas_MangaId",
|
||||||
column: x => x.ChapterId,
|
|
||||||
principalTable: "Chapters",
|
|
||||||
principalColumn: "ChapterId",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Jobs_Jobs_ParentJobId",
|
|
||||||
column: x => x.ParentJobId,
|
|
||||||
principalTable: "Jobs",
|
|
||||||
principalColumn: "JobId",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Jobs_LocalLibraries_ToLibraryId",
|
|
||||||
column: x => x.ToLibraryId,
|
|
||||||
principalTable: "LocalLibraries",
|
|
||||||
principalColumn: "LocalLibraryId",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Jobs_Mangas_DownloadAvailableChaptersJob_MangaId",
|
|
||||||
column: x => x.DownloadAvailableChaptersJob_MangaId,
|
|
||||||
principalTable: "Mangas",
|
|
||||||
principalColumn: "MangaId",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Jobs_Mangas_MangaId",
|
|
||||||
column: x => x.MangaId,
|
column: x => x.MangaId,
|
||||||
principalTable: "Mangas",
|
principalTable: "Mangas",
|
||||||
principalColumn: "MangaId",
|
principalColumn: "Key",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Jobs_Mangas_MoveMangaLibraryJob_MangaId",
|
name: "FK_MetadataEntries_MetadataFetcher_MetadataFetcherName",
|
||||||
column: x => x.MoveMangaLibraryJob_MangaId,
|
column: x => x.MetadataFetcherName,
|
||||||
principalTable: "Mangas",
|
principalTable: "MetadataFetcher",
|
||||||
principalColumn: "MangaId",
|
principalColumn: "Name",
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Jobs_Mangas_RetrieveChaptersJob_MangaId",
|
|
||||||
column: x => x.RetrieveChaptersJob_MangaId,
|
|
||||||
principalTable: "Mangas",
|
|
||||||
principalColumn: "MangaId",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Jobs_Mangas_UpdateFilesDownloadedJob_MangaId",
|
|
||||||
column: x => x.UpdateFilesDownloadedJob_MangaId,
|
|
||||||
principalTable: "Mangas",
|
|
||||||
principalColumn: "MangaId",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "JobJob",
|
name: "MangaConnectorToChapter",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
DependsOnJobsJobId = table.Column<string>(type: "character varying(64)", nullable: false),
|
Key = table.Column<string>(type: "text", nullable: false),
|
||||||
JobId = table.Column<string>(type: "character varying(64)", nullable: false)
|
ObjId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
MangaConnectorName = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||||
|
IdOnConnectorSite = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
WebsiteUrl = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
||||||
|
UseForDownload = table.Column<bool>(type: "boolean", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_JobJob", x => new { x.DependsOnJobsJobId, x.JobId });
|
table.PrimaryKey("PK_MangaConnectorToChapter", x => x.Key);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_JobJob_Jobs_DependsOnJobsJobId",
|
name: "FK_MangaConnectorToChapter_Chapters_ObjId",
|
||||||
column: x => x.DependsOnJobsJobId,
|
column: x => x.ObjId,
|
||||||
principalTable: "Jobs",
|
principalTable: "Chapters",
|
||||||
principalColumn: "JobId",
|
principalColumn: "Key",
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_JobJob_Jobs_JobId",
|
|
||||||
column: x => x.JobId,
|
|
||||||
principalTable: "Jobs",
|
|
||||||
principalColumn: "JobId",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_AltTitle_MangaKey",
|
||||||
|
table: "AltTitle",
|
||||||
|
column: "MangaKey");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_AuthorToManga_MangaIds",
|
name: "IX_AuthorToManga_MangaIds",
|
||||||
table: "AuthorToManga",
|
table: "AuthorToManga",
|
||||||
@@ -320,114 +296,80 @@ namespace API.Migrations.pgsql
|
|||||||
column: "ParentMangaId");
|
column: "ParentMangaId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_JobJob_JobId",
|
name: "IX_Link_MangaKey",
|
||||||
table: "JobJob",
|
|
||||||
column: "JobId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Jobs_ChapterId",
|
|
||||||
table: "Jobs",
|
|
||||||
column: "ChapterId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Jobs_DownloadAvailableChaptersJob_MangaId",
|
|
||||||
table: "Jobs",
|
|
||||||
column: "DownloadAvailableChaptersJob_MangaId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Jobs_MangaId",
|
|
||||||
table: "Jobs",
|
|
||||||
column: "MangaId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Jobs_MoveMangaLibraryJob_MangaId",
|
|
||||||
table: "Jobs",
|
|
||||||
column: "MoveMangaLibraryJob_MangaId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Jobs_ParentJobId",
|
|
||||||
table: "Jobs",
|
|
||||||
column: "ParentJobId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Jobs_RetrieveChaptersJob_MangaId",
|
|
||||||
table: "Jobs",
|
|
||||||
column: "RetrieveChaptersJob_MangaId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Jobs_ToLibraryId",
|
|
||||||
table: "Jobs",
|
|
||||||
column: "ToLibraryId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Jobs_UpdateFilesDownloadedJob_MangaId",
|
|
||||||
table: "Jobs",
|
|
||||||
column: "UpdateFilesDownloadedJob_MangaId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Link_MangaId",
|
|
||||||
table: "Link",
|
table: "Link",
|
||||||
column: "MangaId");
|
column: "MangaKey");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_MangaAltTitle_MangaId",
|
name: "IX_MangaConnectorToChapter_ObjId",
|
||||||
table: "MangaAltTitle",
|
table: "MangaConnectorToChapter",
|
||||||
column: "MangaId");
|
column: "ObjId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MangaConnectorToManga_ObjId",
|
||||||
|
table: "MangaConnectorToManga",
|
||||||
|
column: "ObjId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Mangas_LibraryId",
|
name: "IX_Mangas_LibraryId",
|
||||||
table: "Mangas",
|
table: "Mangas",
|
||||||
column: "LibraryId");
|
column: "LibraryId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Mangas_MangaConnectorName",
|
|
||||||
table: "Mangas",
|
|
||||||
column: "MangaConnectorName");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_MangaTagToManga_MangaIds",
|
name: "IX_MangaTagToManga_MangaIds",
|
||||||
table: "MangaTagToManga",
|
table: "MangaTagToManga",
|
||||||
column: "MangaIds");
|
column: "MangaIds");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MetadataEntries_MangaId",
|
||||||
|
table: "MetadataEntries",
|
||||||
|
column: "MangaId");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "AuthorToManga");
|
name: "AltTitle");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "JobJob");
|
name: "AuthorToManga");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Link");
|
name: "Link");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "MangaAltTitle");
|
name: "MangaConnector");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MangaConnectorToChapter");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MangaConnectorToManga");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "MangaTagToManga");
|
name: "MangaTagToManga");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MetadataEntries");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Authors");
|
name: "Authors");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Jobs");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Tags");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Chapters");
|
name: "Chapters");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Tags");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MetadataFetcher");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Mangas");
|
name: "Mangas");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "LocalLibraries");
|
name: "FileLibraries");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "MangaConnectors");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using API.Schema.MangaContext;
|
||||||
using API.Schema.Contexts;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
@@ -9,208 +8,23 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace API.Migrations.pgsql
|
namespace API.Migrations.Manga
|
||||||
{
|
{
|
||||||
[DbContext(typeof(PgsqlContext))]
|
[DbContext(typeof(MangaContext))]
|
||||||
[Migration("20250515120724_Initial-1")]
|
[Migration("20250901194144_KeyLengthChange")]
|
||||||
partial class Initial1
|
partial class KeyLengthChange
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "9.0.3")
|
.HasAnnotation("ProductVersion", "9.0.8")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Author", b =>
|
modelBuilder.Entity("API.MangaConnectors.MangaConnector", b =>
|
||||||
{
|
|
||||||
b.Property<string>("AuthorId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("AuthorName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(128)
|
|
||||||
.HasColumnType("character varying(128)");
|
|
||||||
|
|
||||||
b.HasKey("AuthorId");
|
|
||||||
|
|
||||||
b.ToTable("Authors");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Chapter", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("ChapterId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("ChapterNumber")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(10)
|
|
||||||
.HasColumnType("character varying(10)");
|
|
||||||
|
|
||||||
b.Property<bool>("Downloaded")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<string>("FileName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.Property<string>("ParentMangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("Title")
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.Property<string>("Url")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(2048)
|
|
||||||
.HasColumnType("character varying(2048)");
|
|
||||||
|
|
||||||
b.Property<int?>("VolumeNumber")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("ChapterId");
|
|
||||||
|
|
||||||
b.HasIndex("ParentMangaId");
|
|
||||||
|
|
||||||
b.ToTable("Chapters");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.Job", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("JobId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<bool>("Enabled")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<byte>("JobType")
|
|
||||||
.HasColumnType("smallint");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastExecution")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<string>("ParentJobId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<decimal>("RecurrenceMs")
|
|
||||||
.HasColumnType("numeric(20,0)");
|
|
||||||
|
|
||||||
b.Property<byte>("state")
|
|
||||||
.HasColumnType("smallint");
|
|
||||||
|
|
||||||
b.HasKey("JobId");
|
|
||||||
|
|
||||||
b.HasIndex("ParentJobId");
|
|
||||||
|
|
||||||
b.ToTable("Jobs");
|
|
||||||
|
|
||||||
b.HasDiscriminator<byte>("JobType");
|
|
||||||
|
|
||||||
b.UseTphMappingStrategy();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.LocalLibrary", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("LocalLibraryId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("BasePath")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.Property<string>("LibraryName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(512)
|
|
||||||
.HasColumnType("character varying(512)");
|
|
||||||
|
|
||||||
b.HasKey("LocalLibraryId");
|
|
||||||
|
|
||||||
b.ToTable("LocalLibraries");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Manga", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("MangaId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("CoverFileNameInCache")
|
|
||||||
.HasMaxLength(512)
|
|
||||||
.HasColumnType("character varying(512)");
|
|
||||||
|
|
||||||
b.Property<string>("CoverUrl")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(512)
|
|
||||||
.HasColumnType("character varying(512)");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("DirectoryName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(1024)
|
|
||||||
.HasColumnType("character varying(1024)");
|
|
||||||
|
|
||||||
b.Property<string>("IdOnConnectorSite")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.Property<float>("IgnoreChaptersBefore")
|
|
||||||
.HasColumnType("real");
|
|
||||||
|
|
||||||
b.Property<string>("LibraryId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("MangaConnectorName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(32)
|
|
||||||
.HasColumnType("character varying(32)");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(512)
|
|
||||||
.HasColumnType("character varying(512)");
|
|
||||||
|
|
||||||
b.Property<string>("OriginalLanguage")
|
|
||||||
.HasMaxLength(8)
|
|
||||||
.HasColumnType("character varying(8)");
|
|
||||||
|
|
||||||
b.Property<byte>("ReleaseStatus")
|
|
||||||
.HasColumnType("smallint");
|
|
||||||
|
|
||||||
b.Property<string>("WebsiteUrl")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(512)
|
|
||||||
.HasColumnType("character varying(512)");
|
|
||||||
|
|
||||||
b.Property<long>("Year")
|
|
||||||
.HasColumnType("bigint");
|
|
||||||
|
|
||||||
b.HasKey("MangaId");
|
|
||||||
|
|
||||||
b.HasIndex("LibraryId");
|
|
||||||
|
|
||||||
b.HasIndex("MangaConnectorName");
|
|
||||||
|
|
||||||
b.ToTable("Mangas");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.MangaConnectors.MangaConnector", b =>
|
|
||||||
{
|
{
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.HasMaxLength(32)
|
.HasMaxLength(32)
|
||||||
@@ -236,14 +50,212 @@ namespace API.Migrations.pgsql
|
|||||||
|
|
||||||
b.HasKey("Name");
|
b.HasKey("Name");
|
||||||
|
|
||||||
b.ToTable("MangaConnectors");
|
b.ToTable("MangaConnector");
|
||||||
|
|
||||||
b.HasDiscriminator<string>("Name").HasValue("MangaConnector");
|
b.HasDiscriminator<string>("Name").HasValue("MangaConnector");
|
||||||
|
|
||||||
b.UseTphMappingStrategy();
|
b.UseTphMappingStrategy();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.MangaTag", b =>
|
modelBuilder.Entity("API.Schema.MangaContext.Author", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("AuthorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.ToTable("Authors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("ChapterNumber")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(10)
|
||||||
|
.HasColumnType("character varying(10)");
|
||||||
|
|
||||||
|
b.Property<bool>("Downloaded")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("FileName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("ParentMangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<int?>("VolumeNumber")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("ParentMangaId");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.FileLibrary", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("BasePath")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("LibraryName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.ToTable("FileLibraries");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Manga", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("CoverFileNameInCache")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("CoverUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("DirectoryName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(1024)
|
||||||
|
.HasColumnType("character varying(1024)");
|
||||||
|
|
||||||
|
b.Property<float>("IgnoreChaptersBefore")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b.Property<string>("LibraryId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("OriginalLanguage")
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<byte>("ReleaseStatus")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.Property<long?>("Year")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("LibraryId");
|
||||||
|
|
||||||
|
b.ToTable("Mangas");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Chapter>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("IdOnConnectorSite")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaConnectorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("ObjId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<bool>("UseForDownload")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("WebsiteUrl")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("ObjId");
|
||||||
|
|
||||||
|
b.ToTable("MangaConnectorToChapter");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Manga>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("IdOnConnectorSite")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaConnectorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("ObjId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<bool>("UseForDownload")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("WebsiteUrl")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("ObjId");
|
||||||
|
|
||||||
|
b.ToTable("MangaConnectorToManga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaTag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Tag")
|
b.Property<string>("Tag")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
@@ -254,6 +266,44 @@ namespace API.Migrations.pgsql
|
|||||||
b.ToTable("Tags");
|
b.ToTable("Tags");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataEntry", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MetadataFetcherName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Identifier")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasKey("MetadataFetcherName", "Identifier");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.ToTable("MetadataEntries");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MetadataEntry")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(21)
|
||||||
|
.HasColumnType("character varying(21)");
|
||||||
|
|
||||||
|
b.HasKey("Name");
|
||||||
|
|
||||||
|
b.ToTable("MetadataFetcher");
|
||||||
|
|
||||||
|
b.HasDiscriminator<string>("MetadataEntry").HasValue("MetadataFetcher");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AuthorToManga", b =>
|
modelBuilder.Entity("AuthorToManga", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("AuthorIds")
|
b.Property<string>("AuthorIds")
|
||||||
@@ -269,21 +319,6 @@ namespace API.Migrations.pgsql
|
|||||||
b.ToTable("AuthorToManga");
|
b.ToTable("AuthorToManga");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("JobJob", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("DependsOnJobsJobId")
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("JobId")
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasKey("DependsOnJobsJobId", "JobId");
|
|
||||||
|
|
||||||
b.HasIndex("JobId");
|
|
||||||
|
|
||||||
b.ToTable("JobJob");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("MangaTagToManga", b =>
|
modelBuilder.Entity("MangaTagToManga", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("MangaTagIds")
|
b.Property<string>("MangaTagIds")
|
||||||
@@ -299,160 +334,37 @@ namespace API.Migrations.pgsql
|
|||||||
b.ToTable("MangaTagToManga");
|
b.ToTable("MangaTagToManga");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadAvailableChaptersJob", b =>
|
modelBuilder.Entity("API.MangaConnectors.ComickIo", b =>
|
||||||
{
|
{
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
b.HasBaseType("API.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
b.Property<string>("MangaId")
|
b.HasDiscriminator().HasValue("ComickIo");
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b.ToTable("Jobs", t =>
|
|
||||||
{
|
|
||||||
t.Property("MangaId")
|
|
||||||
.HasColumnName("DownloadAvailableChaptersJob_MangaId");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadMangaCoverJob", b =>
|
modelBuilder.Entity("API.MangaConnectors.Global", b =>
|
||||||
{
|
{
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
b.HasBaseType("API.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
b.Property<string>("MangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)4);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadSingleChapterJob", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
|
||||||
|
|
||||||
b.Property<string>("ChapterId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("ChapterId");
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)0);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.MoveFileOrFolderJob", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
|
||||||
|
|
||||||
b.Property<string>("FromLocation")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.Property<string>("ToLocation")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)3);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.MoveMangaLibraryJob", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
|
||||||
|
|
||||||
b.Property<string>("MangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("ToLibraryId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b.HasIndex("ToLibraryId");
|
|
||||||
|
|
||||||
b.ToTable("Jobs", t =>
|
|
||||||
{
|
|
||||||
t.Property("MangaId")
|
|
||||||
.HasColumnName("MoveMangaLibraryJob_MangaId");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)7);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.RetrieveChaptersJob", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
|
||||||
|
|
||||||
b.Property<string>("Language")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(8)
|
|
||||||
.HasColumnType("character varying(8)");
|
|
||||||
|
|
||||||
b.Property<string>("MangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b.ToTable("Jobs", t =>
|
|
||||||
{
|
|
||||||
t.Property("MangaId")
|
|
||||||
.HasColumnName("RetrieveChaptersJob_MangaId");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)5);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.UpdateFilesDownloadedJob", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
|
||||||
|
|
||||||
b.Property<string>("MangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b.ToTable("Jobs", t =>
|
|
||||||
{
|
|
||||||
t.Property("MangaId")
|
|
||||||
.HasColumnName("UpdateFilesDownloadedJob_MangaId");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)6);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.MangaConnectors.Global", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue("Global");
|
b.HasDiscriminator().HasValue("Global");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.MangaConnectors.MangaDex", b =>
|
modelBuilder.Entity("API.MangaConnectors.MangaDex", b =>
|
||||||
{
|
{
|
||||||
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
b.HasBaseType("API.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue("MangaDex");
|
b.HasDiscriminator().HasValue("MangaDex");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Chapter", b =>
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MyAnimeList", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Schema.Manga", "ParentManga")
|
b.HasBaseType("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("MyAnimeList");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", "ParentManga")
|
||||||
.WithMany("Chapters")
|
.WithMany("Chapters")
|
||||||
.HasForeignKey("ParentMangaId")
|
.HasForeignKey("ParentMangaId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -461,32 +373,46 @@ namespace API.Migrations.pgsql
|
|||||||
b.Navigation("ParentManga");
|
b.Navigation("ParentManga");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.Job", b =>
|
modelBuilder.Entity("API.Schema.MangaContext.Manga", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Schema.Jobs.Job", "ParentJob")
|
b.HasOne("API.Schema.MangaContext.FileLibrary", "Library")
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("ParentJobId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.Navigation("ParentJob");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Manga", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.LocalLibrary", "Library")
|
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("LibraryId")
|
.HasForeignKey("LibraryId")
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
b.HasOne("API.Schema.MangaConnectors.MangaConnector", "MangaConnector")
|
b.OwnsMany("API.Schema.MangaContext.AltTitle", "AltTitles", b1 =>
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaConnectorName")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.OwnsMany("API.Schema.Link", "Links", b1 =>
|
|
||||||
{
|
{
|
||||||
b1.Property<string>("LinkId")
|
b1.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b1.Property<string>("Language")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b1.Property<string>("MangaKey")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b1.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b1.HasKey("Key");
|
||||||
|
|
||||||
|
b1.HasIndex("MangaKey");
|
||||||
|
|
||||||
|
b1.ToTable("AltTitle");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("MangaKey");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.OwnsMany("API.Schema.MangaContext.Link", "Links", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<string>("Key")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
.HasColumnType("character varying(64)");
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
@@ -500,48 +426,18 @@ namespace API.Migrations.pgsql
|
|||||||
.HasMaxLength(2048)
|
.HasMaxLength(2048)
|
||||||
.HasColumnType("character varying(2048)");
|
.HasColumnType("character varying(2048)");
|
||||||
|
|
||||||
b1.Property<string>("MangaId")
|
b1.Property<string>("MangaKey")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("character varying(64)");
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
b1.HasKey("LinkId");
|
b1.HasKey("Key");
|
||||||
|
|
||||||
b1.HasIndex("MangaId");
|
b1.HasIndex("MangaKey");
|
||||||
|
|
||||||
b1.ToTable("Link");
|
b1.ToTable("Link");
|
||||||
|
|
||||||
b1.WithOwner()
|
b1.WithOwner()
|
||||||
.HasForeignKey("MangaId");
|
.HasForeignKey("MangaKey");
|
||||||
});
|
|
||||||
|
|
||||||
b.OwnsMany("API.Schema.MangaAltTitle", "AltTitles", b1 =>
|
|
||||||
{
|
|
||||||
b1.Property<string>("AltTitleId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b1.Property<string>("Language")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(8)
|
|
||||||
.HasColumnType("character varying(8)");
|
|
||||||
|
|
||||||
b1.Property<string>("MangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b1.Property<string>("Title")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b1.HasKey("AltTitleId");
|
|
||||||
|
|
||||||
b1.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b1.ToTable("MangaAltTitle");
|
|
||||||
|
|
||||||
b1.WithOwner()
|
|
||||||
.HasForeignKey("MangaId");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
b.Navigation("AltTitles");
|
b.Navigation("AltTitles");
|
||||||
@@ -549,132 +445,89 @@ namespace API.Migrations.pgsql
|
|||||||
b.Navigation("Library");
|
b.Navigation("Library");
|
||||||
|
|
||||||
b.Navigation("Links");
|
b.Navigation("Links");
|
||||||
|
});
|
||||||
|
|
||||||
b.Navigation("MangaConnector");
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Chapter>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Chapter", "Obj")
|
||||||
|
.WithMany("MangaConnectorIds")
|
||||||
|
.HasForeignKey("ObjId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Obj");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Manga>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", "Obj")
|
||||||
|
.WithMany("MangaConnectorIds")
|
||||||
|
.HasForeignKey("ObjId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Obj");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataEntry", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", "Manga")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher", "MetadataFetcher")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MetadataFetcherName")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Manga");
|
||||||
|
|
||||||
|
b.Navigation("MetadataFetcher");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AuthorToManga", b =>
|
modelBuilder.Entity("AuthorToManga", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Schema.Author", null)
|
b.HasOne("API.Schema.MangaContext.Author", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("AuthorIds")
|
.HasForeignKey("AuthorIds")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("API.Schema.Manga", null)
|
b.HasOne("API.Schema.MangaContext.Manga", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("MangaIds")
|
.HasForeignKey("MangaIds")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("JobJob", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Jobs.Job", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("DependsOnJobsJobId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("API.Schema.Jobs.Job", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("JobId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("MangaTagToManga", b =>
|
modelBuilder.Entity("MangaTagToManga", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Schema.Manga", null)
|
b.HasOne("API.Schema.MangaContext.Manga", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("MangaIds")
|
.HasForeignKey("MangaIds")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("API.Schema.MangaTag", null)
|
b.HasOne("API.Schema.MangaContext.MangaTag", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("MangaTagIds")
|
.HasForeignKey("MangaTagIds")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadAvailableChaptersJob", b =>
|
modelBuilder.Entity("API.Schema.MangaContext.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Schema.Manga", "Manga")
|
b.Navigation("MangaConnectorIds");
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Manga");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadMangaCoverJob", b =>
|
modelBuilder.Entity("API.Schema.MangaContext.Manga", b =>
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Manga", "Manga")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Manga");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadSingleChapterJob", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Chapter", "Chapter")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("ChapterId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Chapter");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.MoveMangaLibraryJob", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Manga", "Manga")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("API.Schema.LocalLibrary", "ToLibrary")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("ToLibraryId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Manga");
|
|
||||||
|
|
||||||
b.Navigation("ToLibrary");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.RetrieveChaptersJob", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Manga", "Manga")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Manga");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.UpdateFilesDownloadedJob", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Manga", "Manga")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Manga");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Manga", b =>
|
|
||||||
{
|
{
|
||||||
b.Navigation("Chapters");
|
b.Navigation("Chapters");
|
||||||
|
|
||||||
|
b.Navigation("MangaConnectorIds");
|
||||||
});
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
258
API/Migrations/Manga/20250901194144_KeyLengthChange.cs
Normal file
258
API/Migrations/Manga/20250901194144_KeyLengthChange.cs
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace API.Migrations.Manga
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class KeyLengthChange : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "MangaId",
|
||||||
|
table: "MetadataEntries",
|
||||||
|
type: "character varying(64)",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "MangaIds",
|
||||||
|
table: "MangaTagToManga",
|
||||||
|
type: "character varying(64)",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "Mangas",
|
||||||
|
type: "character varying(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "MangaConnectorToManga",
|
||||||
|
type: "character varying(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "MangaConnectorToChapter",
|
||||||
|
type: "character varying(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "MangaKey",
|
||||||
|
table: "Link",
|
||||||
|
type: "character varying(64)",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "Link",
|
||||||
|
type: "character varying(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "FileLibraries",
|
||||||
|
type: "character varying(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "Chapters",
|
||||||
|
type: "character varying(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "MangaIds",
|
||||||
|
table: "AuthorToManga",
|
||||||
|
type: "character varying(64)",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "AuthorIds",
|
||||||
|
table: "AuthorToManga",
|
||||||
|
type: "character varying(64)",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "Authors",
|
||||||
|
type: "character varying(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "MangaKey",
|
||||||
|
table: "AltTitle",
|
||||||
|
type: "character varying(64)",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "AltTitle",
|
||||||
|
type: "character varying(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "MangaId",
|
||||||
|
table: "MetadataEntries",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "MangaIds",
|
||||||
|
table: "MangaTagToManga",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "Mangas",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)",
|
||||||
|
oldMaxLength: 64);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "MangaConnectorToManga",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)",
|
||||||
|
oldMaxLength: 64);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "MangaConnectorToChapter",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)",
|
||||||
|
oldMaxLength: 64);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "MangaKey",
|
||||||
|
table: "Link",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "Link",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)",
|
||||||
|
oldMaxLength: 64);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "FileLibraries",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)",
|
||||||
|
oldMaxLength: 64);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "Chapters",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)",
|
||||||
|
oldMaxLength: 64);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "MangaIds",
|
||||||
|
table: "AuthorToManga",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "AuthorIds",
|
||||||
|
table: "AuthorToManga",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "Authors",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)",
|
||||||
|
oldMaxLength: 64);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "MangaKey",
|
||||||
|
table: "AltTitle",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "AltTitle",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)",
|
||||||
|
oldMaxLength: 64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using API.Schema.MangaContext;
|
||||||
using API.Schema.Contexts;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
@@ -8,206 +7,21 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace API.Migrations.pgsql
|
namespace API.Migrations.Manga
|
||||||
{
|
{
|
||||||
[DbContext(typeof(PgsqlContext))]
|
[DbContext(typeof(MangaContext))]
|
||||||
partial class PgsqlContextModelSnapshot : ModelSnapshot
|
partial class MangaContextModelSnapshot : ModelSnapshot
|
||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "9.0.3")
|
.HasAnnotation("ProductVersion", "9.0.8")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Author", b =>
|
modelBuilder.Entity("API.MangaConnectors.MangaConnector", b =>
|
||||||
{
|
|
||||||
b.Property<string>("AuthorId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("AuthorName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(128)
|
|
||||||
.HasColumnType("character varying(128)");
|
|
||||||
|
|
||||||
b.HasKey("AuthorId");
|
|
||||||
|
|
||||||
b.ToTable("Authors");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Chapter", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("ChapterId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("ChapterNumber")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(10)
|
|
||||||
.HasColumnType("character varying(10)");
|
|
||||||
|
|
||||||
b.Property<bool>("Downloaded")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<string>("FileName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.Property<string>("ParentMangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("Title")
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.Property<string>("Url")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(2048)
|
|
||||||
.HasColumnType("character varying(2048)");
|
|
||||||
|
|
||||||
b.Property<int?>("VolumeNumber")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("ChapterId");
|
|
||||||
|
|
||||||
b.HasIndex("ParentMangaId");
|
|
||||||
|
|
||||||
b.ToTable("Chapters");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.Job", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("JobId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<bool>("Enabled")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<byte>("JobType")
|
|
||||||
.HasColumnType("smallint");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastExecution")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<string>("ParentJobId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<decimal>("RecurrenceMs")
|
|
||||||
.HasColumnType("numeric(20,0)");
|
|
||||||
|
|
||||||
b.Property<byte>("state")
|
|
||||||
.HasColumnType("smallint");
|
|
||||||
|
|
||||||
b.HasKey("JobId");
|
|
||||||
|
|
||||||
b.HasIndex("ParentJobId");
|
|
||||||
|
|
||||||
b.ToTable("Jobs");
|
|
||||||
|
|
||||||
b.HasDiscriminator<byte>("JobType");
|
|
||||||
|
|
||||||
b.UseTphMappingStrategy();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.LocalLibrary", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("LocalLibraryId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("BasePath")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.Property<string>("LibraryName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(512)
|
|
||||||
.HasColumnType("character varying(512)");
|
|
||||||
|
|
||||||
b.HasKey("LocalLibraryId");
|
|
||||||
|
|
||||||
b.ToTable("LocalLibraries");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Manga", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("MangaId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("CoverFileNameInCache")
|
|
||||||
.HasMaxLength(512)
|
|
||||||
.HasColumnType("character varying(512)");
|
|
||||||
|
|
||||||
b.Property<string>("CoverUrl")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(512)
|
|
||||||
.HasColumnType("character varying(512)");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("DirectoryName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(1024)
|
|
||||||
.HasColumnType("character varying(1024)");
|
|
||||||
|
|
||||||
b.Property<string>("IdOnConnectorSite")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.Property<float>("IgnoreChaptersBefore")
|
|
||||||
.HasColumnType("real");
|
|
||||||
|
|
||||||
b.Property<string>("LibraryId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("MangaConnectorName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(32)
|
|
||||||
.HasColumnType("character varying(32)");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(512)
|
|
||||||
.HasColumnType("character varying(512)");
|
|
||||||
|
|
||||||
b.Property<string>("OriginalLanguage")
|
|
||||||
.HasMaxLength(8)
|
|
||||||
.HasColumnType("character varying(8)");
|
|
||||||
|
|
||||||
b.Property<byte>("ReleaseStatus")
|
|
||||||
.HasColumnType("smallint");
|
|
||||||
|
|
||||||
b.Property<string>("WebsiteUrl")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(512)
|
|
||||||
.HasColumnType("character varying(512)");
|
|
||||||
|
|
||||||
b.Property<long>("Year")
|
|
||||||
.HasColumnType("bigint");
|
|
||||||
|
|
||||||
b.HasKey("MangaId");
|
|
||||||
|
|
||||||
b.HasIndex("LibraryId");
|
|
||||||
|
|
||||||
b.HasIndex("MangaConnectorName");
|
|
||||||
|
|
||||||
b.ToTable("Mangas");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.MangaConnectors.MangaConnector", b =>
|
|
||||||
{
|
{
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.HasMaxLength(32)
|
.HasMaxLength(32)
|
||||||
@@ -233,14 +47,212 @@ namespace API.Migrations.pgsql
|
|||||||
|
|
||||||
b.HasKey("Name");
|
b.HasKey("Name");
|
||||||
|
|
||||||
b.ToTable("MangaConnectors");
|
b.ToTable("MangaConnector");
|
||||||
|
|
||||||
b.HasDiscriminator<string>("Name").HasValue("MangaConnector");
|
b.HasDiscriminator<string>("Name").HasValue("MangaConnector");
|
||||||
|
|
||||||
b.UseTphMappingStrategy();
|
b.UseTphMappingStrategy();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.MangaTag", b =>
|
modelBuilder.Entity("API.Schema.MangaContext.Author", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("AuthorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.ToTable("Authors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("ChapterNumber")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(10)
|
||||||
|
.HasColumnType("character varying(10)");
|
||||||
|
|
||||||
|
b.Property<bool>("Downloaded")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("FileName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("ParentMangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<int?>("VolumeNumber")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("ParentMangaId");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.FileLibrary", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("BasePath")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("LibraryName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.ToTable("FileLibraries");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Manga", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("CoverFileNameInCache")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("CoverUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("DirectoryName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(1024)
|
||||||
|
.HasColumnType("character varying(1024)");
|
||||||
|
|
||||||
|
b.Property<float>("IgnoreChaptersBefore")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b.Property<string>("LibraryId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("OriginalLanguage")
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<byte>("ReleaseStatus")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.Property<long?>("Year")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("LibraryId");
|
||||||
|
|
||||||
|
b.ToTable("Mangas");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Chapter>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("IdOnConnectorSite")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaConnectorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("ObjId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<bool>("UseForDownload")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("WebsiteUrl")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("ObjId");
|
||||||
|
|
||||||
|
b.ToTable("MangaConnectorToChapter");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Manga>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("IdOnConnectorSite")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaConnectorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("ObjId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<bool>("UseForDownload")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("WebsiteUrl")
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.HasIndex("ObjId");
|
||||||
|
|
||||||
|
b.ToTable("MangaConnectorToManga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaTag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Tag")
|
b.Property<string>("Tag")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
@@ -251,6 +263,44 @@ namespace API.Migrations.pgsql
|
|||||||
b.ToTable("Tags");
|
b.ToTable("Tags");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataEntry", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MetadataFetcherName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Identifier")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasKey("MetadataFetcherName", "Identifier");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.ToTable("MetadataEntries");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MetadataEntry")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(21)
|
||||||
|
.HasColumnType("character varying(21)");
|
||||||
|
|
||||||
|
b.HasKey("Name");
|
||||||
|
|
||||||
|
b.ToTable("MetadataFetcher");
|
||||||
|
|
||||||
|
b.HasDiscriminator<string>("MetadataEntry").HasValue("MetadataFetcher");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AuthorToManga", b =>
|
modelBuilder.Entity("AuthorToManga", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("AuthorIds")
|
b.Property<string>("AuthorIds")
|
||||||
@@ -266,21 +316,6 @@ namespace API.Migrations.pgsql
|
|||||||
b.ToTable("AuthorToManga");
|
b.ToTable("AuthorToManga");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("JobJob", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("DependsOnJobsJobId")
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("JobId")
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasKey("DependsOnJobsJobId", "JobId");
|
|
||||||
|
|
||||||
b.HasIndex("JobId");
|
|
||||||
|
|
||||||
b.ToTable("JobJob");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("MangaTagToManga", b =>
|
modelBuilder.Entity("MangaTagToManga", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("MangaTagIds")
|
b.Property<string>("MangaTagIds")
|
||||||
@@ -296,160 +331,37 @@ namespace API.Migrations.pgsql
|
|||||||
b.ToTable("MangaTagToManga");
|
b.ToTable("MangaTagToManga");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadAvailableChaptersJob", b =>
|
modelBuilder.Entity("API.MangaConnectors.ComickIo", b =>
|
||||||
{
|
{
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
b.HasBaseType("API.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
b.Property<string>("MangaId")
|
b.HasDiscriminator().HasValue("ComickIo");
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b.ToTable("Jobs", t =>
|
|
||||||
{
|
|
||||||
t.Property("MangaId")
|
|
||||||
.HasColumnName("DownloadAvailableChaptersJob_MangaId");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadMangaCoverJob", b =>
|
modelBuilder.Entity("API.MangaConnectors.Global", b =>
|
||||||
{
|
{
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
b.HasBaseType("API.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
b.Property<string>("MangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)4);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadSingleChapterJob", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
|
||||||
|
|
||||||
b.Property<string>("ChapterId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("ChapterId");
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)0);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.MoveFileOrFolderJob", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
|
||||||
|
|
||||||
b.Property<string>("FromLocation")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.Property<string>("ToLocation")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)3);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.MoveMangaLibraryJob", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
|
||||||
|
|
||||||
b.Property<string>("MangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.Property<string>("ToLibraryId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b.HasIndex("ToLibraryId");
|
|
||||||
|
|
||||||
b.ToTable("Jobs", t =>
|
|
||||||
{
|
|
||||||
t.Property("MangaId")
|
|
||||||
.HasColumnName("MoveMangaLibraryJob_MangaId");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)7);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.RetrieveChaptersJob", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
|
||||||
|
|
||||||
b.Property<string>("Language")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(8)
|
|
||||||
.HasColumnType("character varying(8)");
|
|
||||||
|
|
||||||
b.Property<string>("MangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b.ToTable("Jobs", t =>
|
|
||||||
{
|
|
||||||
t.Property("MangaId")
|
|
||||||
.HasColumnName("RetrieveChaptersJob_MangaId");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)5);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.UpdateFilesDownloadedJob", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.Jobs.Job");
|
|
||||||
|
|
||||||
b.Property<string>("MangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b.ToTable("Jobs", t =>
|
|
||||||
{
|
|
||||||
t.Property("MangaId")
|
|
||||||
.HasColumnName("UpdateFilesDownloadedJob_MangaId");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue((byte)6);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.MangaConnectors.Global", b =>
|
|
||||||
{
|
|
||||||
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue("Global");
|
b.HasDiscriminator().HasValue("Global");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.MangaConnectors.MangaDex", b =>
|
modelBuilder.Entity("API.MangaConnectors.MangaDex", b =>
|
||||||
{
|
{
|
||||||
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
b.HasBaseType("API.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
b.HasDiscriminator().HasValue("MangaDex");
|
b.HasDiscriminator().HasValue("MangaDex");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Chapter", b =>
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MyAnimeList", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Schema.Manga", "ParentManga")
|
b.HasBaseType("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("MyAnimeList");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", "ParentManga")
|
||||||
.WithMany("Chapters")
|
.WithMany("Chapters")
|
||||||
.HasForeignKey("ParentMangaId")
|
.HasForeignKey("ParentMangaId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -458,32 +370,46 @@ namespace API.Migrations.pgsql
|
|||||||
b.Navigation("ParentManga");
|
b.Navigation("ParentManga");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.Job", b =>
|
modelBuilder.Entity("API.Schema.MangaContext.Manga", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Schema.Jobs.Job", "ParentJob")
|
b.HasOne("API.Schema.MangaContext.FileLibrary", "Library")
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("ParentJobId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.Navigation("ParentJob");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Manga", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.LocalLibrary", "Library")
|
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("LibraryId")
|
.HasForeignKey("LibraryId")
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
b.HasOne("API.Schema.MangaConnectors.MangaConnector", "MangaConnector")
|
b.OwnsMany("API.Schema.MangaContext.AltTitle", "AltTitles", b1 =>
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaConnectorName")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.OwnsMany("API.Schema.Link", "Links", b1 =>
|
|
||||||
{
|
{
|
||||||
b1.Property<string>("LinkId")
|
b1.Property<string>("Key")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b1.Property<string>("Language")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b1.Property<string>("MangaKey")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b1.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b1.HasKey("Key");
|
||||||
|
|
||||||
|
b1.HasIndex("MangaKey");
|
||||||
|
|
||||||
|
b1.ToTable("AltTitle");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("MangaKey");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.OwnsMany("API.Schema.MangaContext.Link", "Links", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<string>("Key")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
.HasColumnType("character varying(64)");
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
@@ -497,48 +423,18 @@ namespace API.Migrations.pgsql
|
|||||||
.HasMaxLength(2048)
|
.HasMaxLength(2048)
|
||||||
.HasColumnType("character varying(2048)");
|
.HasColumnType("character varying(2048)");
|
||||||
|
|
||||||
b1.Property<string>("MangaId")
|
b1.Property<string>("MangaKey")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("character varying(64)");
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
b1.HasKey("LinkId");
|
b1.HasKey("Key");
|
||||||
|
|
||||||
b1.HasIndex("MangaId");
|
b1.HasIndex("MangaKey");
|
||||||
|
|
||||||
b1.ToTable("Link");
|
b1.ToTable("Link");
|
||||||
|
|
||||||
b1.WithOwner()
|
b1.WithOwner()
|
||||||
.HasForeignKey("MangaId");
|
.HasForeignKey("MangaKey");
|
||||||
});
|
|
||||||
|
|
||||||
b.OwnsMany("API.Schema.MangaAltTitle", "AltTitles", b1 =>
|
|
||||||
{
|
|
||||||
b1.Property<string>("AltTitleId")
|
|
||||||
.HasMaxLength(64)
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b1.Property<string>("Language")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(8)
|
|
||||||
.HasColumnType("character varying(8)");
|
|
||||||
|
|
||||||
b1.Property<string>("MangaId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("character varying(64)");
|
|
||||||
|
|
||||||
b1.Property<string>("Title")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(256)
|
|
||||||
.HasColumnType("character varying(256)");
|
|
||||||
|
|
||||||
b1.HasKey("AltTitleId");
|
|
||||||
|
|
||||||
b1.HasIndex("MangaId");
|
|
||||||
|
|
||||||
b1.ToTable("MangaAltTitle");
|
|
||||||
|
|
||||||
b1.WithOwner()
|
|
||||||
.HasForeignKey("MangaId");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
b.Navigation("AltTitles");
|
b.Navigation("AltTitles");
|
||||||
@@ -546,132 +442,89 @@ namespace API.Migrations.pgsql
|
|||||||
b.Navigation("Library");
|
b.Navigation("Library");
|
||||||
|
|
||||||
b.Navigation("Links");
|
b.Navigation("Links");
|
||||||
|
});
|
||||||
|
|
||||||
b.Navigation("MangaConnector");
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Chapter>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Chapter", "Obj")
|
||||||
|
.WithMany("MangaConnectorIds")
|
||||||
|
.HasForeignKey("ObjId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Obj");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId<API.Schema.MangaContext.Manga>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", "Obj")
|
||||||
|
.WithMany("MangaConnectorIds")
|
||||||
|
.HasForeignKey("ObjId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Obj");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataEntry", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaContext.Manga", "Manga")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher", "MetadataFetcher")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MetadataFetcherName")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Manga");
|
||||||
|
|
||||||
|
b.Navigation("MetadataFetcher");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AuthorToManga", b =>
|
modelBuilder.Entity("AuthorToManga", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Schema.Author", null)
|
b.HasOne("API.Schema.MangaContext.Author", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("AuthorIds")
|
.HasForeignKey("AuthorIds")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("API.Schema.Manga", null)
|
b.HasOne("API.Schema.MangaContext.Manga", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("MangaIds")
|
.HasForeignKey("MangaIds")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("JobJob", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Jobs.Job", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("DependsOnJobsJobId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("API.Schema.Jobs.Job", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("JobId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("MangaTagToManga", b =>
|
modelBuilder.Entity("MangaTagToManga", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Schema.Manga", null)
|
b.HasOne("API.Schema.MangaContext.Manga", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("MangaIds")
|
.HasForeignKey("MangaIds")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("API.Schema.MangaTag", null)
|
b.HasOne("API.Schema.MangaContext.MangaTag", null)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("MangaTagIds")
|
.HasForeignKey("MangaTagIds")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadAvailableChaptersJob", b =>
|
modelBuilder.Entity("API.Schema.MangaContext.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("API.Schema.Manga", "Manga")
|
b.Navigation("MangaConnectorIds");
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Manga");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadMangaCoverJob", b =>
|
modelBuilder.Entity("API.Schema.MangaContext.Manga", b =>
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Manga", "Manga")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Manga");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.DownloadSingleChapterJob", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Chapter", "Chapter")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("ChapterId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Chapter");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.MoveMangaLibraryJob", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Manga", "Manga")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("API.Schema.LocalLibrary", "ToLibrary")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("ToLibraryId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Manga");
|
|
||||||
|
|
||||||
b.Navigation("ToLibrary");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.RetrieveChaptersJob", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Manga", "Manga")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Manga");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Jobs.UpdateFilesDownloadedJob", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("API.Schema.Manga", "Manga")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("MangaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Manga");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Manga", b =>
|
|
||||||
{
|
{
|
||||||
b.Navigation("Chapters");
|
b.Navigation("Chapters");
|
||||||
|
|
||||||
|
b.Navigation("MangaConnectorIds");
|
||||||
});
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
91
API/Migrations/Notifications/20250703191820_Initial.Designer.cs
generated
Normal file
91
API/Migrations/Notifications/20250703191820_Initial.Designer.cs
generated
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using API.Schema.NotificationsContext;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace API.Migrations.Notifications
|
||||||
|
{
|
||||||
|
[DbContext(typeof(NotificationsContext))]
|
||||||
|
[Migration("20250703191820_Initial")]
|
||||||
|
partial class Initial
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.5")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore");
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.NotificationsContext.Notification", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Date")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<bool>("IsSent")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("Message")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("character varying(512)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b.Property<byte>("Urgency")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.HasKey("Key");
|
||||||
|
|
||||||
|
b.ToTable("Notifications");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.NotificationsContext.NotificationConnectors.NotificationConnector", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Body")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(4096)
|
||||||
|
.HasColumnType("character varying(4096)");
|
||||||
|
|
||||||
|
b.Property<Dictionary<string, string>>("Headers")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("hstore");
|
||||||
|
|
||||||
|
b.Property<string>("HttpMethod")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(2048)
|
||||||
|
.HasColumnType("character varying(2048)");
|
||||||
|
|
||||||
|
b.HasKey("Name");
|
||||||
|
|
||||||
|
b.ToTable("NotificationConnectors");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace API.Migrations.notifications
|
namespace API.Migrations.Notifications
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class Initial : Migration
|
public partial class Initial : Migration
|
||||||
@@ -34,15 +34,16 @@ namespace API.Migrations.notifications
|
|||||||
name: "Notifications",
|
name: "Notifications",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
NotificationId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
Key = table.Column<string>(type: "text", nullable: false),
|
||||||
Urgency = table.Column<byte>(type: "smallint", nullable: false),
|
Urgency = table.Column<byte>(type: "smallint", nullable: false),
|
||||||
Title = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
Title = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
||||||
Message = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
|
Message = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
|
||||||
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
IsSent = table.Column<bool>(type: "boolean", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_Notifications", x => x.NotificationId);
|
table.PrimaryKey("PK_Notifications", x => x.Key);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using API.Schema.Contexts;
|
using API.Schema.NotificationsContext;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
@@ -10,32 +10,35 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace API.Migrations.notifications
|
namespace API.Migrations.Notifications
|
||||||
{
|
{
|
||||||
[DbContext(typeof(NotificationsContext))]
|
[DbContext(typeof(NotificationsContext))]
|
||||||
[Migration("20250515120746_Initial")]
|
[Migration("20250901194327_KeyLengthChange")]
|
||||||
partial class Initial
|
partial class KeyLengthChange
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "9.0.3")
|
.HasAnnotation("ProductVersion", "9.0.8")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore");
|
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore");
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Notification", b =>
|
modelBuilder.Entity("API.Schema.NotificationsContext.Notification", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NotificationId")
|
b.Property<string>("Key")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
.HasColumnType("character varying(64)");
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
b.Property<DateTime>("Date")
|
b.Property<DateTime>("Date")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<bool>("IsSent")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
b.Property<string>("Message")
|
b.Property<string>("Message")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(512)
|
.HasMaxLength(512)
|
||||||
@@ -49,12 +52,12 @@ namespace API.Migrations.notifications
|
|||||||
b.Property<byte>("Urgency")
|
b.Property<byte>("Urgency")
|
||||||
.HasColumnType("smallint");
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
b.HasKey("NotificationId");
|
b.HasKey("Key");
|
||||||
|
|
||||||
b.ToTable("Notifications");
|
b.ToTable("Notifications");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.NotificationConnectors.NotificationConnector", b =>
|
modelBuilder.Entity("API.Schema.NotificationsContext.NotificationConnectors.NotificationConnector", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace API.Migrations.Notifications
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class KeyLengthChange : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "Notifications",
|
||||||
|
type: "character varying(64)",
|
||||||
|
maxLength: 64,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "text");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Key",
|
||||||
|
table: "Notifications",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(64)",
|
||||||
|
oldMaxLength: 64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using API.Schema.Contexts;
|
using API.Schema.NotificationsContext;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
@@ -9,7 +9,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace API.Migrations.notifications
|
namespace API.Migrations.Notifications
|
||||||
{
|
{
|
||||||
[DbContext(typeof(NotificationsContext))]
|
[DbContext(typeof(NotificationsContext))]
|
||||||
partial class NotificationsContextModelSnapshot : ModelSnapshot
|
partial class NotificationsContextModelSnapshot : ModelSnapshot
|
||||||
@@ -18,21 +18,24 @@ namespace API.Migrations.notifications
|
|||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "9.0.3")
|
.HasAnnotation("ProductVersion", "9.0.8")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore");
|
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore");
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.Notification", b =>
|
modelBuilder.Entity("API.Schema.NotificationsContext.Notification", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NotificationId")
|
b.Property<string>("Key")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
.HasColumnType("character varying(64)");
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
b.Property<DateTime>("Date")
|
b.Property<DateTime>("Date")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<bool>("IsSent")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
b.Property<string>("Message")
|
b.Property<string>("Message")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(512)
|
.HasMaxLength(512)
|
||||||
@@ -46,12 +49,12 @@ namespace API.Migrations.notifications
|
|||||||
b.Property<byte>("Urgency")
|
b.Property<byte>("Urgency")
|
||||||
.HasColumnType("smallint");
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
b.HasKey("NotificationId");
|
b.HasKey("Key");
|
||||||
|
|
||||||
b.ToTable("Notifications");
|
b.ToTable("Notifications");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("API.Schema.NotificationConnectors.NotificationConnector", b =>
|
modelBuilder.Entity("API.Schema.NotificationsContext.NotificationConnectors.NotificationConnector", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
@@ -34,7 +34,7 @@ public class NamedSwaggerGenOptions : IConfigureNamedOptions<SwaggerGenOptions>
|
|||||||
{
|
{
|
||||||
var info = new OpenApiInfo()
|
var info = new OpenApiInfo()
|
||||||
{
|
{
|
||||||
Title = "Test API " + description.GroupName,
|
Title = "Tranga " + description.GroupName,
|
||||||
Version = description.ApiVersion.ToString()
|
Version = description.ApiVersion.ToString()
|
||||||
};
|
};
|
||||||
if (description.IsDeprecated)
|
if (description.IsDeprecated)
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using API;
|
using API;
|
||||||
using API.Schema;
|
using API.Schema.LibraryContext;
|
||||||
using API.Schema.Contexts;
|
using API.Schema.MangaContext;
|
||||||
using API.Schema.Jobs;
|
using API.Schema.NotificationsContext;
|
||||||
using API.Schema.MangaConnectors;
|
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using Asp.Versioning.Builder;
|
using Asp.Versioning.Builder;
|
||||||
using Asp.Versioning.Conventions;
|
using Asp.Versioning.Conventions;
|
||||||
@@ -55,17 +54,17 @@ builder.Services.AddSwaggerGen(opt =>
|
|||||||
});
|
});
|
||||||
builder.Services.ConfigureOptions<NamedSwaggerGenOptions>();
|
builder.Services.ConfigureOptions<NamedSwaggerGenOptions>();
|
||||||
|
|
||||||
string ConnectionString = $"Host={Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "localhost:5432"}; " +
|
string connectionString = $"Host={Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "localhost:5432"}; " +
|
||||||
$"Database={Environment.GetEnvironmentVariable("POSTGRES_DB") ?? "postgres"}; " +
|
$"Database={Environment.GetEnvironmentVariable("POSTGRES_DB") ?? "postgres"}; " +
|
||||||
$"Username={Environment.GetEnvironmentVariable("POSTGRES_USER") ?? "postgres"}; " +
|
$"Username={Environment.GetEnvironmentVariable("POSTGRES_USER") ?? "postgres"}; " +
|
||||||
$"Password={Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "postgres"}";
|
$"Password={Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "postgres"}";
|
||||||
|
|
||||||
builder.Services.AddDbContext<PgsqlContext>(options =>
|
builder.Services.AddDbContext<MangaContext>(options =>
|
||||||
options.UseNpgsql(ConnectionString));
|
options.UseNpgsql(connectionString));
|
||||||
builder.Services.AddDbContext<NotificationsContext>(options =>
|
builder.Services.AddDbContext<NotificationsContext>(options =>
|
||||||
options.UseNpgsql(ConnectionString));
|
options.UseNpgsql(connectionString));
|
||||||
builder.Services.AddDbContext<LibraryContext>(options =>
|
builder.Services.AddDbContext<LibraryContext>(options =>
|
||||||
options.UseNpgsql(ConnectionString));
|
options.UseNpgsql(connectionString));
|
||||||
|
|
||||||
builder.Services.AddControllers(options =>
|
builder.Services.AddControllers(options =>
|
||||||
{
|
{
|
||||||
@@ -76,7 +75,7 @@ builder.Services.AddControllers().AddNewtonsoftJson(opts =>
|
|||||||
opts.SerializerSettings.Converters.Add(new StringEnumConverter());
|
opts.SerializerSettings.Converters.Add(new StringEnumConverter());
|
||||||
opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||||
});
|
});
|
||||||
builder.Services.AddScoped<ILog>(opts => LogManager.GetLogger("API"));
|
builder.Services.AddScoped<ILog>(_ => LogManager.GetLogger("API"));
|
||||||
|
|
||||||
builder.WebHost.UseUrls("http://*:6531");
|
builder.WebHost.UseUrls("http://*:6531");
|
||||||
|
|
||||||
@@ -97,8 +96,7 @@ app.MapControllers()
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(options =>
|
app.UseSwaggerUI(options =>
|
||||||
{
|
{
|
||||||
options.SwaggerEndpoint(
|
options.SwaggerEndpoint($"/swagger/v2/swagger.json", "v2");
|
||||||
$"/swagger/v2/swagger.json", "v2");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
@@ -107,34 +105,13 @@ app.UseMiddleware<RequestTimeMiddleware>();
|
|||||||
|
|
||||||
using (IServiceScope scope = app.Services.CreateScope())
|
using (IServiceScope scope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
PgsqlContext context = scope.ServiceProvider.GetRequiredService<PgsqlContext>();
|
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||||
context.Database.Migrate();
|
context.Database.Migrate();
|
||||||
|
|
||||||
MangaConnector[] connectors =
|
if (!context.FileLibraries.Any())
|
||||||
[
|
context.FileLibraries.Add(new FileLibrary(Tranga.Settings.DownloadLocation, "Default FileLibrary"));
|
||||||
new MangaDex(),
|
|
||||||
new Global(scope.ServiceProvider.GetService<PgsqlContext>()!)
|
|
||||||
];
|
|
||||||
MangaConnector[] newConnectors = connectors.Where(c => !context.MangaConnectors.Contains(c)).ToArray();
|
|
||||||
context.MangaConnectors.AddRange(newConnectors);
|
|
||||||
if (!context.LocalLibraries.Any())
|
|
||||||
context.LocalLibraries.Add(new LocalLibrary(TrangaSettings.downloadLocation, "Default Library"));
|
|
||||||
|
|
||||||
context.Jobs.AddRange(context.Jobs.Where(j => j.JobType == JobType.DownloadAvailableChaptersJob)
|
await context.Sync(CancellationToken.None);
|
||||||
.AsEnumerable()
|
|
||||||
.Select(dacj =>
|
|
||||||
{
|
|
||||||
DownloadAvailableChaptersJob? j = dacj as DownloadAvailableChaptersJob;
|
|
||||||
return new UpdateFilesDownloadedJob(j!.Manga, 0);
|
|
||||||
}));
|
|
||||||
context.Jobs.RemoveRange(context.Jobs.Where(j => j.state == JobState.Completed && j.RecurrenceMs < 1));
|
|
||||||
foreach (Job job in context.Jobs.Where(j => j.state == JobState.Running))
|
|
||||||
{
|
|
||||||
job.state = JobState.FirstExecution;
|
|
||||||
job.LastExecution = DateTime.UnixEpoch;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using (IServiceScope scope = app.Services.CreateScope())
|
using (IServiceScope scope = app.Services.CreateScope())
|
||||||
@@ -142,17 +119,24 @@ using (IServiceScope scope = app.Services.CreateScope())
|
|||||||
NotificationsContext context = scope.ServiceProvider.GetRequiredService<NotificationsContext>();
|
NotificationsContext context = scope.ServiceProvider.GetRequiredService<NotificationsContext>();
|
||||||
context.Database.Migrate();
|
context.Database.Migrate();
|
||||||
|
|
||||||
|
context.Notifications.RemoveRange(context.Notifications);
|
||||||
string[] emojis = { "(•‿•)", "(づ \u25d5‿\u25d5 )づ", "( \u02d8\u25bd\u02d8)っ\u2668", "=\uff3e\u25cf \u22cf \u25cf\uff3e=", "(ΦωΦ)", "(\u272a\u3268\u272a)", "( ノ・o・ )ノ", "(〜^\u2207^ )〜", "~(\u2267ω\u2266)~","૮ \u00b4• ﻌ \u00b4• ა", "(\u02c3ᆺ\u02c2)", "(=\ud83d\udf66 \u0f1d \ud83d\udf66=)"};
|
string[] emojis = { "(•‿•)", "(づ \u25d5‿\u25d5 )づ", "( \u02d8\u25bd\u02d8)っ\u2668", "=\uff3e\u25cf \u22cf \u25cf\uff3e=", "(ΦωΦ)", "(\u272a\u3268\u272a)", "( ノ・o・ )ノ", "(〜^\u2207^ )〜", "~(\u2267ω\u2266)~","૮ \u00b4• ﻌ \u00b4• ა", "(\u02c3ᆺ\u02c2)", "(=\ud83d\udf66 \u0f1d \ud83d\udf66=)"};
|
||||||
context.Notifications.Add(new Notification("Tranga Started", emojis[Random.Shared.Next(0, emojis.Length - 1)], NotificationUrgency.High));
|
context.Notifications.Add(new Notification("Tranga Started", emojis[Random.Shared.Next(0, emojis.Length - 1)], NotificationUrgency.High));
|
||||||
|
|
||||||
context.SaveChanges();
|
await context.Sync(CancellationToken.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using (IServiceScope scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
LibraryContext context = scope.ServiceProvider.GetRequiredService<LibraryContext>();
|
||||||
|
context.Database.Migrate();
|
||||||
|
|
||||||
TrangaSettings.Load();
|
await context.Sync(CancellationToken.None);
|
||||||
Tranga.StartLogger();
|
}
|
||||||
Tranga.JobStarterThread.Start(app.Services);
|
|
||||||
Tranga.NotificationSenderThread.Start(app.Services);
|
Tranga.SetServiceProvider(app.Services);
|
||||||
|
Tranga.StartLogger(new FileInfo("Log4Net.config.xml"));
|
||||||
|
Tranga.AddDefaultWorkers();
|
||||||
|
|
||||||
app.UseCors("AllowAll");
|
app.UseCors("AllowAll");
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Schema;
|
|
||||||
|
|
||||||
[PrimaryKey("AuthorId")]
|
|
||||||
public class Author(string authorName)
|
|
||||||
{
|
|
||||||
[StringLength(64)]
|
|
||||||
[Required]
|
|
||||||
public string AuthorId { get; init; } = TokenGen.CreateToken(typeof(Author), authorName);
|
|
||||||
[StringLength(128)]
|
|
||||||
[Required]
|
|
||||||
public string AuthorName { get; init; } = authorName;
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"{AuthorId} {AuthorName}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,189 +0,0 @@
|
|||||||
using API.Schema.Jobs;
|
|
||||||
using API.Schema.LibraryConnectors;
|
|
||||||
using API.Schema.MangaConnectors;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Schema.Contexts;
|
|
||||||
|
|
||||||
public class PgsqlContext(DbContextOptions<PgsqlContext> options) : DbContext(options)
|
|
||||||
{
|
|
||||||
public DbSet<Job> Jobs { get; set; }
|
|
||||||
public DbSet<MangaConnector> MangaConnectors { get; set; }
|
|
||||||
public DbSet<Manga> Mangas { get; set; }
|
|
||||||
public DbSet<LocalLibrary> LocalLibraries { get; set; }
|
|
||||||
public DbSet<Chapter> Chapters { get; set; }
|
|
||||||
public DbSet<Author> Authors { get; set; }
|
|
||||||
public DbSet<MangaTag> Tags { get; set; }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
//Job Types
|
|
||||||
modelBuilder.Entity<Job>()
|
|
||||||
.HasDiscriminator(j => j.JobType)
|
|
||||||
.HasValue<MoveFileOrFolderJob>(JobType.MoveFileOrFolderJob)
|
|
||||||
.HasValue<MoveMangaLibraryJob>(JobType.MoveMangaLibraryJob)
|
|
||||||
.HasValue<DownloadAvailableChaptersJob>(JobType.DownloadAvailableChaptersJob)
|
|
||||||
.HasValue<DownloadSingleChapterJob>(JobType.DownloadSingleChapterJob)
|
|
||||||
.HasValue<DownloadMangaCoverJob>(JobType.DownloadMangaCoverJob)
|
|
||||||
.HasValue<RetrieveChaptersJob>(JobType.RetrieveChaptersJob)
|
|
||||||
.HasValue<UpdateFilesDownloadedJob>(JobType.UpdateFilesDownloadedJob);
|
|
||||||
|
|
||||||
//Job specification
|
|
||||||
modelBuilder.Entity<DownloadAvailableChaptersJob>()
|
|
||||||
.HasOne<Manga>(j => j.Manga)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey(j => j.MangaId)
|
|
||||||
.IsRequired()
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
modelBuilder.Entity<DownloadAvailableChaptersJob>()
|
|
||||||
.Navigation(j => j.Manga)
|
|
||||||
.AutoInclude();
|
|
||||||
modelBuilder.Entity<DownloadMangaCoverJob>()
|
|
||||||
.HasOne<Manga>(j => j.Manga)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey(j => j.MangaId)
|
|
||||||
.IsRequired()
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
modelBuilder.Entity<DownloadMangaCoverJob>()
|
|
||||||
.Navigation(j => j.Manga)
|
|
||||||
.AutoInclude();
|
|
||||||
modelBuilder.Entity<DownloadSingleChapterJob>()
|
|
||||||
.HasOne<Chapter>(j => j.Chapter)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey(j => j.ChapterId)
|
|
||||||
.IsRequired()
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
modelBuilder.Entity<DownloadSingleChapterJob>()
|
|
||||||
.Navigation(j => j.Chapter)
|
|
||||||
.AutoInclude();
|
|
||||||
modelBuilder.Entity<MoveMangaLibraryJob>()
|
|
||||||
.HasOne<Manga>(j => j.Manga)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey(j => j.MangaId)
|
|
||||||
.IsRequired()
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
modelBuilder.Entity<MoveMangaLibraryJob>()
|
|
||||||
.Navigation(j => j.Manga)
|
|
||||||
.AutoInclude();
|
|
||||||
modelBuilder.Entity<MoveMangaLibraryJob>()
|
|
||||||
.HasOne<LocalLibrary>(j => j.ToLibrary)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey(j => j.ToLibraryId)
|
|
||||||
.IsRequired()
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
modelBuilder.Entity<MoveMangaLibraryJob>()
|
|
||||||
.Navigation(j => j.ToLibrary)
|
|
||||||
.AutoInclude();
|
|
||||||
modelBuilder.Entity<RetrieveChaptersJob>()
|
|
||||||
.HasOne<Manga>(j => j.Manga)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey(j => j.MangaId)
|
|
||||||
.IsRequired()
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
modelBuilder.Entity<RetrieveChaptersJob>()
|
|
||||||
.Navigation(j => j.Manga)
|
|
||||||
.AutoInclude();
|
|
||||||
modelBuilder.Entity<UpdateFilesDownloadedJob>()
|
|
||||||
.HasOne<Manga>(j => j.Manga)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey(j => j.MangaId)
|
|
||||||
.IsRequired()
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
modelBuilder.Entity<UpdateFilesDownloadedJob>()
|
|
||||||
.Navigation(j => j.Manga)
|
|
||||||
.AutoInclude();
|
|
||||||
|
|
||||||
//Job has possible ParentJob
|
|
||||||
modelBuilder.Entity<Job>()
|
|
||||||
.HasMany<Job>()
|
|
||||||
.WithOne(childJob => childJob.ParentJob)
|
|
||||||
.HasForeignKey(childjob => childjob.ParentJobId)
|
|
||||||
.IsRequired(false)
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
//Job might be dependent on other Jobs
|
|
||||||
modelBuilder.Entity<Job>()
|
|
||||||
.HasMany<Job>(root => root.DependsOnJobs)
|
|
||||||
.WithMany();
|
|
||||||
modelBuilder.Entity<Job>()
|
|
||||||
.Navigation(j => j.DependsOnJobs)
|
|
||||||
.AutoInclude(false);
|
|
||||||
|
|
||||||
//MangaConnector Types
|
|
||||||
modelBuilder.Entity<MangaConnector>()
|
|
||||||
.HasDiscriminator(c => c.Name)
|
|
||||||
.HasValue<Global>("Global")
|
|
||||||
.HasValue<MangaDex>("MangaDex");
|
|
||||||
//MangaConnector is responsible for many Manga
|
|
||||||
modelBuilder.Entity<MangaConnector>()
|
|
||||||
.HasMany<Manga>()
|
|
||||||
.WithOne(m => m.MangaConnector)
|
|
||||||
.HasForeignKey(m => m.MangaConnectorName)
|
|
||||||
.IsRequired()
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.Navigation(m => m.MangaConnector)
|
|
||||||
.AutoInclude();
|
|
||||||
|
|
||||||
//Manga has many Chapters
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.HasMany<Chapter>(m => m.Chapters)
|
|
||||||
.WithOne(c => c.ParentManga)
|
|
||||||
.HasForeignKey(c => c.ParentMangaId)
|
|
||||||
.IsRequired()
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
modelBuilder.Entity<Chapter>()
|
|
||||||
.Navigation(c => c.ParentManga)
|
|
||||||
.AutoInclude();
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.Navigation(m => m.Chapters)
|
|
||||||
.AutoInclude();
|
|
||||||
//Manga owns MangaAltTitles
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.OwnsMany<MangaAltTitle>(m => m.AltTitles)
|
|
||||||
.WithOwner();
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.Navigation(m => m.AltTitles)
|
|
||||||
.AutoInclude();
|
|
||||||
//Manga owns Links
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.OwnsMany<Link>(m => m.Links)
|
|
||||||
.WithOwner();
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.Navigation(m => m.Links)
|
|
||||||
.AutoInclude();
|
|
||||||
//Manga has many Tags associated with many Manga
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.HasMany<MangaTag>(m => m.MangaTags)
|
|
||||||
.WithMany()
|
|
||||||
.UsingEntity("MangaTagToManga",
|
|
||||||
l=> l.HasOne(typeof(MangaTag)).WithMany().HasForeignKey("MangaTagIds").HasPrincipalKey(nameof(MangaTag.Tag)),
|
|
||||||
r => r.HasOne(typeof(Manga)).WithMany().HasForeignKey("MangaIds").HasPrincipalKey(nameof(Manga.MangaId)),
|
|
||||||
j => j.HasKey("MangaTagIds", "MangaIds")
|
|
||||||
);
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.Navigation(m => m.MangaTags)
|
|
||||||
.AutoInclude();
|
|
||||||
//Manga has many Authors associated with many Manga
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.HasMany<Author>(m => m.Authors)
|
|
||||||
.WithMany()
|
|
||||||
.UsingEntity("AuthorToManga",
|
|
||||||
l=> l.HasOne(typeof(Author)).WithMany().HasForeignKey("AuthorIds").HasPrincipalKey(nameof(Author.AuthorId)),
|
|
||||||
r => r.HasOne(typeof(Manga)).WithMany().HasForeignKey("MangaIds").HasPrincipalKey(nameof(Manga.MangaId)),
|
|
||||||
j => j.HasKey("AuthorIds", "MangaIds")
|
|
||||||
);
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.Navigation(m => m.Authors)
|
|
||||||
.AutoInclude();
|
|
||||||
|
|
||||||
//LocalLibrary has many Mangas
|
|
||||||
modelBuilder.Entity<LocalLibrary>()
|
|
||||||
.HasMany<Manga>()
|
|
||||||
.WithOne(m => m.Library)
|
|
||||||
.HasForeignKey(m => m.LibraryId)
|
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
|
||||||
modelBuilder.Entity<Manga>()
|
|
||||||
.Navigation(m => m.Library)
|
|
||||||
.AutoInclude();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
24
API/Schema/Identifiable.cs
Normal file
24
API/Schema/Identifiable.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
[PrimaryKey("Key")]
|
||||||
|
public abstract class Identifiable
|
||||||
|
{
|
||||||
|
protected Identifiable()
|
||||||
|
{
|
||||||
|
this.Key = TokenGen.CreateToken(this.GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Identifiable(string key)
|
||||||
|
{
|
||||||
|
this.Key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(TokenGen.MaximumLength, MinimumLength = TokenGen.MinimumLength)]
|
||||||
|
public string Key { get; init; }
|
||||||
|
|
||||||
|
public override string ToString() => Key;
|
||||||
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace API.Schema.Jobs;
|
|
||||||
|
|
||||||
public class DownloadAvailableChaptersJob : Job
|
|
||||||
{
|
|
||||||
[StringLength(64)] [Required] public string MangaId { get; init; }
|
|
||||||
[JsonIgnore] public Manga Manga { get; init; } = null!;
|
|
||||||
|
|
||||||
public DownloadAvailableChaptersJob(Manga manga, ulong recurrenceMs, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
|
||||||
: base(TokenGen.CreateToken(typeof(DownloadAvailableChaptersJob)), JobType.DownloadAvailableChaptersJob, recurrenceMs, parentJob, dependsOnJobs)
|
|
||||||
{
|
|
||||||
this.MangaId = manga.MangaId;
|
|
||||||
this.Manga = manga;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF ONLY!!!
|
|
||||||
/// </summary>
|
|
||||||
internal DownloadAvailableChaptersJob(string mangaId, ulong recurrenceMs, string? parentJobId)
|
|
||||||
: base(TokenGen.CreateToken(typeof(DownloadAvailableChaptersJob)), JobType.DownloadAvailableChaptersJob, recurrenceMs, parentJobId)
|
|
||||||
{
|
|
||||||
this.MangaId = mangaId;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
|
||||||
{
|
|
||||||
context.Attach(Manga);
|
|
||||||
return Manga.Chapters.Select(chapter => new DownloadSingleChapterJob(chapter, this));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace API.Schema.Jobs;
|
|
||||||
|
|
||||||
public class DownloadMangaCoverJob : Job
|
|
||||||
{
|
|
||||||
[StringLength(64)] [Required] public string MangaId { get; init; }
|
|
||||||
[JsonIgnore] public Manga Manga { get; init; } = null!;
|
|
||||||
|
|
||||||
public DownloadMangaCoverJob(Manga manga, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
|
||||||
: base(TokenGen.CreateToken(typeof(DownloadMangaCoverJob)), JobType.DownloadMangaCoverJob, 0, parentJob, dependsOnJobs)
|
|
||||||
{
|
|
||||||
this.MangaId = manga.MangaId;
|
|
||||||
this.Manga = manga;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF ONLY!!!
|
|
||||||
/// </summary>
|
|
||||||
internal DownloadMangaCoverJob(string mangaId, string? parentJobId)
|
|
||||||
: base(TokenGen.CreateToken(typeof(DownloadMangaCoverJob)), JobType.DownloadMangaCoverJob, 0, parentJobId)
|
|
||||||
{
|
|
||||||
this.MangaId = mangaId;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
|
||||||
{
|
|
||||||
context.Attach(Manga);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Manga.CoverFileNameInCache = Manga.MangaConnector.SaveCoverImageToCache(Manga);
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
catch (DbUpdateException e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.IO.Compression;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using API.MangaDownloadClients;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using SixLabors.ImageSharp;
|
|
||||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
|
||||||
using SixLabors.ImageSharp.Processing;
|
|
||||||
using SixLabors.ImageSharp.Processing.Processors.Binarization;
|
|
||||||
using static System.IO.UnixFileMode;
|
|
||||||
|
|
||||||
namespace API.Schema.Jobs;
|
|
||||||
|
|
||||||
public class DownloadSingleChapterJob : Job
|
|
||||||
{
|
|
||||||
[StringLength(64)] [Required] public string ChapterId { get; init; }
|
|
||||||
|
|
||||||
[JsonIgnore] public Chapter Chapter { get; init; } = null!;
|
|
||||||
|
|
||||||
public DownloadSingleChapterJob(Chapter chapter, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
|
||||||
: base(TokenGen.CreateToken(typeof(DownloadSingleChapterJob)), JobType.DownloadSingleChapterJob, 0, parentJob, dependsOnJobs)
|
|
||||||
{
|
|
||||||
this.ChapterId = chapter.ChapterId;
|
|
||||||
this.Chapter = chapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF ONLY!!!
|
|
||||||
/// </summary>
|
|
||||||
internal DownloadSingleChapterJob(string chapterId, string? parentJobId)
|
|
||||||
: base(TokenGen.CreateToken(typeof(DownloadSingleChapterJob)), JobType.DownloadSingleChapterJob, 0, parentJobId)
|
|
||||||
{
|
|
||||||
this.ChapterId = chapterId;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
|
||||||
{
|
|
||||||
context.Attach(Chapter);
|
|
||||||
string[] imageUrls = Chapter.ParentManga.MangaConnector.GetChapterImageUrls(Chapter);
|
|
||||||
if (imageUrls.Length < 1)
|
|
||||||
{
|
|
||||||
Log.Info($"No imageUrls for chapter {ChapterId}");
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
string saveArchiveFilePath = Chapter.FullArchiveFilePath;
|
|
||||||
|
|
||||||
//Check if Publication Directory already exists
|
|
||||||
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
|
||||||
if (!Directory.Exists(directoryPath))
|
|
||||||
{
|
|
||||||
Log.Info($"Creating publication Directory: {directoryPath}");
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
||||||
Directory.CreateDirectory(directoryPath,
|
|
||||||
UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute );
|
|
||||||
else
|
|
||||||
Directory.CreateDirectory(directoryPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (File.Exists(saveArchiveFilePath)) //Don't download twice. Redownload
|
|
||||||
{
|
|
||||||
Log.Info($"Archive {saveArchiveFilePath} already existed, but deleting and re-downloading.");
|
|
||||||
File.Delete(saveArchiveFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create a temporary folder to store images
|
|
||||||
string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName;
|
|
||||||
Log.Debug($"Created temp folder: {tempFolder}");
|
|
||||||
|
|
||||||
Log.Info($"Downloading images: {ChapterId}");
|
|
||||||
int chapterNum = 0;
|
|
||||||
//Download all Images to temporary Folder
|
|
||||||
foreach (string imageUrl in imageUrls)
|
|
||||||
{
|
|
||||||
string extension = imageUrl.Split('.')[^1].Split('?')[0];
|
|
||||||
string imagePath = Path.Join(tempFolder, $"{chapterNum++}.{extension}");
|
|
||||||
bool status = DownloadImage(imageUrl, imagePath);
|
|
||||||
if (status is false)
|
|
||||||
{
|
|
||||||
Log.Error($"Failed to download image: {imageUrl}");
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CopyCoverFromCacheToDownloadLocation(Chapter.ParentManga);
|
|
||||||
|
|
||||||
Log.Debug($"Creating ComicInfo.xml {ChapterId}");
|
|
||||||
File.WriteAllText(Path.Join(tempFolder, "ComicInfo.xml"), Chapter.GetComicInfoXmlString());
|
|
||||||
|
|
||||||
Log.Debug($"Packaging images to archive {ChapterId}");
|
|
||||||
//ZIP-it and ship-it
|
|
||||||
ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath);
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
||||||
File.SetUnixFileMode(saveArchiveFilePath, UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute | OtherRead | OtherExecute);
|
|
||||||
Directory.Delete(tempFolder, true); //Cleanup
|
|
||||||
|
|
||||||
Chapter.Downloaded = true;
|
|
||||||
context.SaveChanges();
|
|
||||||
|
|
||||||
return [new UpdateFilesDownloadedJob(Chapter.ParentManga, 0, this)];
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ProcessImage(string imagePath)
|
|
||||||
{
|
|
||||||
if (!TrangaSettings.bwImages && TrangaSettings.compression == 100)
|
|
||||||
{
|
|
||||||
Log.Debug($"No processing requested for image");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Debug($"Processing image: {imagePath}");
|
|
||||||
|
|
||||||
using Image image = Image.Load(imagePath);
|
|
||||||
File.Delete(imagePath);
|
|
||||||
if(TrangaSettings.bwImages)
|
|
||||||
image.Mutate(i => i.ApplyProcessor(new AdaptiveThresholdProcessor()));
|
|
||||||
image.SaveAsJpeg(imagePath, new JpegEncoder()
|
|
||||||
{
|
|
||||||
Quality = TrangaSettings.compression
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CopyCoverFromCacheToDownloadLocation(Manga manga)
|
|
||||||
{
|
|
||||||
//Check if Publication already has a Folder and cover
|
|
||||||
string publicationFolder = manga.CreatePublicationFolder();
|
|
||||||
DirectoryInfo dirInfo = new (publicationFolder);
|
|
||||||
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
|
|
||||||
{
|
|
||||||
Log.Debug($"Cover already exists at {publicationFolder}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Info($"Copying cover to {publicationFolder}");
|
|
||||||
string? fileInCache = manga.CoverFileNameInCache ?? manga.MangaConnector.SaveCoverImageToCache(manga);
|
|
||||||
if (fileInCache is null)
|
|
||||||
{
|
|
||||||
Log.Error($"File {fileInCache} does not exist");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" );
|
|
||||||
File.Copy(fileInCache, newFilePath, true);
|
|
||||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
||||||
File.SetUnixFileMode(newFilePath, GroupRead | GroupWrite | UserRead | UserWrite);
|
|
||||||
Log.Debug($"Copied cover from {fileInCache} to {newFilePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool DownloadImage(string imageUrl, string savePath)
|
|
||||||
{
|
|
||||||
HttpDownloadClient downloadClient = new();
|
|
||||||
RequestResult requestResult = downloadClient.MakeRequest(imageUrl, RequestType.MangaImage);
|
|
||||||
|
|
||||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
|
||||||
return false;
|
|
||||||
if (requestResult.result == Stream.Null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
FileStream fs = new (savePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
|
||||||
requestResult.result.CopyTo(fs);
|
|
||||||
fs.Close();
|
|
||||||
ProcessImage(savePath);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
using log4net;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace API.Schema.Jobs;
|
|
||||||
|
|
||||||
[PrimaryKey("JobId")]
|
|
||||||
public abstract class Job
|
|
||||||
{
|
|
||||||
[StringLength(64)]
|
|
||||||
[Required]
|
|
||||||
public string JobId { get; init; }
|
|
||||||
|
|
||||||
[StringLength(64)] public string? ParentJobId { get; init; }
|
|
||||||
[JsonIgnore] public Job? ParentJob { get; init; }
|
|
||||||
[JsonIgnore] public ICollection<Job> DependsOnJobs { get; init; }
|
|
||||||
|
|
||||||
[Required] public JobType JobType { get; init; }
|
|
||||||
|
|
||||||
[Required] public ulong RecurrenceMs { get; set; }
|
|
||||||
|
|
||||||
[Required] public DateTime LastExecution { get; internal set; } = DateTime.UnixEpoch;
|
|
||||||
|
|
||||||
[NotMapped] [Required] public DateTime NextExecution => LastExecution.AddMilliseconds(RecurrenceMs);
|
|
||||||
[Required] public JobState state { get; internal set; } = JobState.FirstExecution;
|
|
||||||
[Required] public bool Enabled { get; internal set; } = true;
|
|
||||||
|
|
||||||
[JsonIgnore] [NotMapped] internal bool IsCompleted => state is >= (JobState)128 and < (JobState)192;
|
|
||||||
[JsonIgnore] [NotMapped] internal bool DependenciesFulfilled => DependsOnJobs.All(j => j.IsCompleted);
|
|
||||||
|
|
||||||
[NotMapped] [JsonIgnore] protected ILog Log { get; init; }
|
|
||||||
|
|
||||||
protected Job(string jobId, JobType jobType, ulong recurrenceMs, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
|
||||||
{
|
|
||||||
this.JobId = jobId;
|
|
||||||
this.JobType = jobType;
|
|
||||||
this.RecurrenceMs = recurrenceMs;
|
|
||||||
this.ParentJobId = parentJob?.JobId;
|
|
||||||
this.ParentJob = parentJob;
|
|
||||||
this.DependsOnJobs = dependsOnJobs ?? [];
|
|
||||||
|
|
||||||
this.Log = LogManager.GetLogger(this.GetType());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF ONLY!!!
|
|
||||||
/// </summary>
|
|
||||||
protected internal Job(string jobId, JobType jobType, ulong recurrenceMs, string? parentJobId)
|
|
||||||
{
|
|
||||||
this.JobId = jobId;
|
|
||||||
this.JobType = jobType;
|
|
||||||
this.RecurrenceMs = recurrenceMs;
|
|
||||||
this.ParentJobId = parentJobId;
|
|
||||||
this.DependsOnJobs = [];
|
|
||||||
|
|
||||||
this.Log = LogManager.GetLogger(this.GetType());
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Job> Run(IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
Log.Debug($"Running job {JobId}");
|
|
||||||
using IServiceScope scope = serviceProvider.CreateScope();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
PgsqlContext context = scope.ServiceProvider.GetRequiredService<PgsqlContext>();
|
|
||||||
context.Attach(this);
|
|
||||||
this.state = JobState.Running;
|
|
||||||
context.SaveChanges();
|
|
||||||
Job[] newJobs = RunInternal(context).ToArray();
|
|
||||||
this.state = JobState.Completed;
|
|
||||||
context.SaveChanges();
|
|
||||||
context.Jobs.AddRange(newJobs);
|
|
||||||
context.SaveChanges();
|
|
||||||
Log.Info($"Job {JobId} completed. Generated {newJobs.Length} new jobs.");
|
|
||||||
return newJobs;
|
|
||||||
}
|
|
||||||
catch (DbUpdateException e)
|
|
||||||
{
|
|
||||||
this.state = JobState.Failed;
|
|
||||||
Log.Error($"Failed to run job {JobId}", e);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract IEnumerable<Job> RunInternal(PgsqlContext context);
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"{JobId}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
namespace API.Schema.Jobs;
|
|
||||||
|
|
||||||
public enum JobState : byte
|
|
||||||
{
|
|
||||||
//Values 0-63 Preparation Stages
|
|
||||||
FirstExecution = 0,
|
|
||||||
//64-127 Running Stages
|
|
||||||
Running = 64,
|
|
||||||
//128-191 Completion Stages
|
|
||||||
Completed = 128,
|
|
||||||
CompletedWaiting = 159,
|
|
||||||
//192-255 Error stages
|
|
||||||
Failed = 192
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
namespace API.Schema.Jobs;
|
|
||||||
|
|
||||||
|
|
||||||
public enum JobType : byte
|
|
||||||
{
|
|
||||||
DownloadSingleChapterJob = 0,
|
|
||||||
DownloadAvailableChaptersJob = 1,
|
|
||||||
UpdateMetaDataJob = 2,
|
|
||||||
MoveFileOrFolderJob = 3,
|
|
||||||
DownloadMangaCoverJob = 4,
|
|
||||||
RetrieveChaptersJob = 5,
|
|
||||||
UpdateFilesDownloadedJob = 6,
|
|
||||||
MoveMangaLibraryJob = 7
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
|
|
||||||
namespace API.Schema.Jobs;
|
|
||||||
|
|
||||||
public class MoveFileOrFolderJob : Job
|
|
||||||
{
|
|
||||||
[StringLength(256)]
|
|
||||||
[Required]
|
|
||||||
public string FromLocation { get; init; }
|
|
||||||
[StringLength(256)]
|
|
||||||
[Required]
|
|
||||||
public string ToLocation { get; init; }
|
|
||||||
|
|
||||||
public MoveFileOrFolderJob(string fromLocation, string toLocation, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
|
||||||
: base(TokenGen.CreateToken(typeof(MoveFileOrFolderJob)), JobType.MoveFileOrFolderJob, 0, parentJob, dependsOnJobs)
|
|
||||||
{
|
|
||||||
this.FromLocation = fromLocation;
|
|
||||||
this.ToLocation = toLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF ONLY!!!
|
|
||||||
/// </summary>
|
|
||||||
internal MoveFileOrFolderJob(string jobId, string fromLocation, string toLocation, string? parentJobId)
|
|
||||||
: base(jobId, JobType.MoveFileOrFolderJob, 0, parentJobId)
|
|
||||||
{
|
|
||||||
this.FromLocation = fromLocation;
|
|
||||||
this.ToLocation = toLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileInfo fi = new (FromLocation);
|
|
||||||
if (!fi.Exists)
|
|
||||||
{
|
|
||||||
Log.Error($"File does not exist at {FromLocation}");
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (File.Exists(ToLocation))//Do not override existing
|
|
||||||
{
|
|
||||||
Log.Error($"File already exists at {ToLocation}");
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
if(fi.Attributes.HasFlag(FileAttributes.Directory))
|
|
||||||
MoveDirectory(fi, ToLocation);
|
|
||||||
else
|
|
||||||
MoveFile(fi, ToLocation);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
private void MoveDirectory(FileInfo from, string toLocation)
|
|
||||||
{
|
|
||||||
Directory.Move(from.FullName, toLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void MoveFile(FileInfo from, string toLocation)
|
|
||||||
{
|
|
||||||
File.Move(from.FullName, toLocation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace API.Schema.Jobs;
|
|
||||||
|
|
||||||
public class MoveMangaLibraryJob : Job
|
|
||||||
{
|
|
||||||
[StringLength(64)] [Required] public string MangaId { get; init; }
|
|
||||||
[JsonIgnore] public Manga Manga { get; init; } = null!;
|
|
||||||
[StringLength(64)] [Required] public string ToLibraryId { get; init; }
|
|
||||||
public LocalLibrary ToLibrary { get; init; } = null!;
|
|
||||||
|
|
||||||
public MoveMangaLibraryJob(Manga manga, LocalLibrary toLibrary, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
|
||||||
: base(TokenGen.CreateToken(typeof(MoveMangaLibraryJob)), JobType.MoveMangaLibraryJob, 0, parentJob, dependsOnJobs)
|
|
||||||
{
|
|
||||||
this.MangaId = manga.MangaId;
|
|
||||||
this.Manga = manga;
|
|
||||||
this.ToLibraryId = toLibrary.LocalLibraryId;
|
|
||||||
this.ToLibrary = toLibrary;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF ONLY!!!
|
|
||||||
/// </summary>
|
|
||||||
internal MoveMangaLibraryJob(string mangaId, string toLibraryId, string? parentJobId)
|
|
||||||
: base(TokenGen.CreateToken(typeof(MoveMangaLibraryJob)), JobType.MoveMangaLibraryJob, 0, parentJobId)
|
|
||||||
{
|
|
||||||
this.MangaId = mangaId;
|
|
||||||
this.ToLibraryId = toLibraryId;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
|
||||||
{
|
|
||||||
context.Attach(Manga);
|
|
||||||
Dictionary<Chapter, string> oldPath = Manga.Chapters.ToDictionary(c => c, c => c.FullArchiveFilePath);
|
|
||||||
Manga.Library = ToLibrary;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
catch (DbUpdateException e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return Manga.Chapters.Select(c => new MoveFileOrFolderJob(oldPath[c], c.FullArchiveFilePath));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace API.Schema.Jobs;
|
|
||||||
|
|
||||||
public class RetrieveChaptersJob : Job
|
|
||||||
{
|
|
||||||
[StringLength(64)] [Required] public string MangaId { get; init; }
|
|
||||||
[JsonIgnore] public Manga Manga { get; init; } = null!;
|
|
||||||
[StringLength(8)] [Required] public string Language { get; private set; }
|
|
||||||
|
|
||||||
public RetrieveChaptersJob(Manga manga, string language, ulong recurrenceMs, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
|
||||||
: base(TokenGen.CreateToken(typeof(RetrieveChaptersJob)), JobType.RetrieveChaptersJob, recurrenceMs, parentJob, dependsOnJobs)
|
|
||||||
{
|
|
||||||
this.MangaId = manga.MangaId;
|
|
||||||
this.Manga = manga;
|
|
||||||
this.Language = language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF ONLY!!!
|
|
||||||
/// </summary>
|
|
||||||
internal RetrieveChaptersJob(string mangaId, string language, ulong recurrenceMs, string? parentJobId)
|
|
||||||
: base(TokenGen.CreateToken(typeof(RetrieveChaptersJob)), JobType.RetrieveChaptersJob, recurrenceMs, parentJobId)
|
|
||||||
{
|
|
||||||
this.MangaId = mangaId;
|
|
||||||
this.Language = language;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
|
||||||
{
|
|
||||||
context.Attach(Manga);
|
|
||||||
// This gets all chapters that are not downloaded
|
|
||||||
Chapter[] allChapters = Manga.MangaConnector.GetChapters(Manga, Language);
|
|
||||||
Chapter[] newChapters = allChapters.Where(chapter => context.Chapters.Contains(chapter) == false).ToArray();
|
|
||||||
Log.Info($"{newChapters.Length} new chapters.");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
context.Chapters.AddRange(newChapters);
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
catch (DbUpdateException e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using API.Schema.Contexts;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace API.Schema.Jobs;
|
|
||||||
|
|
||||||
public class UpdateFilesDownloadedJob : Job
|
|
||||||
{
|
|
||||||
[StringLength(64)] [Required] public string MangaId { get; init; }
|
|
||||||
[JsonIgnore] public Manga Manga { get; init; } = null!;
|
|
||||||
|
|
||||||
public UpdateFilesDownloadedJob(Manga manga, ulong recurrenceMs, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
|
||||||
: base(TokenGen.CreateToken(typeof(UpdateFilesDownloadedJob)), JobType.UpdateFilesDownloadedJob, recurrenceMs, parentJob, dependsOnJobs)
|
|
||||||
{
|
|
||||||
this.MangaId = manga.MangaId;
|
|
||||||
this.Manga = manga;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF ONLY!!!
|
|
||||||
/// </summary>
|
|
||||||
internal UpdateFilesDownloadedJob(string mangaId, ulong recurrenceMs, string? parentJobId)
|
|
||||||
: base(TokenGen.CreateToken(typeof(UpdateFilesDownloadedJob)), JobType.UpdateFilesDownloadedJob, recurrenceMs, parentJobId)
|
|
||||||
{
|
|
||||||
this.MangaId = mangaId;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
|
||||||
{
|
|
||||||
context.Attach(Manga);
|
|
||||||
foreach (Chapter chapter in Manga.Chapters)
|
|
||||||
chapter.Downloaded = chapter.CheckDownloaded();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
catch (DbUpdateException e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using log4net;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace API.Schema.LibraryConnectors;
|
|
||||||
|
|
||||||
[PrimaryKey("LibraryConnectorId")]
|
|
||||||
public abstract class LibraryConnector(string libraryConnectorId, LibraryType libraryType, string baseUrl, string auth)
|
|
||||||
{
|
|
||||||
[StringLength(64)]
|
|
||||||
[Required]
|
|
||||||
public string LibraryConnectorId { get; } = libraryConnectorId;
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public LibraryType LibraryType { get; init; } = libraryType;
|
|
||||||
[StringLength(256)]
|
|
||||||
[Required]
|
|
||||||
[Url]
|
|
||||||
public string BaseUrl { get; init; } = baseUrl;
|
|
||||||
[StringLength(256)]
|
|
||||||
[Required]
|
|
||||||
public string Auth { get; init; } = auth;
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
[NotMapped]
|
|
||||||
protected ILog Log { get; init; } = LogManager.GetLogger($"{libraryType.ToString()} {baseUrl}");
|
|
||||||
|
|
||||||
protected abstract void UpdateLibraryInternal();
|
|
||||||
internal abstract bool Test();
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace API.Schema.LibraryConnectors;
|
|
||||||
|
|
||||||
public enum LibraryType : byte
|
|
||||||
{
|
|
||||||
Komga = 0,
|
|
||||||
Kavita = 1
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace API.Schema.LibraryConnectors;
|
namespace API.Schema.LibraryContext.LibraryConnectors;
|
||||||
|
|
||||||
public class Kavita : LibraryConnector
|
public class Kavita : LibraryConnector
|
||||||
{
|
{
|
||||||
|
|
||||||
public Kavita(string baseUrl, string auth) : base(TokenGen.CreateToken(typeof(Kavita), baseUrl), LibraryType.Kavita, baseUrl, auth)
|
public Kavita(string baseUrl, string auth) : base(LibraryType.Kavita, baseUrl, auth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,8 +44,9 @@ public class Kavita : LibraryConnector
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (HttpRequestException e)
|
catch (HttpRequestException)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -53,13 +54,13 @@ public class Kavita : LibraryConnector
|
|||||||
protected override void UpdateLibraryInternal()
|
protected override void UpdateLibraryInternal()
|
||||||
{
|
{
|
||||||
foreach (KavitaLibrary lib in GetLibraries())
|
foreach (KavitaLibrary lib in GetLibraries())
|
||||||
NetClient.MakePost($"{BaseUrl}/api/ToLibrary/scan?libraryId={lib.id}", "Bearer", Auth);
|
NetClient.MakePost($"{BaseUrl}/api/ToFileLibrary/scan?libraryId={lib.id}", "Bearer", Auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override bool Test()
|
internal override bool Test()
|
||||||
{
|
{
|
||||||
foreach (KavitaLibrary lib in GetLibraries())
|
foreach (KavitaLibrary lib in GetLibraries())
|
||||||
if (NetClient.MakePost($"{BaseUrl}/api/ToLibrary/scan?libraryId={lib.id}", "Bearer", Auth))
|
if (NetClient.MakePost($"{BaseUrl}/api/ToFileLibrary/scan?libraryId={lib.id}", "Bearer", Auth))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -70,7 +71,7 @@ public class Kavita : LibraryConnector
|
|||||||
/// <returns>Array of KavitaLibrary</returns>
|
/// <returns>Array of KavitaLibrary</returns>
|
||||||
private IEnumerable<KavitaLibrary> GetLibraries()
|
private IEnumerable<KavitaLibrary> GetLibraries()
|
||||||
{
|
{
|
||||||
Stream data = NetClient.MakeRequest($"{BaseUrl}/api/ToLibrary/libraries", "Bearer", Auth);
|
Stream data = NetClient.MakeRequest($"{BaseUrl}/api/ToFileLibrary/libraries", "Bearer", Auth);
|
||||||
if (data == Stream.Null)
|
if (data == Stream.Null)
|
||||||
{
|
{
|
||||||
Log.Info("No libraries found");
|
Log.Info("No libraries found");
|
||||||
@@ -90,7 +91,7 @@ public class Kavita : LibraryConnector
|
|||||||
JsonObject? jObject = (JsonObject?)jsonNode;
|
JsonObject? jObject = (JsonObject?)jsonNode;
|
||||||
if(jObject is null)
|
if(jObject is null)
|
||||||
continue;
|
continue;
|
||||||
int libraryId = jObject!["id"]!.GetValue<int>();
|
int libraryId = jObject["id"]!.GetValue<int>();
|
||||||
string libraryName = jObject["name"]!.GetValue<string>();
|
string libraryName = jObject["name"]!.GetValue<string>();
|
||||||
ret.Add(new KavitaLibrary(libraryId, libraryName));
|
ret.Add(new KavitaLibrary(libraryId, libraryName));
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace API.Schema.LibraryConnectors;
|
namespace API.Schema.LibraryContext.LibraryConnectors;
|
||||||
|
|
||||||
public class Komga : LibraryConnector
|
public class Komga : LibraryConnector
|
||||||
{
|
{
|
||||||
public Komga(string baseUrl, string auth) : base(TokenGen.CreateToken(typeof(Komga), baseUrl), LibraryType.Komga,
|
public Komga(string baseUrl, string auth) : base(LibraryType.Komga, baseUrl, auth)
|
||||||
baseUrl, auth)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using log4net;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace API.Schema.LibraryContext.LibraryConnectors;
|
||||||
|
|
||||||
|
[PrimaryKey("Key")]
|
||||||
|
public abstract class LibraryConnector : Identifiable
|
||||||
|
{
|
||||||
|
public LibraryType LibraryType { get; init; }
|
||||||
|
[StringLength(256)] [Url] public string BaseUrl { get; init; }
|
||||||
|
[StringLength(256)] public string Auth { get; init; }
|
||||||
|
[NotMapped] protected ILog Log { get; init; }
|
||||||
|
|
||||||
|
protected LibraryConnector(LibraryType libraryType, string baseUrl, string auth)
|
||||||
|
: base()
|
||||||
|
{
|
||||||
|
this.LibraryType = libraryType;
|
||||||
|
this.BaseUrl = baseUrl;
|
||||||
|
this.Auth = auth;
|
||||||
|
this.Log = LogManager.GetLogger(GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// EF CORE ONLY!!!!
|
||||||
|
/// </summary>
|
||||||
|
internal LibraryConnector(string key, LibraryType libraryType, string baseUrl, string auth)
|
||||||
|
: base(key)
|
||||||
|
{
|
||||||
|
this.LibraryType = libraryType;
|
||||||
|
this.BaseUrl = baseUrl;
|
||||||
|
this.Auth = auth;
|
||||||
|
this.Log = LogManager.GetLogger(GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() => $"{base.ToString()} {this.LibraryType} {this.BaseUrl}";
|
||||||
|
|
||||||
|
protected abstract void UpdateLibraryInternal();
|
||||||
|
internal abstract bool Test();
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum LibraryType : byte
|
||||||
|
{
|
||||||
|
Komga = 0,
|
||||||
|
Kavita = 1
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using log4net;
|
using log4net;
|
||||||
|
|
||||||
namespace API.Schema.LibraryConnectors;
|
namespace API.Schema.LibraryContext.LibraryConnectors;
|
||||||
|
|
||||||
public class NetClient
|
public class NetClient
|
||||||
{
|
{
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using API.Schema.LibraryConnectors;
|
using API.Schema.LibraryContext.LibraryConnectors;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Schema.Contexts;
|
namespace API.Schema.LibraryContext;
|
||||||
|
|
||||||
public class LibraryContext(DbContextOptions<LibraryContext> options) : DbContext(options)
|
public class LibraryContext(DbContextOptions<LibraryContext> options) : TrangaBaseContext<LibraryContext>(options)
|
||||||
{
|
{
|
||||||
public DbSet<LibraryConnector> LibraryConnectors { get; set; }
|
public DbSet<LibraryConnector> LibraryConnectors { get; set; }
|
||||||
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Schema;
|
|
||||||
|
|
||||||
[PrimaryKey("LinkId")]
|
|
||||||
public class Link(string linkProvider, string linkUrl)
|
|
||||||
{
|
|
||||||
[StringLength(64)]
|
|
||||||
[Required]
|
|
||||||
public string LinkId { get; init; } = TokenGen.CreateToken(typeof(Link), linkProvider, linkUrl);
|
|
||||||
[StringLength(64)]
|
|
||||||
[Required]
|
|
||||||
public string LinkProvider { get; init; } = linkProvider;
|
|
||||||
[StringLength(2048)]
|
|
||||||
[Required]
|
|
||||||
[Url]
|
|
||||||
public string LinkUrl { get; init; } = linkUrl;
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"{LinkId} {LinkProvider} {LinkUrl}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace API.Schema;
|
|
||||||
|
|
||||||
public class LocalLibrary(string basePath, string libraryName)
|
|
||||||
{
|
|
||||||
[StringLength(64)]
|
|
||||||
[Required]
|
|
||||||
public string LocalLibraryId { get; init; } = TokenGen.CreateToken(typeof(LocalLibrary), basePath);
|
|
||||||
[StringLength(256)]
|
|
||||||
[Required]
|
|
||||||
public string BasePath { get; internal set; } = basePath;
|
|
||||||
|
|
||||||
[StringLength(512)]
|
|
||||||
[Required]
|
|
||||||
public string LibraryName { get; internal set; } = libraryName;
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"{LocalLibraryId} {LibraryName} - {BasePath}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
|
||||||
using API.Schema.MangaConnectors;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using static System.IO.UnixFileMode;
|
|
||||||
|
|
||||||
namespace API.Schema;
|
|
||||||
|
|
||||||
[PrimaryKey("MangaId")]
|
|
||||||
public class Manga
|
|
||||||
{
|
|
||||||
[StringLength(64)]
|
|
||||||
[Required]
|
|
||||||
public string MangaId { get; init; }
|
|
||||||
[StringLength(256)] [Required] public string IdOnConnectorSite { get; init; }
|
|
||||||
[StringLength(512)] [Required] public string Name { get; internal set; }
|
|
||||||
[Required] public string Description { get; internal set; }
|
|
||||||
[Url] [StringLength(512)] [Required] public string WebsiteUrl { get; internal init; }
|
|
||||||
[JsonIgnore] [Url] [StringLength(512)] public string CoverUrl { get; internal set; }
|
|
||||||
[Required] public MangaReleaseStatus ReleaseStatus { get; internal set; }
|
|
||||||
|
|
||||||
[StringLength(64)]
|
|
||||||
public string? LibraryId { get; init; }
|
|
||||||
[JsonIgnore] public LocalLibrary? Library { get; internal set; }
|
|
||||||
|
|
||||||
[StringLength(32)]
|
|
||||||
[Required]
|
|
||||||
public string MangaConnectorName { get; init; }
|
|
||||||
[JsonIgnore] public MangaConnector MangaConnector { get; init; } = null!;
|
|
||||||
|
|
||||||
public ICollection<Author> Authors { get; internal set; }= null!;
|
|
||||||
public ICollection<MangaTag> MangaTags { get; internal set; }= null!;
|
|
||||||
public ICollection<Link> Links { get; internal set; }= null!;
|
|
||||||
public ICollection<MangaAltTitle> AltTitles { get; internal set; } = null!;
|
|
||||||
[Required] public float IgnoreChaptersBefore { get; internal set; }
|
|
||||||
[StringLength(1024)] [Required] public string DirectoryName { get; private set; }
|
|
||||||
|
|
||||||
[JsonIgnore] [StringLength(512)] public string? CoverFileNameInCache { get; internal set; } = null;
|
|
||||||
[Required] public uint? Year { get; internal init; }
|
|
||||||
[StringLength(8)] public string? OriginalLanguage { get; internal init; }
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
[NotMapped]
|
|
||||||
public string? FullDirectoryPath => Library is not null ? Path.Join(Library.BasePath, DirectoryName) : null;
|
|
||||||
|
|
||||||
[JsonIgnore] public ICollection<Chapter> Chapters { get; internal set; } = [];
|
|
||||||
|
|
||||||
public Manga(string idOnConnector, string name, string description, string websiteUrl, string coverUrl, MangaReleaseStatus releaseStatus,
|
|
||||||
MangaConnector mangaConnector, ICollection<Author> authors, ICollection<MangaTag> mangaTags, ICollection<Link> links, ICollection<MangaAltTitle> altTitles,
|
|
||||||
LocalLibrary? library = null, float ignoreChaptersBefore = 0f, uint? year = null, string? originalLanguage = null)
|
|
||||||
{
|
|
||||||
this.MangaId = TokenGen.CreateToken(typeof(Manga), mangaConnector.Name, idOnConnector);
|
|
||||||
this.IdOnConnectorSite = idOnConnector;
|
|
||||||
this.Name = name;
|
|
||||||
this.Description = description;
|
|
||||||
this.WebsiteUrl = websiteUrl;
|
|
||||||
this.CoverUrl = coverUrl;
|
|
||||||
this.ReleaseStatus = releaseStatus;
|
|
||||||
this.LibraryId = library?.LocalLibraryId;
|
|
||||||
this.Library = library;
|
|
||||||
this.MangaConnectorName = mangaConnector.Name;
|
|
||||||
this.MangaConnector = mangaConnector;
|
|
||||||
this.Authors = authors;
|
|
||||||
this.MangaTags = mangaTags;
|
|
||||||
this.Links = links;
|
|
||||||
this.AltTitles = altTitles;
|
|
||||||
this.IgnoreChaptersBefore = ignoreChaptersBefore;
|
|
||||||
this.DirectoryName = CleanDirectoryName(name);
|
|
||||||
this.Year = year;
|
|
||||||
this.OriginalLanguage = originalLanguage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF ONLY!!!
|
|
||||||
/// </summary>
|
|
||||||
public Manga(string mangaId, string idOnConnectorSite, string name, string description, string websiteUrl, string coverUrl, MangaReleaseStatus releaseStatus,
|
|
||||||
string mangaConnectorName, string directoryName, float ignoreChaptersBefore, string? libraryId, uint? year, string? originalLanguage)
|
|
||||||
{
|
|
||||||
this.MangaId = mangaId;
|
|
||||||
this.IdOnConnectorSite = idOnConnectorSite;
|
|
||||||
this.Name = name;
|
|
||||||
this.Description = description;
|
|
||||||
this.WebsiteUrl = websiteUrl;
|
|
||||||
this.CoverUrl = coverUrl;
|
|
||||||
this.ReleaseStatus = releaseStatus;
|
|
||||||
this.MangaConnectorName = mangaConnectorName;
|
|
||||||
this.DirectoryName = directoryName;
|
|
||||||
this.LibraryId = libraryId;
|
|
||||||
this.IgnoreChaptersBefore = ignoreChaptersBefore;
|
|
||||||
this.Year = year;
|
|
||||||
this.OriginalLanguage = originalLanguage;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public string CreatePublicationFolder()
|
|
||||||
{
|
|
||||||
string publicationFolder = FullDirectoryPath;
|
|
||||||
if(!Directory.Exists(publicationFolder))
|
|
||||||
Directory.CreateDirectory(publicationFolder);
|
|
||||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
||||||
File.SetUnixFileMode(publicationFolder, GroupRead | GroupWrite | GroupExecute | OtherRead | OtherWrite | OtherExecute | UserRead | UserWrite | UserExecute);
|
|
||||||
return publicationFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
//https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
|
|
||||||
//less than 32 is control *forbidden*
|
|
||||||
//34 is " *forbidden*
|
|
||||||
//42 is * *forbidden*
|
|
||||||
//47 is / *forbidden*
|
|
||||||
//58 is : *forbidden*
|
|
||||||
//60 is < *forbidden*
|
|
||||||
//62 is > *forbidden*
|
|
||||||
//63 is ? *forbidden*
|
|
||||||
//92 is \ *forbidden*
|
|
||||||
//124 is | *forbidden*
|
|
||||||
//127 is delete *forbidden*
|
|
||||||
//Below 127 all except *******
|
|
||||||
private static readonly int[] ForbiddenCharsBelow127 = [34, 42, 47, 58, 60, 62, 63, 92, 124, 127];
|
|
||||||
//Above 127 none except *******
|
|
||||||
private static readonly int[] IncludeCharsAbove127 = [128, 138, 142];
|
|
||||||
//128 is € include
|
|
||||||
//138 is Š include
|
|
||||||
//142 is Ž include
|
|
||||||
//152 through 255 looks fine except 157, 172, 173, 175 *******
|
|
||||||
private static readonly int[] ForbiddenCharsAbove152 = [157, 172, 173, 175];
|
|
||||||
private static string CleanDirectoryName(string name)
|
|
||||||
{
|
|
||||||
StringBuilder sb = new ();
|
|
||||||
foreach (char c in name)
|
|
||||||
{
|
|
||||||
if (c > 32 && c < 127 && ForbiddenCharsBelow127.Contains(c) == false)
|
|
||||||
sb.Append(c);
|
|
||||||
else if (c > 127 && c < 152 && IncludeCharsAbove127.Contains(c))
|
|
||||||
sb.Append(c);
|
|
||||||
else if(c >= 152 && c <= 255 && ForbiddenCharsAbove152.Contains(c) == false)
|
|
||||||
sb.Append(c);
|
|
||||||
}
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"{MangaId} {Name}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Schema;
|
|
||||||
|
|
||||||
[PrimaryKey("AltTitleId")]
|
|
||||||
public class MangaAltTitle(string language, string title)
|
|
||||||
{
|
|
||||||
[StringLength(64)]
|
|
||||||
[Required]
|
|
||||||
public string AltTitleId { get; init; } = TokenGen.CreateToken("AltTitle", language, title);
|
|
||||||
[StringLength(8)]
|
|
||||||
[Required]
|
|
||||||
public string Language { get; init; } = language;
|
|
||||||
[StringLength(256)]
|
|
||||||
[Required]
|
|
||||||
public string Title { get; set; } = title;
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"{AltTitleId} {Language} {Title}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
using API.Schema.Contexts;
|
|
||||||
|
|
||||||
namespace API.Schema.MangaConnectors;
|
|
||||||
|
|
||||||
public class Global : MangaConnector
|
|
||||||
{
|
|
||||||
private PgsqlContext context { get; init; }
|
|
||||||
public Global(PgsqlContext context) : base("Global", ["all"], [""], "")
|
|
||||||
{
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Manga[] SearchManga(string mangaSearchName)
|
|
||||||
{
|
|
||||||
//Get all enabled Connectors
|
|
||||||
MangaConnector[] enabledConnectors = context.MangaConnectors.Where(c => c.Enabled && c.Name != "Global").ToArray();
|
|
||||||
|
|
||||||
//Create Task for each MangaConnector to search simulatneously
|
|
||||||
Task<Manga[]>[] tasks =
|
|
||||||
enabledConnectors.Select(c => new Task<Manga[]>(() => c.SearchManga(mangaSearchName))).ToArray();
|
|
||||||
foreach (var task in tasks)
|
|
||||||
task.Start();
|
|
||||||
|
|
||||||
//Wait for all tasks to finish
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Thread.Sleep(50);
|
|
||||||
}while(tasks.Any(t => t.Status < TaskStatus.RanToCompletion));
|
|
||||||
|
|
||||||
//Concatenate all results into one
|
|
||||||
Manga[] ret = tasks.Select(t => t.IsCompletedSuccessfully ? t.Result : []).ToArray().SelectMany(i => i).ToArray();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Manga? GetMangaFromUrl(string url)
|
|
||||||
{
|
|
||||||
MangaConnector? mc = context.MangaConnectors.ToArray().FirstOrDefault(c => c.UrlMatchesConnector(url));
|
|
||||||
return mc?.GetMangaFromUrl(url) ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Manga? GetMangaFromId(string mangaIdOnSite)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Chapter[] GetChapters(Manga manga, string? language = null)
|
|
||||||
{
|
|
||||||
return manga.MangaConnector.GetChapters(manga, language);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal override string[] GetChapterImageUrls(Chapter chapter)
|
|
||||||
{
|
|
||||||
return chapter.ParentManga.MangaConnector.GetChapterImageUrls(chapter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user