From c07fbd5315d15bedfa9fe8b38cf98e5bfc2ee004 Mon Sep 17 00:00:00 2001
From: Dimas <dimasfaid@gmail.com>
Date: Fri, 17 Nov 2023 02:03:14 +0700
Subject: [PATCH] Fix incorrect use of substr and add random id for song

---
 Controller/LaguController.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Controller/LaguController.php b/Controller/LaguController.php
index a803b85..8d1560e 100644
--- a/Controller/LaguController.php
+++ b/Controller/LaguController.php
@@ -270,11 +270,12 @@ class LaguController
         $target_dir = "audio/";
         $file = $formData["file_lagu"]["name"];
 
-        if( substr($formData["file_lagu"]['type'], 5) !== 'audio'){
+        if( substr($formData["file_lagu"]['type'], 0, 5) !== "audio"){
           return $res->view("Pages/AddSong", [
               "auth" => $req->auth,
               "added" => false,
               "failed" => true,
+              "tipe" => substr($formData["file_lagu"]['type'], 5)
           ]);
         }
 
@@ -296,11 +297,12 @@ class LaguController
         $target_dir = "image/";
         $file = $formData["image_file"]["name"];
 
-        if( substr($formData["image_file"]['type'], 5) !== 'image'){
+        if( substr($formData["image_file"]['type'], 0, 5) !== "image"){
           return $res->view("Pages/AddSong", [
               "auth" => $req->auth,
               "added" => false,
               "failed" => true,
+              "tipe" => $formData["image_file"]['type']
           ]);
         }
 
@@ -319,6 +321,7 @@ class LaguController
         try {
             $transaction->insert(
                 [
+                    "song_id" => rand(1,9223372036854775807),
                     "title" => $title,
                     "release_date" => $release_date,
                     "duration" => $duration,
-- 
GitLab