From b3d5cb92b100406df98e5cd1f54eff9cd2078b1c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Feb 2021 11:07:08 +0100 Subject: [PATCH] Add ability to update torrents cache in client --- .../edit-advanced-configuration.component.html | 14 ++++++++++++++ .../edit-advanced-configuration.component.ts | 2 +- .../edit-custom-config.component.ts | 3 +++ config/test.yaml | 2 ++ server/controllers/api/config.ts | 3 +++ server/lib/thumbnail.ts | 3 +-- server/middlewares/validators/config.ts | 1 + server/models/server/tracker.ts | 2 +- server/tests/api/check-params/config.ts | 3 +++ server/tests/api/server/config.ts | 5 +++++ shared/extra-utils/server/config.ts | 3 +++ shared/models/server/custom-config.model.ts | 4 ++++ 12 files changed, 41 insertions(+), 4 deletions(-) diff --git a/client/src/app/+admin/config/edit-custom-config/edit-advanced-configuration.component.html b/client/src/app/+admin/config/edit-custom-config/edit-advanced-configuration.component.html index 6018ff5e0..0ab80e5a9 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-advanced-configuration.component.html +++ b/client/src/app/+admin/config/edit-custom-config/edit-advanced-configuration.component.html @@ -38,6 +38,20 @@
{{ formErrors.cache.captions.size }}
+ +
+ + +
+ + {getCacheSize('torrents'), plural, =1 {cached torrent} other {cached torrents}} +
+ +
{{ formErrors.cache.torrents.size }}
+
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-advanced-configuration.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-advanced-configuration.component.ts index 934438a50..01ff022c5 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-advanced-configuration.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-advanced-configuration.component.ts @@ -12,7 +12,7 @@ export class EditAdvancedConfigurationComponent { @Input() form: FormGroup @Input() formErrors: any - getCacheSize (type: 'captions' | 'previews') { + getCacheSize (type: 'captions' | 'previews' | 'torrents') { return this.form.value['cache'][type]['size'] } } diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index 2c7a10937..4b35d65fc 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts @@ -105,6 +105,9 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { }, captions: { size: CACHE_CAPTIONS_SIZE_VALIDATOR + }, + torrents: { + size: CACHE_CAPTIONS_SIZE_VALIDATOR } }, signup: { diff --git a/config/test.yaml b/config/test.yaml index ae8011ba5..33c11afc3 100644 --- a/config/test.yaml +++ b/config/test.yaml @@ -61,6 +61,8 @@ cache: size: 1 captions: size: 1 + torrents: + size: 1 signup: enabled: true diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 5c242da04..fb108ca1c 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -395,6 +395,9 @@ function customConfig (): CustomConfig { }, captions: { size: CONFIG.CACHE.VIDEO_CAPTIONS.SIZE + }, + torrents: { + size: CONFIG.CACHE.TORRENTS.SIZE } }, signup: { diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index 49317df28..e37aefc85 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts @@ -1,6 +1,5 @@ -import { copy } from 'fs-extra' import { join } from 'path' -import { logger } from '@server/helpers/logger' + import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' import { processImage } from '../helpers/image-utils' diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 71098ff99..a85883b19 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -25,6 +25,7 @@ const customConfigUpdateValidator = [ body('cache.previews.size').isInt().withMessage('Should have a valid previews cache size'), body('cache.captions.size').isInt().withMessage('Should have a valid captions cache size'), + body('cache.torrents.size').isInt().withMessage('Should have a valid torrents cache size'), body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'), body('signup.limit').isInt().withMessage('Should have a valid signup limit'), diff --git a/server/models/server/tracker.ts b/server/models/server/tracker.ts index d7c91faad..97520f92d 100644 --- a/server/models/server/tracker.ts +++ b/server/models/server/tracker.ts @@ -36,7 +36,7 @@ export class TrackerModel extends Model { const query = { include: [ { - attributes: [ 'id', 'trackerId' ], + attributes: [ 'id' ], model: VideoModel.unscoped(), required: true, where: { id: videoId } diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index c7eb3189b..004aa65b3 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -65,6 +65,9 @@ describe('Test config API validators', function () { }, captions: { size: 3 + }, + torrents: { + size: 4 } }, signup: { diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index b2371614f..0b0f48d22 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -55,6 +55,7 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) { expect(data.cache.previews.size).to.equal(1) expect(data.cache.captions.size).to.equal(1) + expect(data.cache.torrents.size).to.equal(1) expect(data.signup.enabled).to.be.true expect(data.signup.limit).to.equal(4) @@ -144,6 +145,7 @@ function checkUpdatedConfig (data: CustomConfig) { expect(data.cache.previews.size).to.equal(2) expect(data.cache.captions.size).to.equal(3) + expect(data.cache.torrents.size).to.equal(4) expect(data.signup.enabled).to.be.false expect(data.signup.limit).to.equal(5) @@ -305,6 +307,9 @@ describe('Test config', function () { }, captions: { size: 3 + }, + torrents: { + size: 4 } }, signup: { diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts index efe569243..026a5e61c 100644 --- a/shared/extra-utils/server/config.ts +++ b/shared/extra-utils/server/config.ts @@ -90,6 +90,9 @@ function updateCustomSubConfig (url: string, token: string, newConfig: DeepParti }, captions: { size: 3 + }, + torrents: { + size: 4 } }, signup: { diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts index 93b2d3417..0bccd63e3 100644 --- a/shared/models/server/custom-config.model.ts +++ b/shared/models/server/custom-config.model.ts @@ -59,6 +59,10 @@ export interface CustomConfig { captions: { size: number } + + torrents: { + size: number + } } signup: {