Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Support svg logos

Chocobozzzba7c0e67352f
diff --git a/client/src/app/+admin/config/pages/admin-config-logo.component.html b/client/src/app/+admin/config/pages/admin-config-logo.component.html
index da932a4d41..52a11d28f6 100644
--- a/client/src/app/+admin/config/pages/admin-config-logo.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-logo.component.html
@@ -17,7 +17,7 @@
</div>
</div>
- <my-preview-upload class="avatar-preview" formControlName="avatar" inputName="avatar" displayDelete="true"></my-preview-upload>
+ <my-image-input class="avatar-preview" formControlName="avatar" inputName="avatar" displayDelete="true" [fileConstraints]="avatarFileConstraints"></my-image-input>
</div>
<div class="form-group">
@@ -31,7 +31,7 @@
</p>
</div>
- <my-preview-upload class="banner-preview" formControlName="banner" inputName="banner" displayDelete="true"></my-preview-upload>
+ <my-image-input class="banner-preview" formControlName="banner" inputName="banner" displayDelete="true" [fileConstraints]="avatarFileConstraints"></my-image-input>
</div>
<div class="form-group">
@@ -43,17 +43,18 @@
<ng-container i18n>If not set, the <strong>Square icon</strong> will be used.</ng-container>
</p>
- <p i18n>It will be resized to 32x32 pixels and converted to .png format.</p>
+ <p i18n>If the image is not in .svg format, it will be resized to 32x32 pixels and converted to .png format.</p>
</div>
- <my-preview-upload
+ <my-image-input
class="favicon-preview"
formControlName="favicon"
inputName="favicon"
displayDelete="true"
buttonsAside="true"
[previewSize]="{ height: '32px', width: '32px' }"
- ></my-preview-upload>
+ [fileConstraints]="logoFileConstraints"
+ ></my-image-input>
</div>
<div class="form-group">
@@ -65,17 +66,18 @@
<ng-container i18n>If not set, the <strong>Square icon</strong> will be used.</ng-container>
</p>
- <p i18n>Its height will be reduced to 48 pixels and the width will be calculated based on the original file ratio.</p>
+ <p i18n>If the image is not in .svg format, its height will be reduced to 48 pixels and the width will be calculated based on the original file ratio.</p>
</div>
- <my-preview-upload
+ <my-image-input
class="header-wide-preview"
formControlName="header-wide"
inputName="header-wide"
displayDelete="true"
buttonsAside="true"
[previewSize]="{ height: '48px', width: 'auto' }"
- ></my-preview-upload>
+ [fileConstraints]="logoFileConstraints"
+ ></my-image-input>
</div>
<div class="form-group">
@@ -100,17 +102,18 @@
<ng-container i18n>If not set, the <strong>Square icon</strong> will be used.</ng-container>
</p>
- <p i18n>It will be resized to 48x48 pixels.</p>
+ <p i18n>If the image is not in .svg format, it will be resized to 48x48 pixels.</p>
</div>
- <my-preview-upload
+ <my-image-input
class="header-square-preview"
formControlName="header-square"
inputName="header-square"
displayDelete="true"
buttonsAside="true"
[previewSize]="{ height: '48px', width: '48px' }"
- ></my-preview-upload>
+ [fileConstraints]="logoFileConstraints"
+ ></my-image-input>
</div>
<div class="form-group">
@@ -122,10 +125,10 @@
<ng-container i18n>If not set, the <strong>Square icon</strong> will be used.</ng-container>
</p>
- <p i18n>It will be resized to 1200x650 pixels.</p>
+ <p i18n>If the image is not in .svg format, it will be resized to 1200x650 pixels.</p>
</div>
- <my-preview-upload class="opengraph-preview" formControlName="opengraph" inputName="opengraph" displayDelete="true"></my-preview-upload>
+ <my-image-input class="opengraph-preview" formControlName="opengraph" inputName="opengraph" displayDelete="true" [fileConstraints]="logoFileConstraints"></my-image-input>
</div>
</div>
</div>
diff --git a/client/src/app/+admin/config/pages/admin-config-logo.component.ts b/client/src/app/+admin/config/pages/admin-config-logo.component.ts
index ee54f966ca..8e92caa250 100644
--- a/client/src/app/+admin/config/pages/admin-config-logo.component.ts
+++ b/client/src/app/+admin/config/pages/admin-config-logo.component.ts
@@ -12,7 +12,7 @@ import { PeertubeCheckboxComponent } from '@app/shared/shared-forms/peertube-che
import { CustomConfig, LogoType } from '@peertube/peertube-models'
import { of, Subscription, switchMap, tap } from 'rxjs'
import { AdminConfigService } from '../../../shared/shared-admin/admin-config.service'
-import { PreviewUploadComponent } from '../../../shared/shared-forms/preview-upload.component'
+import { ImageInputComponent } from '../../../shared/shared-forms/image-input.component'
import { InstanceLogoService } from '../../../shared/shared-instance/instance-logo.service'
import { AdminSaveBarComponent } from '../shared/admin-save-bar.component'
@@ -35,7 +35,7 @@ type Form = {
FormsModule,
ReactiveFormsModule,
AdminSaveBarComponent,
- PreviewUploadComponent,
+ ImageInputComponent,
PeertubeCheckboxComponent
]
})
@@ -59,6 +59,14 @@ export class AdminConfigLogoComponent implements OnInit, OnDestroy, CanComponent
return this.server.getHTMLConfig().instance.name
}
+ get avatarFileConstraints () {
+ return this.server.getHTMLConfig().avatar.file
+ }
+
+ get logoFileConstraints () {
+ return this.server.getHTMLConfig().logo.file
+ }
+
ngOnInit () {
this.customConfig = this.route.parent.snapshot.data['customConfig']
diff --git a/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts b/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
index 9a5dd45b91..ea3acce8f3 100644
--- a/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
+++ b/client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
@@ -18,7 +18,7 @@ import { VideoPlaylistService } from '@app/shared/shared-video-playlist/video-pl
import { VideoPlaylistCreate, VideoPlaylistPrivacy } from '@peertube/peertube-models'
import { of, switchMap } from 'rxjs'
import { MarkdownTextareaComponent } from '../../shared/shared-forms/markdown-textarea.component'
-import { PreviewUploadComponent } from '../../shared/shared-forms/preview-upload.component'
+import { ImageInputComponent } from '../../shared/shared-forms/image-input.component'
import { SelectChannelComponent } from '../../shared/shared-forms/select/select-channel.component'
import { SelectOptionsComponent } from '../../shared/shared-forms/select/select-options.component'
import { HelpComponent } from '../../shared/shared-main/buttons/help.component'
@@ -32,7 +32,7 @@ import { MyVideoPlaylistEdit } from './my-video-playlist-edit'
RouterLink,
FormsModule,
ReactiveFormsModule,
- PreviewUploadComponent,
+ ImageInputComponent,
NgClass,
HelpComponent,
MarkdownTextareaComponent,
diff --git a/client/src/app/+my-library/my-video-playlists/my-video-playlist-edit.component.html b/client/src/app/+my-library/my-video-playlists/my-video-playlist-edit.component.html
index 2668e8f04a..7640a277ee 100644
--- a/client/src/app/+my-library/my-video-playlists/my-video-playlist-edit.component.html
+++ b/client/src/app/+my-library/my-video-playlists/my-video-playlist-edit.component.html
@@ -39,7 +39,7 @@
<div class="form-group">
<label for="thumbnailfile" i18n>Playlist thumbnail</label>
- <my-preview-upload i18n-inputLabel inputLabel="Edit" inputName="thumbnailfile" formControlName="thumbnailfile"></my-preview-upload>
+ <my-image-input i18n-inputLabel inputLabel="Edit" inputName="thumbnailfile" formControlName="thumbnailfile"></my-image-input>
</div>
<div class="form-group">
diff --git a/client/src/app/+my-library/my-video-playlists/my-video-playlist-edit.component.scss b/client/src/app/+my-library/my-video-playlists/my-video-playlist-edit.component.scss
index e48e2b61de..fead6d31ec 100644
--- a/client/src/app/+my-library/my-video-playlists/my-video-playlist-edit.component.scss
+++ b/client/src/app/+my-library/my-video-playlists/my-video-playlist-edit.component.scss
@@ -20,7 +20,7 @@ my-select-options {
max-width: 500px;
}
-my-preview-upload {
+my-image-input {
width: 223px;
height: 122px;
}
diff --git a/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts b/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts
index 0319741f48..3321303428 100644
--- a/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts
+++ b/client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts
@@ -19,7 +19,7 @@ import { VideoPlaylistUpdate } from '@peertube/peertube-models'
import { forkJoin, Subscription } from 'rxjs'
import { map, switchMap } from 'rxjs/operators'
import { MarkdownTextareaComponent } from '../../shared/shared-forms/markdown-textarea.component'
-import { PreviewUploadComponent } from '../../shared/shared-forms/preview-upload.component'
+import { ImageInputComponent } from '../../shared/shared-forms/image-input.component'
import { SelectChannelComponent } from '../../shared/shared-forms/select/select-channel.component'
import { SelectOptionsComponent } from '../../shared/shared-forms/select/select-options.component'
import { HelpComponent } from '../../shared/shared-main/buttons/help.component'
@@ -33,7 +33,7 @@ import { MyVideoPlaylistEdit } from './my-video-playlist-edit'
RouterLink,
FormsModule,
ReactiveFormsModule,
- PreviewUploadComponent,
+ ImageInputComponent,
NgClass,
HelpComponent,
MarkdownTextareaComponent,
diff --git a/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.html b/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.html
index 374735dd88..072a399420 100644
--- a/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.html
+++ b/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.html
@@ -29,7 +29,7 @@
<br />
The chosen image will be definitive and cannot be modified.
</div>
- <my-preview-upload i18n-inputLabel inputLabel="Edit" inputName="previewfileUpload" [(ngModel)]="audioPreviewFile"></my-preview-upload>
+ <my-image-input i18n-inputLabel inputLabel="Edit" inputName="previewfileUpload" [(ngModel)]="audioPreviewFile"></my-image-input>
</div>
<div class="form-group upload-audio-button">
<my-button theme="primary" [label]="getAudioUploadLabel()" icon="upload" (click)="uploadAudio()"></my-button>
diff --git a/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.scss b/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.scss
index 9e888e79ef..645d292204 100644
--- a/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.scss
+++ b/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.scss
@@ -14,7 +14,7 @@
.audio-preview {
margin: 30px 0;
- my-preview-upload {
+ my-image-input {
width: 360px;
height: 200px;
}
diff --git a/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.ts b/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.ts
index 89a484e638..61dcbe7ddb 100644
--- a/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.ts
+++ b/client/src/app/+videos-publish-manage/+video-publish/upload/video-upload.component.ts
@@ -1,4 +1,3 @@
-
import { AfterViewInit, Component, ElementRef, OnDestroy, OnInit, inject, input, output, viewChild } from '@angular/core'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { ActivatedRoute } from '@angular/router'
@@ -12,7 +11,7 @@ import debug from 'debug'
import { truncate } from 'lodash-es'
import { Subscription } from 'rxjs'
import { SelectChannelItem } from 'src/types'
-import { PreviewUploadComponent } from '../../../shared/shared-forms/preview-upload.component'
+import { ImageInputComponent } from '../../../shared/shared-forms/image-input.component'
import { SelectChannelComponent } from '../../../shared/shared-forms/select/select-channel.component'
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
import { ButtonComponent } from '../../../shared/shared-main/buttons/button.component'
@@ -34,11 +33,11 @@ const debugLogger = debug('peertube:video-publish')
NgbTooltip,
SelectChannelComponent,
FormsModule,
- PreviewUploadComponent,
+ ImageInputComponent,
ButtonComponent,
ReactiveFormsModule,
VideoManageContainerComponent
-]
+ ]
})
export class VideoUploadComponent implements OnInit, OnDestroy, AfterViewInit, CanComponentDeactivate {
private notifier = inject(Notifier)
diff --git a/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-edit-info.component.html b/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-edit-info.component.html
index a62adf0729..0a75e0e37c 100644
--- a/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-edit-info.component.html
+++ b/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-edit-info.component.html
@@ -41,7 +41,7 @@
<label i18n for="avatarfile">Platform icon</label>
<div class="form-group-description" i18n>Used in various places such as on the website, mobile application and social media</div>
- <my-preview-upload class="avatar-preview" formControlName="avatar" inputName="avatar" displayDelete="true"></my-preview-upload>
+ <my-image-input class="avatar-preview" formControlName="avatar" inputName="avatar" displayDelete="true" [fileConstraints]="avatarFileConstraints"></my-image-input>
</div>
<div class="form-group">
diff --git a/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-edit-info.component.ts b/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-edit-info.component.ts
index dee1085f8e..be5165a969 100644
--- a/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-edit-info.component.ts
+++ b/client/src/app/modal/admin-config-wizard/steps/admin-config-wizard-edit-info.component.ts
@@ -13,7 +13,7 @@ import {
} from '@app/shared/form-validators/form-validator.model'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { PeertubeColorPickerComponent } from '@app/shared/shared-forms/peertube-color-picker.component'
-import { PreviewUploadComponent } from '@app/shared/shared-forms/preview-upload.component'
+import { ImageInputComponent } from '@app/shared/shared-forms/image-input.component'
import { ButtonComponent } from '../../../shared/shared-main/buttons/button.component'
import { findAppropriateImage } from '@peertube/peertube-core-utils'
import { logger } from '@root-helpers/logger'
@@ -38,7 +38,7 @@ export type FormEditInfo = FormDefaultTyped<Form>
PeertubeColorPickerComponent,
CdkStepperModule,
ButtonComponent,
- PreviewUploadComponent
+ ImageInputComponent
]
})
export class AdminConfigWizardEditInfoComponent implements OnInit {
@@ -72,6 +72,10 @@ export class AdminConfigWizardEditInfoComponent implements OnInit {
}
}
+ get avatarFileConstraints () {
+ return this.server.getHTMLConfig().avatar.file
+ }
+
private buildForm () {
const obj: BuildFormArgumentTyped<Form> = {
platformName: INSTANCE_NAME_VALIDATOR,
diff --git a/client/src/app/shared/shared-forms/preview-upload.component.html b/client/src/app/shared/shared-forms/image-input.component.html
similarity index 90%
rename from client/src/app/shared/shared-forms/preview-upload.component.html
rename to client/src/app/shared/shared-forms/image-input.component.html
index 2660534589..37f7142c83 100644
--- a/client/src/app/shared/shared-forms/preview-upload.component.html
+++ b/client/src/app/shared/shared-forms/image-input.component.html
@@ -11,8 +11,8 @@
[(ngModel)]="file"
[inputName]="inputName()"
[inputLabel]="inputLabel()"
- [extensions]="videoImageExtensions"
- [maxFileSize]="maxVideoImageSize"
+ [extensions]="imageExtensions"
+ [maxFileSize]="maxImageSize"
placement="right"
icon="upload"
(fileChanged)="onFileChanged($event)"
diff --git a/client/src/app/shared/shared-forms/preview-upload.component.scss b/client/src/app/shared/shared-forms/image-input.component.scss
similarity index 100%
rename from client/src/app/shared/shared-forms/preview-upload.component.scss
rename to client/src/app/shared/shared-forms/image-input.component.scss
diff --git a/client/src/app/shared/shared-forms/preview-upload.component.ts b/client/src/app/shared/shared-forms/image-input.component.ts
similarity index 67%
rename from client/src/app/shared/shared-forms/preview-upload.component.ts
rename to client/src/app/shared/shared-forms/image-input.component.ts
index 2cfcf1fc62..b5a8c0e4c1 100644
--- a/client/src/app/shared/shared-forms/preview-upload.component.ts
+++ b/client/src/app/shared/shared-forms/image-input.component.ts
@@ -2,39 +2,44 @@ import { CommonModule } from '@angular/common'
import { booleanAttribute, Component, forwardRef, inject, input, OnInit } from '@angular/core'
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms'
import { ServerService } from '@app/core'
-import { HTMLServerConfig } from '@peertube/peertube-models'
+import { FileConstraints, HTMLServerConfig } from '@peertube/peertube-models'
import { imageToDataURL } from '@root-helpers/images'
+import { DeleteButtonComponent } from '../shared-main/buttons/delete-button.component'
import { BytesPipe } from '../shared-main/common/bytes.pipe'
import { ReactiveFileComponent } from './reactive-file.component'
-import { DeleteButtonComponent } from '../shared-main/buttons/delete-button.component'
@Component({
- selector: 'my-preview-upload',
- styleUrls: [ './preview-upload.component.scss' ],
- templateUrl: './preview-upload.component.html',
+ selector: 'my-image-input',
+ styleUrls: [ './image-input.component.scss' ],
+ templateUrl: './image-input.component.html',
providers: [
{
provide: NG_VALUE_ACCESSOR,
- useExisting: forwardRef(() => PreviewUploadComponent),
+ useExisting: forwardRef(() => ImageInputComponent),
multi: true
}
],
imports: [ CommonModule, FormsModule, ReactiveFileComponent, DeleteButtonComponent ]
})
-export class PreviewUploadComponent implements OnInit, ControlValueAccessor {
+export class ImageInputComponent implements OnInit, ControlValueAccessor {
private serverService = inject(ServerService)
readonly inputName = input.required<string>()
- readonly inputLabel = input<string>(undefined)
+ readonly inputLabel = input<string>()
readonly displayDelete = input(false, { transform: booleanAttribute })
readonly buttonsAside = input(false, { transform: booleanAttribute })
- readonly previewSize = input<{ width: string, height: string }>(undefined)
+ readonly previewSize = input<{ width: string, height: string }>()
+ readonly fileConstraints = input<FileConstraints>()
imageSrc: string
- allowedExtensionsMessage = ''
maxSizeText: string
file: Blob
+ imageExtensions: string[] = []
+ maxImageSize: number
+ maxImageSizeInBytes: string | number
+ allowedExtensionsMessage = ''
+
private serverConfig: HTMLServerConfig
private bytesPipe: BytesPipe
@@ -43,26 +48,20 @@ export class PreviewUploadComponent implements OnInit, ControlValueAccessor {
this.maxSizeText = $localize`max size`
}
- get videoImageExtensions () {
- return this.serverConfig.video.image.extensions
- }
-
- get maxVideoImageSize () {
- return this.serverConfig.video.image.size.max
- }
-
- get maxVideoImageSizeInBytes () {
- return this.bytesPipe.transform(this.maxVideoImageSize)
- }
-
getReactiveFileButtonTooltip () {
- return $localize`(extensions: ${this.videoImageExtensions}, ${this.maxSizeText}\: ${this.maxVideoImageSizeInBytes})`
+ return $localize`(extensions: ${this.imageExtensions.join(', ')}, max size\: ${this.maxImageSizeInBytes})`
}
ngOnInit () {
this.serverConfig = this.serverService.getHTMLConfig()
- this.allowedExtensionsMessage = this.videoImageExtensions.join(', ')
+ const fileContraints = this.fileConstraints() ?? this.serverConfig.video.image
+
+ this.imageExtensions = fileContraints.extensions
+ this.maxImageSize = fileContraints.size.max
+ this.maxImageSizeInBytes = this.bytesPipe.transform(this.maxImageSize)
+
+ this.allowedExtensionsMessage = this.imageExtensions.join(', ')
}
onFileChanged (file: Blob) {
diff --git a/client/src/app/shared/shared-forms/reactive-file.component.ts b/client/src/app/shared/shared-forms/reactive-file.component.ts
index 3a2a582b2f..359293c4b6 100644
--- a/client/src/app/shared/shared-forms/reactive-file.component.ts
+++ b/client/src/app/shared/shared-forms/reactive-file.component.ts
@@ -76,7 +76,7 @@ export class ReactiveFileComponent implements OnInit, OnChanges, ControlValueAcc
const extension = '.' + file.name.split('.').pop()
if (this.extensions().includes(extension.toLowerCase()) === false) {
- const message = $localize`PeerTube cannot handle this kind of file. Accepted extensions are ${this.allowedExtensionsMessage}.`
+ const message = $localize`This input cannot handle this kind of file. Accepted extensions are ${this.allowedExtensionsMessage}.`
this.notifier.error(message)
return
diff --git a/packages/models/src/server/server-config.model.ts b/packages/models/src/server/server-config.model.ts
index bbac0c69be..c24d7520d4 100644
--- a/packages/models/src/server/server-config.model.ts
+++ b/packages/models/src/server/server-config.model.ts
@@ -32,6 +32,13 @@ export interface RegisteredIdAndPassAuthConfig {
weight: number
}
+export interface FileConstraints {
+ size: {
+ max: number
+ }
+ extensions: string[]
+}
+
export interface ServerConfig {
serverVersion: string
serverCommit?: string
@@ -314,42 +321,26 @@ export interface ServerConfig {
}
avatar: {
- file: {
- size: {
- max: number
- }
- extensions: string[]
- }
+ file: FileConstraints
}
banner: {
- file: {
- size: {
- max: number
- }
- extensions: string[]
- }
+ file: FileConstraints
+ }
+
+ logo: {
+ file: FileConstraints
}
video: {
- image: {
- size: {
- max: number
- }
- extensions: string[]
- }
+ image: FileConstraints
file: {
extensions: string[]
}
}
videoCaption: {
- file: {
- size: {
- max: number
- }
- extensions: string[]
- }
+ file: FileConstraints
}
user: {
diff --git a/packages/tests/fixtures/peertube.svg b/packages/tests/fixtures/peertube.svg
new file mode 100644
index 0000000000..0e6e228e61
--- /dev/null
+++ b/packages/tests/fixtures/peertube.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg height="682.68799" viewBox="2799 -911 512 682.688" width="512" xmlns="http://www.w3.org/2000/svg"><g stroke-width="32"><path d="m2799-911v341.344l256-170.656" fill="#211f20"/><path d="m2799-569.656v341.344l256-170.656" fill="#737373"/><path d="m3055-740.344v341.344l256-170.656" fill="#f1680d"/></g></svg>
\ No newline at end of file
diff --git a/packages/tests/src/api/check-params/config.ts b/packages/tests/src/api/check-params/config.ts
index ae014f5a20..acb05fc36b 100644
--- a/packages/tests/src/api/check-params/config.ts
+++ b/packages/tests/src/api/check-params/config.ts
@@ -243,7 +243,7 @@ describe('Test config API validators', function () {
expect(response.body.detail).to.equal(
'Browse videos default sort should be -publishedAt or -originallyPublishedAt ' +
- 'or name or -trending or -hot or -likes or -views, instead of hello'
+ 'or name or -trending or -hot or -likes or -views, instead of hello'
)
})
@@ -273,7 +273,7 @@ describe('Test config API validators', function () {
expect(response.body.detail).to.equal(
'Trending videos algorithm most-viewed should be enabled ' +
- 'if browse videos default sort is -trending'
+ 'if browse videos default sort is -trending'
)
})
@@ -322,12 +322,12 @@ describe('Test config API validators', function () {
describe('Updating instance image/logo', function () {
const toTest = [
- { path: '/api/v1/config/instance-banner/pick', attachName: 'bannerfile' },
- { path: '/api/v1/config/instance-avatar/pick', attachName: 'avatarfile' },
- { path: '/api/v1/config/instance-logo/favicon/pick', attachName: 'logofile' },
- { path: '/api/v1/config/instance-logo/header-square/pick', attachName: 'logofile' },
- { path: '/api/v1/config/instance-logo/header-wide/pick', attachName: 'logofile' },
- { path: '/api/v1/config/instance-logo/opengraph/pick', attachName: 'logofile' }
+ { path: '/api/v1/config/instance-banner/pick', attachName: 'bannerfile', supportSVG: false },
+ { path: '/api/v1/config/instance-avatar/pick', attachName: 'avatarfile', supportSVG: false },
+ { path: '/api/v1/config/instance-logo/favicon/pick', attachName: 'logofile', supportSVG: true },
+ { path: '/api/v1/config/instance-logo/header-square/pick', attachName: 'logofile', supportSVG: true },
+ { path: '/api/v1/config/instance-logo/header-wide/pick', attachName: 'logofile', supportSVG: true },
+ { path: '/api/v1/config/instance-logo/opengraph/pick', attachName: 'logofile', supportSVG: true }
]
it('Should fail with an incorrect input file', async function () {
@@ -396,6 +396,23 @@ describe('Test config API validators', function () {
})
}
})
+
+ it('Should succeed with SVG logo on some endpoints', async function () {
+ for (const { attachName, path, supportSVG } of toTest) {
+ const attaches = { [attachName]: buildAbsoluteFixturePath('peertube.svg') }
+
+ await makeUploadRequest({
+ url: server.url,
+ path,
+ token: server.accessToken,
+ fields: {},
+ attaches,
+ expectedStatus: supportSVG
+ ? HttpStatusCode.NO_CONTENT_204
+ : HttpStatusCode.BAD_REQUEST_400
+ })
+ }
+ })
})
describe('Deleting instance image', function () {
diff --git a/packages/tests/src/api/server/config.ts b/packages/tests/src/api/server/config.ts
index 276fb57424..0e077948ae 100644
--- a/packages/tests/src/api/server/config.ts
+++ b/packages/tests/src/api/server/config.ts
@@ -971,6 +971,26 @@ describe('Test config', function () {
await server.config.deleteInstanceImage({ type: ActorImageType.AVATAR })
})
})
+
+ describe('SVG logos', async function () {
+ it('Should upload SVG on compatible endpoints', async function () {
+ for (const type of [ 'favicon', 'header-wide', 'header-square', 'opengraph' ] as LogoType[]) {
+ await server.config.updateInstanceLogo({ type, fixture: 'peertube.svg' })
+
+ const htmlConfig = await server.config.getConfig()
+
+ const logos = htmlConfig.instance.logo.filter(l => l.type === type)
+ expect(logos).to.have.lengthOf(1)
+ expect(logos[0].width).to.be.null
+ expect(logos[0].height).to.be.null
+ expect(logos[0].isFallback).to.be.false
+ expect(logos[0].type).to.equal(type)
+
+ await makeRawRequest({ url: logos[0].fileUrl, expectedStatus: HttpStatusCode.OK_200 })
+ await testFileExistsOnFSOrNot(server, 'uploads/images', basename(logos[0].fileUrl), true)
+ }
+ })
+ })
})
})
diff --git a/server/core/controllers/api/config.ts b/server/core/controllers/api/config.ts
index dd67a96f95..91bf9466d9 100644
--- a/server/core/controllers/api/config.ts
+++ b/server/core/controllers/api/config.ts
@@ -109,7 +109,7 @@ configRouter.delete(
configRouter.post(
'/instance-logo/:logoType/pick',
authenticate,
- createReqFiles([ 'logofile' ], MIMETYPES.IMAGE.MIMETYPE_EXT),
+ createReqFiles([ 'logofile' ], MIMETYPES.LOGO_IMAGE.MIMETYPE_EXT),
ensureUserHasRight(UserRight.MANAGE_CONFIGURATION),
updateOrDeleteLogoValidator,
updateInstanceLogoValidator,
diff --git a/server/core/helpers/custom-validators/config.ts b/server/core/helpers/custom-validators/config.ts
index 5ae1ee7055..76d82da6e6 100644
--- a/server/core/helpers/custom-validators/config.ts
+++ b/server/core/helpers/custom-validators/config.ts
@@ -1,7 +1,23 @@
import { LogoType } from '@peertube/peertube-models'
+import { CONSTRAINTS_FIELDS, MIMETYPES } from '@server/initializers/constants.js'
+import { UploadFilesForCheck } from 'express'
+import { isFileValid } from './misc.js'
const logoTypes = new Set<LogoType>([ 'favicon', 'header-square', 'header-wide', 'opengraph' ])
export function isConfigLogoTypeValid (value: LogoType) {
return logoTypes.has(value)
}
+
+const imageMimeTypesRegex = Object.keys(MIMETYPES.LOGO_IMAGE.MIMETYPE_EXT)
+ .map(mimeType => `(${mimeType.replace('+', '\\+')})`)
+ .join('|')
+
+export function isLogoImageFile (files: UploadFilesForCheck, fieldname: string) {
+ return isFileValid({
+ files,
+ mimeTypeRegex: imageMimeTypesRegex,
+ field: fieldname,
+ maxSize: CONSTRAINTS_FIELDS.LOGO.IMAGE.FILE_SIZE.max
+ })
+}
diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.ts
index d453826a06..cb040de5f2 100644
--- a/server/core/initializers/constants.ts
+++ b/server/core/initializers/constants.ts
@@ -304,7 +304,8 @@ export const REPEAT_JOBS: { [id in JobType]?: RepeatOptions } = {
}
export const JOB_PRIORITY = {
STORYBOARD: 95,
- TRANSCODING: 100,
+ REQUIRED_TRANSCODING: 100,
+ OPTIONAL_TRANSCODING: 10000,
VIDEO_STUDIO: 150,
TRANSCRIPTION: 200
}
@@ -482,6 +483,14 @@ export const CONSTRAINTS_FIELDS = {
}
}
},
+ LOGO: {
+ IMAGE: {
+ EXTNAME: [ '.svg', '.png', '.jpeg', '.jpg', '.gif', '.webp' ],
+ FILE_SIZE: {
+ max: 8 * 1024 * 1024 // 8MB
+ }
+ }
+ },
VIDEO_EVENTS: {
COUNT: { min: 0 }
},
@@ -773,6 +782,10 @@ export const MIMETYPES = {
},
EXT_MIMETYPE: null as { [id: string]: string }
},
+ LOGO_IMAGE: {
+ MIMETYPE_EXT: null as { [id: string]: string },
+ EXT_MIMETYPE: null as { [id: string]: string }
+ },
VIDEO_CAPTIONS: {
MIMETYPE_EXT: {
'text/vtt': '.vtt',
@@ -811,8 +824,15 @@ export const MIMETYPES = {
}
}
+MIMETYPES.LOGO_IMAGE.MIMETYPE_EXT = {
+ ...MIMETYPES.IMAGE.MIMETYPE_EXT,
+
+ 'image/svg+xml': '.svg'
+}
+
MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT)
MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT)
+MIMETYPES.LOGO_IMAGE.EXT_MIMETYPE = invert(MIMETYPES.LOGO_IMAGE.MIMETYPE_EXT)
MIMETYPES.VIDEO_CAPTIONS.EXT_MIMETYPE = invert(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT)
export const BINARY_CONTENT_TYPES = new Set([
@@ -1297,6 +1317,7 @@ if (process.env.PRODUCTION_CONSTANTS !== 'true') {
ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB
+ CONSTRAINTS_FIELDS.LOGO.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB
CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB
VIEW_LIFETIME.VIEWER_COUNTER = 1000 * 5 // 5 second
diff --git a/server/core/lib/server-config-manager.ts b/server/core/lib/server-config-manager.ts
index 0dddb1eee7..0cf7ce0690 100644
--- a/server/core/lib/server-config-manager.ts
+++ b/server/core/lib/server-config-manager.ts
@@ -310,6 +310,14 @@ class ServerConfigManager {
extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME
}
},
+ logo: {
+ file: {
+ size: {
+ max: CONSTRAINTS_FIELDS.LOGO.IMAGE.FILE_SIZE.max
+ },
+ extensions: CONSTRAINTS_FIELDS.LOGO.IMAGE.EXTNAME
+ }
+ },
video: {
image: {
extensions: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME,
diff --git a/server/core/lib/upload-image.ts b/server/core/lib/upload-image.ts
index b5bf0fad56..2ac5d5214a 100644
--- a/server/core/lib/upload-image.ts
+++ b/server/core/lib/upload-image.ts
@@ -2,7 +2,7 @@ import { LogoType, UploadImageType, UploadImageType_Type } from '@peertube/peert
import { buildUUID, getLowercaseExtension } from '@peertube/peertube-node-utils'
import { buildImageSize } from '@server/helpers/image-utils.js'
import { UploadImageModel } from '@server/models/application/upload-image.js'
-import { remove } from 'fs-extra/esm'
+import { copy, remove } from 'fs-extra/esm'
import { retryTransactionWrapper } from '../helpers/database-utils.js'
import { UPLOAD_IMAGES_SIZE } from '../initializers/constants.js'
import { sequelizeTypescript } from '../initializers/database.js'
@@ -16,19 +16,7 @@ export async function replaceUploadImage (options: {
}) {
const { actor, imagePhysicalFile, type } = options
- const processImageSize = async (imageSizeArg: { width: number, height: number }) => {
- const imageSize = await buildImageSize(imagePhysicalFile.path, imageSizeArg)
-
- const extension = getLowercaseExtension(imagePhysicalFile.path)
- const imageName = buildUUID() + extension
- const destination = UploadImageModel.getPathOf(imageName)
-
- await processImageFromWorker({ path: imagePhysicalFile.path, destination, newSize: imageSize, keepOriginal: true })
-
- return { imageName, imageSize }
- }
-
- const processedImages = await Promise.all(UPLOAD_IMAGES_SIZE[type].map(processImageSize))
+ const processedImages = await generateImageSizes(imagePhysicalFile.path, type)
await remove(imagePhysicalFile.path)
return retryTransactionWrapper(() =>
@@ -57,6 +45,40 @@ export async function replaceUploadImage (options: {
)
}
+async function generateImageSizes (imagePath: string, type: UploadImageType_Type) {
+ if (imagePath.endsWith('.svg')) {
+ const extension = getLowercaseExtension(imagePath)
+ const imageName = buildUUID() + extension
+ const destination = UploadImageModel.getPathOf(imageName)
+
+ await copy(imagePath, destination)
+
+ return [ { imageName, imageSize: { width: null, height: null } } ]
+ }
+
+ return Promise.all(UPLOAD_IMAGES_SIZE[type].map(size => generateImageSize({ ...size, imagePath })))
+}
+
+async function generateImageSize (options: {
+ imagePath: string
+ width: number
+ height: number
+}) {
+ const { imagePath, width, height } = options
+
+ const imageSize = await buildImageSize(imagePath, { width, height })
+
+ const extension = getLowercaseExtension(imagePath)
+ const imageName = buildUUID() + extension
+ const destination = UploadImageModel.getPathOf(imageName)
+
+ await processImageFromWorker({ path: imagePath, destination, newSize: imageSize, keepOriginal: true })
+
+ return { imageName, imageSize }
+}
+
+// ---------------------------------------------------------------------------
+
export async function deleteUploadImages (options: {
actor: MActorUploadImages
type: UploadImageType_Type
diff --git a/server/core/middlewares/validators/config.ts b/server/core/middlewares/validators/config.ts
index 40f1f7f252..23df71f6fd 100644
--- a/server/core/middlewares/validators/config.ts
+++ b/server/core/middlewares/validators/config.ts
@@ -1,18 +1,20 @@
import { CustomConfig, HttpStatusCode } from '@peertube/peertube-models'
-import { isConfigLogoTypeValid } from '@server/helpers/custom-validators/config.js'
+import { isConfigLogoTypeValid, isLogoImageFile } from '@server/helpers/custom-validators/config.js'
import { isIntOrNull } from '@server/helpers/custom-validators/misc.js'
import { isPlayerThemeValid } from '@server/helpers/custom-validators/player-settings.js'
import { isNumberArray, isStringArray } from '@server/helpers/custom-validators/search.js'
import { isVideoCommentsPolicyValid, isVideoLicenceValid, isVideoPrivacyValid } from '@server/helpers/custom-validators/videos.js'
+import { cleanUpReqFiles } from '@server/helpers/express-utils.js'
import { guessLanguageFromReq } from '@server/helpers/i18n.js'
import { CONFIG, isEmailEnabled } from '@server/initializers/config.js'
+import { CONSTRAINTS_FIELDS } from '@server/initializers/constants.js'
import express from 'express'
import { body, param } from 'express-validator'
import { getBrowseVideosDefaultScopeError, getBrowseVideosDefaultSortError } from '../../helpers/custom-validators/browse-videos.js'
import { isThemeNameValid } from '../../helpers/custom-validators/plugins.js'
import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users.js'
import { isThemeRegistered } from '../../lib/plugins/theme-utils.js'
-import { areValidationErrors, updateActorImageValidatorFactory } from './shared/index.js'
+import { areValidationErrors } from './shared/index.js'
export const customConfigUpdateValidator = [
body('instance.name').exists(),
@@ -192,7 +194,18 @@ export const updateOrDeleteLogoValidator = [
}
]
-export const updateInstanceLogoValidator = updateActorImageValidatorFactory('logofile')
+export const updateInstanceLogoValidator = [
+ body('logofile').custom((value, { req }) => isLogoImageFile(req.files, 'logofile')).withMessage(
+ 'This file is not supported or too large. Please, make sure it is of the following type : ' +
+ CONSTRAINTS_FIELDS.LOGO.IMAGE.EXTNAME.join(', ')
+ ),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
+
+ return next()
+ }
+]
// ---------------------------------------------------------------------------
// Private