Prechádzať zdrojové kódy

Added checks to make sure thumbnail is square and not too big or small

Kristian Vos 3 rokov pred
rodič
commit
435c5173c4
1 zmenil súbory, kde vykonal 24 pridanie a 0 odobranie
  1. 24 0
      frontend/src/components/modals/EditSong.vue

+ 24 - 0
frontend/src/components/modals/EditSong.vue

@@ -76,6 +76,7 @@
 							class="thumbnail-preview"
 							:src="song.thumbnail"
 							onerror="this.src='/assets/notes-transparent.png'"
+							ref="thumbnailElement"
 							v-if="songDataLoaded"
 						/>
 					</div>
@@ -947,6 +948,29 @@ export default {
 				return new Toast("Please fill in all fields");
 			}
 
+			const thumbnailHeight = this.$refs.thumbnailElement.naturalHeight;
+			const thumbnailWidth = this.$refs.thumbnailElement.naturalWidth;
+			const thumbnailSizeDifference = thumbnailWidth - thumbnailHeight;
+
+			if (thumbnailHeight < 100 || thumbnailWidth < 100) {
+				saveButtonRef.handleFailedSave();
+				return new Toast(
+					"Thumbnail width and height must be at least 100px."
+				);
+			}
+
+			if (thumbnailHeight > 2000 || thumbnailWidth > 2000) {
+				saveButtonRef.handleFailedSave();
+				return new Toast(
+					"Thumbnail width and height must be less than 2000px."
+				);
+			}
+
+			if (thumbnailSizeDifference > 5 || thumbnailSizeDifference < -5) {
+				saveButtonRef.handleFailedSave();
+				return new Toast("Thumbnail is not square.");
+			}
+
 			// Duration
 			if (
 				Number(song.skipDuration) + Number(song.duration) >