Selaa lähdekoodia

修改API上傳工具 加入預覽圖及影片

manto07m 3 vuotta sitten
vanhempi
commit
4249c8e92c

+ 6 - 5
api-detail.php

@@ -32,9 +32,10 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 		var right = <?php echo ($right); ?>;
 		var webLink;
 		var source;
-		var searchURL = window.location.search;
-		searchURL = searchURL.substring(1, searchURL.length);
-		object = decodeURIComponent(searchURL.split("&")[0].split("=")[1]);
+		var url_href = window.location.href;
+		var url = new URL(url_href);
+		var object = (url.searchParams.get("object") == undefined ? "" : url.searchParams.get("object"));
+
 		if (object == 'undefined') {
 			window.location.href = "./api-list.php";
 		}
@@ -85,7 +86,7 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 </head>
 
 <body>
-	
+
 	<section class="body">
 		<!-- start: header -->
 		<header-menu></header-menu>
@@ -206,7 +207,7 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 		const hidden = ["png"];
 		if (webLink == null || webLink == '空') {
 			$("#webLink").append("<span>" + source + "</span>");
-		}else{
+		} else {
 			$("#webLink").append("<a href='" + webLink + "' target='_blank'>" + source + "</a>");
 		}
 

+ 3 - 6
api-list.php

@@ -20,12 +20,9 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 		var userName = "<?php echo $_SESSION['name'] ?>";
 		var role = "<?php echo ($groupName); ?>";
 		var right = <?php echo ($right); ?>;
-		var searchURL = window.location.search;
-		searchURL = searchURL.substring(1, searchURL.length);
-		type = searchURL.split("&")[0].split("=")[1];
-		if (type === undefined) {
-			//window.location.href = "?type=other";
-		}
+		var url_href = window.location.href;
+		var url = new URL(url_href);
+		var type = (url.searchParams.get("type") == undefined ? "all" : url.searchParams.get("type"));
 		var $grid;
 		var list;
 

+ 49 - 9
api-upload.php

@@ -186,6 +186,44 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 												</div>
 											</div>
 										</div>
+										<div class="row">
+											<div class="col-sm-6">
+												<div class="form-group">
+													<label class="control-label">上傳API預覽圖</label>
+													<div class="fileupload fileupload-new" data-provides="fileupload">
+														<div class="input-append">
+															<div class="uneditable-input">
+																<span id="fileCount" class="fileupload-preview"></span>
+															</div>
+															<span class="btn btn-default btn-file">
+																<span class="fileupload-exists">更換檔案</span>
+																<span class="fileupload-new">選擇檔案</span>
+																<input type="file" id="thumbnail" accept="image/png, image/gif, image/jpeg">
+															</span>
+															<a href="#" class="btn btn-default fileupload-exists" data-dismiss="fileupload">移除檔案</a>
+														</div>
+													</div>
+												</div>
+											</div>
+											<div class="col-sm-6">
+												<div class="form-group">
+													<label class="control-label">上傳API操作影片</label>
+													<div class="fileupload fileupload-new" data-provides="fileupload">
+														<div class="input-append">
+															<div class="uneditable-input">
+																<span id="fileCount" class="fileupload-preview"></span>
+															</div>
+															<span class="btn btn-default btn-file">
+																<span class="fileupload-exists">更換檔案</span>
+																<span class="fileupload-new">選擇檔案</span>
+																<input type="file" id="video" accept=".mp4,.avi">
+															</span>
+															<a href="#" class="btn btn-default fileupload-exists" data-dismiss="fileupload">移除檔案</a>
+														</div>
+													</div>
+												</div>
+											</div>
+										</div>
 										<div class="row">
 											<div class="col-sm-6">
 												<div class="form-group">
@@ -201,9 +239,9 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 																<input type="file" id="files" multiple webkitdirectory mozdirectory>
 															</span>
 															<a href="#" class="btn btn-default fileupload-exists" data-dismiss="fileupload">移除檔案</a>
-															<span class="help-block"><strong>注意事項:</strong>請選擇要上傳的資料夾,盡量不要有子資料夾,若有請壓縮後再上傳
-																<br>預覽縮圖請存成PNG,影片格式請使用.avi或.mp4
-																<br>預覽圖及影片名稱請與API名稱相同</span>
+															<span class="help-block"><strong>注意事項:</strong>
+																<br>請選擇要上傳的資料夾,盡量不要有子資料夾,若有請壓縮後再上傳
+																<br>影片格式請使用.avi或.mp4</span>
 														</div>
 													</div>
 												</div>
@@ -427,11 +465,11 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 				e.preventDefault();
 
 				if (isDuplicate) {
-					showNotification('警告','尚未提供上傳不同版本功能,請勿重複上傳!','error');
+					showNotification('警告', '尚未提供上傳不同版本功能,請勿重複上傳!', 'error');
 					return;
 				}
 				if ($("#files").val() === "") {
-					showNotification('警告','請先選擇上傳檔案!','error');
+					showNotification('警告', '請先選擇上傳檔案!', 'error');
 					return;
 				}
 
@@ -443,6 +481,8 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 				for (i = 0; i < $("#files").prop('files').length; i++) {
 					formData.append("files[]", $("#files").prop('files')[i]);
 				}
+				formData.append("thumbnail", $("#thumbnail").prop('files')[0]);
+				formData.append("video", $("#video").prop('files')[0]);
 				$.ajax({
 					type: "POST",
 					url: "./script/php/api_upload.php",
@@ -453,7 +493,7 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 					dataType: 'text', // 回傳的資料格式
 					success: function(data) {
 						console.log(data);
-						showNotification('成功','轉檔上傳成功!','success');
+						showNotification('成功', '轉檔上傳成功!', 'success');
 					},
 					xhr: function() {
 						var xhr = new window.XMLHttpRequest(); // 建立xhr(XMLHttpRequest)物件
@@ -463,8 +503,8 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 								var percentVal = Math.round(percentComplete * 100) + "%";
 								$("#bar").text(percentVal); // 進度條百分比文字
 								$("#bar").width(percentVal); // 進度條顏色
-								if(percentVal == '100%'){
-									showNotification('提示','上傳成功!請稍待轉檔完成','info');
+								if (percentVal == '100%') {
+									showNotification('提示', '上傳成功!請稍待轉檔完成', 'info');
 								}
 							}
 						}, false);
@@ -498,7 +538,7 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 			return isDuplicate;
 		}
 
-		function showNotification(title,text,type) {
+		function showNotification(title, text, type) {
 			var notice = new PNotify({
 				title: title,
 				text: text,

+ 1 - 1
component-list.php

@@ -25,7 +25,7 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 		var url_href = window.location.href;
 		var url = new URL(url_href);
 		parent = url.searchParams.get("parent");
-		type = (url.searchParams.get("type") == "" ? "" : url.searchParams.get("type"));
+		type = (url.searchParams.get("type") == undefined ? "" : url.searchParams.get("type"));
 
 		var $grid;
 

+ 0 - 1
script/php/api_group_detail.php

@@ -15,7 +15,6 @@ if (isset($_GET["object"])) {
     ,[usage]
     ,[source]
     ,[version]
-    ,[filePath]
     ,[webLink]
 FROM [BIMComponents].[dbo].[API_Table] WHERE id = ?;";
     $fetchResult = sqlsrv_query($conn, $sql,array($name));    

+ 15 - 4
script/php/api_upload.php

@@ -1,17 +1,27 @@
 <?php
+session_start();
 include("connectSQL_Component.php");
 $keys = [];
 $values = [];
 $APIName = "";
 
-if (isset($_FILES['files'])) {
+if (isset($_FILES['files']) && isset($_FILES['video']) && isset($_FILES['thumbnail'])) {
 	if ($_POST['APIName'] != "" && $_POST['software'] != "") {
 		$APIName = $_POST['APIName'];
 		$foldername = '../../assets/API/Universal/' . $_POST['software'] . '/' . $_POST['APIName'];
 		if (!is_dir($foldername)) mkdir($foldername);
 		for ($count = 0; $count < count($_FILES['files']['name']); $count++) {
-			move_uploaded_file($_FILES['files']['tmp_name'][$count], $foldername . '/' . $_FILES['files']['name'][$count]);
+			if ($_FILES['files']['name'][$count] != $_FILES['thumbnail']['name'] && $_FILES['files']['name'][$count] != $_FILES['video']['name']) {
+				move_uploaded_file($_FILES['files']['tmp_name'][$count], $foldername . '/' . $_FILES['files']['name'][$count]);
+			}
 		}
+		$thumbnail_path = $foldername . '/' . $_FILES['thumbnail']['name'];
+		$ext = pathinfo($_FILES['video']['name'], PATHINFO_EXTENSION);
+		move_uploaded_file($_FILES['video']['tmp_name'], $foldername . '/' . $APIName . "." . $ext);
+		move_uploaded_file($_FILES['thumbnail']['tmp_name'], $thumbnail_path);
+		imagepng(imagecreatefromstring(file_get_contents($thumbnail_path)), $foldername . '/' . $APIName . ".png");	//轉成 api名稱.png
+		unlink($thumbnail_path);	//刪除原始檔案
+
 		$placeholder = "?";
 		$count = 0;
 		foreach ($_POST as $key => $value) {
@@ -21,16 +31,17 @@ if (isset($_FILES['files'])) {
 				$count++;
 			}
 		}
+		array_push($values, $_SESSION['UserID']); //將 [uploaderID] 放入
 		$placeholder = $placeholder . str_repeat(",?", $count - 1);
 		$params = implode(",", $keys);
 		$sql =  "IF NOT EXISTS (SELECT [APIName] FROM [API_Table] WHERE [APIName] = '{$_POST["APIName"]}')
             BEGIN
 			INSERT INTO [API_Table]
 			(
-				" . $params . "
+				" . $params . ",[uploaderID]
 			)
 	  VALUES
-			(" . $placeholder  . ");
+			(" . $placeholder  . ",?);
 			END";
 		$stmt = sqlsrv_query($conn, $sql, $values);
 

+ 3 - 3
script/php/api_video_tool.php

@@ -76,9 +76,9 @@ function FindPath($root, $folder, $ffmpeg)
             $ext = pathinfo($file_path, PATHINFO_EXTENSION);
             if (in_array($ext, $GLOBALS["videoExt"])) {
                 ConvertVideo($file_path, $ffmpeg);
-            } else if (in_array($ext, $GLOBALS["pdfExt"])) {
-                //ConvertPdf($file_path);
-            }
+            } /*else if (in_array($ext, $GLOBALS["pdfExt"])) {
+                ConvertPdf($file_path);
+            }*/
             $GLOBALS["output"] .= ("</li>");
         } else {
             $GLOBALS["output"] .= ("<li>");

+ 5 - 3
script/php/getPath.php

@@ -4,12 +4,14 @@ include("connectSQL_Component.php");
 
 $array = [];
 $table = [];
-if(isset($_GET["type"])){
+if(isset($_GET["type"]) && $_GET["type"] != "all"){
     $type = urldecode($_GET["type"]);
     $sql = "SELECT * FROM [BIMComponents].[dbo].[API_Table] Where [type] = '".$type."';";
 }
-else
-$sql = "SELECT * FROM [BIMComponents].[dbo].[API_Table]";
+else{
+    $sql = "SELECT * FROM [BIMComponents].[dbo].[API_Table]";
+}
+
 $fetchResult = sqlsrv_query($conn, $sql);
 while ($row = sqlsrv_fetch_array($fetchResult)) {
     array_push($table, $row);

+ 0 - 78
script/php/tools/fileReader.php

@@ -1,78 +0,0 @@
-<?php
-$txtTable = [];
-
-
-$root    = './assets/API/Universal/Revit/';
-//$folder = $_GET["folder"];
-$paths = array_diff(scandir($root), array('.', '..', 'Thumbs.db','MEP','other'));
-foreach ($paths as $value) {
-    $path = scandir($root . "/" . $value);
-    foreach ($path as $txt) {
-        if (str_contains($txt, '.txt')) {
-            $txt = $root . "/" . $value."/".$txt;
-            if (file_exists($txt)) {
-                $str = file_get_contents($txt);
-                $str = str_replace("、",",",$str);
-                $array = explode(":", $str);
-                $data = [];
-                for ($i = 1; $i < 10; $i++) {
-                    
-                    if ($i != 9) {
-                        $values = explode("\r\n", $array[$i]);
-                        array_push($data,$values[0]);
-                        
-                    } else {                        
-                        array_push($data,$array[$i]);
-                    }
-                    
-                }
-                array_push($data,$root . "/" . $value);
-                array_push($txtTable,$data);
-                
-            }            
-        }
-    }
-}
-print_r($txtTable);
-$serverName = "GMGIS\SQLEXPRESS"; //test server 201
-$username = 'BIMuser';
-$password = 'Component3444';
-$dbname = 'BIMComponents';
-
-$connectionInfo = array("Database"=>"$dbname", "UID"=>"$username", "PWD"=>"$password", "CharacterSet"=>"UTF-8");
-$conn = sqlsrv_connect($serverName, $connectionInfo);
-if($conn === false){
-    die(print_r(sqlsrv_errors(), true));
-}
-
-for ($i = 0; $i < count($txtTable); $i++) {      
-    $sql = "INSERT INTO [BIMComponents].[dbo].[API_Table]
-([APIName]
-,[software]
-,[detail]
-,[revitVersion]
-,[operate]
-,[type]
-,[keyword]
-,[source]
-,[notes]
-,[filePath]
-)
-VALUES
-('".$txtTable[$i][0]."'
-,'".$txtTable[$i][1]."'
-,'".$txtTable[$i][2]."'
-,'".$txtTable[$i][3]."'
-,'".$txtTable[$i][4]."'
-,'".$txtTable[$i][5]."'
-,'".$txtTable[$i][6]."'
-,'".$txtTable[$i][7]."'
-,'".$txtTable[$i][8]."'
-,'".$txtTable[$i][9]."'
-);";
-
-    //sqlsrv_query($conn, $sql);
-    echo($sql."<br>");
-}
-
-sqlsrv_close($conn);