Pārlūkot izejas kodu

update 2024-05-17

junggilpark 1 gadu atpakaļ
vecāks
revīzija
dc5ecf9bdc
2 mainītis faili ar 64 papildinājumiem un 69 dzēšanām
  1. 9 32
      src/app.js
  2. 55 37
      src/views/hello.html

+ 9 - 32
src/app.js

@@ -1274,8 +1274,8 @@ isAuthenticated,
 isAccessTokens,
 async (req, res, next)=>{
   if (req.body) {
-    const {name, siteId, path, teamId, teamName} = req.body;
-    const resultObj = {message:'', successItems : [], failItems : [], locations: []};
+    const {name, siteId, path, teamId, teamName, bindId} = req.body;
+    const resultObj = {message:'', success: 'F'};
     if (name && siteId && path && teamId && teamName) {
       const options = {
         headers: {
@@ -1287,28 +1287,20 @@ async (req, res, next)=>{
       try {
         const teamInfo = await axios.get(`${endPoint}/teams/${teamId}/channels`, options);
         const sharePoint = await axios.get(`${endPoint}/sites/${siteId}/drive`, options);
-        // const siteIndo = await axios.get(`${endPoint}/sites/${siteId}`, options);
-        console.log();
         if (teamInfo.data && teamInfo.data.value && sharePoint.data) {
           const sharePointUrl = sharePoint.data.webUrl;
           if (path.includes('/drive/root:/') && sharePointUrl) {
             let channelName = path.replace('/drive/root:/', '');
-            console.log(channelName);
-            console.log(sharePointUrl + '/' + channelName);
             const contentUrl = sharePointUrl + '/' + channelName;
             channelName = channelName.substring(0, channelName.indexOf('/'));
-            console.log(channelName);
             const idx = teamInfo.data.value.findIndex(obj => obj.displayName === channelName);
+            resultObj.message = `채널명 : ${channelName}<br>파일명 : ${name}<br>요청하신 채널에 탭으로 설정 되지않았습니다.`;
             if (idx >= 0 && contentUrl) {
               const channelId = teamInfo.data.value[idx].id;
-              console.log(teamInfo.data);
-              console.log(`${endPoint}/sites/${siteId}${path}`);
-              console.log(channelId);
               if (channelId) {
                 const param = {
                   displayName: name,
-                  // "teamsApp@odata.bind" : "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/06805b9e-77e3-4b93-ac81-525eb87513b8",
-                  // "teamsApp@odata.bind" : "https://graph.microsoft.com/v1.0/$metadata#teams('a677e58b-0812-4abb-887f-4c49f5adfa3d')/channels('19%3Abec3c8a2cd164db0b001942f087b5a4a%40thread.tacv2')/tabs",
+                  "teamsApp@odata.bind" : `https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/${bindId}`,
                   configuration: {
                     entityId: null,
                     contentUrl: contentUrl,
@@ -1318,33 +1310,18 @@ async (req, res, next)=>{
                 }
                 //sites/root/lists
                 const channelInfo = await axios.post(`${endPoint}/teams/${teamId}/channels/${channelId}/tabs`, param, options);
-                console.log(channelInfo.data);
+                if (channelInfo.data) {
+                  resultObj.success = 'S';
+                  resultObj.message = '채널명 : ' + channelName + '<br>파일명 : '+name+'<br>요청하신 채널에 탭으로 설정 되었습니다.';
+                }
               }
-              // const result = await axios.get(`${endPoint}/sites/${siteId}${path}`, options);
-              // console.log(result.data);
-              // if (result) {
-              //   const param = {
-              //     displayName: name,
-              //     configuration: {
-              //       entityId: null,
-              //       contentUrl: "",
-              //       websiteUrl: "",
-              //       removeUrl: null
-              //     }
-              //   }
-              // }
             }
           }
         }
       }
       catch (error) {
-        // console.log(error);
-        console.log(error.message);
-        console.log(error.name);
-        console.log(error.errors);
-        console.log(error.response.data);
+        resultObj.message = `채널명 : ${channelName}<br>파일명 : ${name}<br>요청하신 채널에 탭으로 설정 중 오류가 발생하였습니다.<br>` + getErrorMessage(error);
       }
-        // resultObj.message = `요청 하신 ${nameArray.length} 개 파일 중 ${ resultObj.successItems.length} 개 파일이 ${text} 되었습니다.`;
     }
     return res.json(resultObj);
   }

+ 55 - 37
src/views/hello.html

@@ -333,17 +333,44 @@
 
               const teamId = $('section .panel .panel-item').eq(0).attr('id');
               const teamList = document.querySelector('#my-team').nextElementSibling.nextElementSibling;
+              let bindId = '';
               let isTeam = false;
+              const fileName = $('section .file-content div.on .sp-name').text();
+              
+              if (checkCnt === 1 && fileName) {
+                const frontId = 'com.microsoft.teamspace.tab.file.staticviewer.';
+                if (fileName.includes('.xlsx')) {
+                  bindId = frontId + 'excel';
+                }
+                else if (fileName.includes('.pdf')){
+                  bindId = frontId + 'pdf';
+                }
+                else if (fileName.includes('.pptx')) {
+                  bindId = frontId + 'powerpoint';
+                }
+                else if (fileName.includes('.docx')) {
+                  bindId = frontId + 'word';
+                }
+                else if (fileName.includes('.vsdx')) {
+                  bindId = frontId + 'visio';
+                }
+              }
+
               if (teamList && $(teamList).find('#'+teamId+'_li').length > 0) {
                 isTeam = true;
-              } 
-              let str = `<div>편집</div>`;
+              }
+
+              let str = '';
+              if (bindId) {
+                str += `<div>편집</div>`;
+              }
               const selectImage = $('section .file-content div.on').find('img');
               if (checkCnt === 1 && 
                   selectImage.length && 
                   isTeam === true &&
-                  selectImage.attr('src') !== '/static/images/folder.png') {
-                str += `<div onclick="addTabs()">탭으로 설정</div>`;
+                  selectImage.attr('src') !== '/static/images/folder.png'&&
+                  bindId) {
+                str += `<div onclick="addTabs('${bindId}')">탭으로 설정</div>`;
               }
               str += `<div onclick="download()">다운로드</div>
                       <div onclick="deleteItem()">삭제</div>`;
@@ -391,10 +418,21 @@
     }
 
     function openWebUrl(url, name, event) {
-      window.open(url);
+      //window.open(url);
+      $.ajax({
+        method: 'get', 
+        url : url, 
+        type : 'json',
+        success : (res)=>{
+          console.log(res);
+        },
+        error : (error)=>{
+          console.log(error);
+        }
+      })
     }
 
-    function addTabs() {
+    function addTabs(bindId) {
       const fileName = $('section .file-content div.on .file_name').text();
       const siteId = $('section .panel .panel-item').eq(0).attr('id');
       const path = getDrivePath() + '/' + fileName;
@@ -408,9 +446,9 @@
           teamId = teamData[idx].id;
         }
       }
-      console.log(fileName , siteId , teamId , path, teamName, channelName);
-      if (fileName && siteId && teamId && path && teamName && channelName) {
-        //teams/a677e58b-0812-4abb-887f-4c49f5adfa3d/channels
+
+      if (fileName && siteId && teamId && path && teamName && channelName && bindId) {
+      
         $.ajax({
           method : 'post',
           url : '/api/add-tab',
@@ -421,45 +459,25 @@
             teamId : teamId,
             teamName : teamName,
             channelName : channelName,
+            bindId : bindId,
           },
           success : (res) => {
-            console.log(res);
+            let color = '';
+            if (res.success === 'F') {
+              color = 'red';
+            }
+            alertMessage('탭으로 설정', res.message, null, color);
+
           },
           error : (error) => {
             console.log(error);
+            alertMessage('탭으로 설정', error.message, null, 'red');
           }
         })
-        // callApi('get', '/sites/' + siteId + path + '/'+ fileName, (jsonData)=>{
-        //   console.log(jsonData);
-        // });
-        // const param = {
-        //   displayName: fileName,
-        //   webUrl : "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/06805b9e-77e3-4b93-ac81-525eb87513b8",
-        //   "configuration": {
-        //     "entityId": "2DCA2E6C7A10415CAF6B8AB6661B3154",
-        //     "contentUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/tabView",
-        //     "websiteUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154",
-        //     "removeUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/uninstallTab"
-        //   }
-        // }
       }
       else {
         alertMessage('탭으로 설정', '탭으로 설정 할 파일 정보를 확인 해주세요.');
       }
-      // const param = {
-      //   "displayName": "My Contoso Tab",
-      //   "teamsApp@odata.bind" : "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/06805b9e-77e3-4b93-ac81-525eb87513b8",
-      //   "configuration": {
-      //     "entityId": "2DCA2E6C7A10415CAF6B8AB6661B3154",
-      //     "contentUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/tabView",
-      //     "websiteUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154",
-      //     "removeUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/uninstallTab"
-      //   }
-      // }
-      // $.ajax({
-      //   url : '/api/add-tabs'
-
-      // })
     }
 
     //파일별 이미지 세팅