hello.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <html lang="en">
  2. <head>
  3. <meta charset="utf-8" />
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  5. <link rel="icon" href="/favicon.ico" />
  6. <link rel="stylesheet" type="text/css" href="/static/styles/custom.css?v=05" />
  7. <script
  8. src="https://res.cdn.office.net/teams-js/2.17.0/js/MicrosoftTeams.min.js"
  9. integrity="sha384-xp55t/129OsN192JZYLP0rGhzjCF9aYtjY0LVtXvolkDrBe4Jchylp56NrUYJ4S2"
  10. crossorigin="anonymous"
  11. ></script>
  12. <script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.2.1/js/msal.js"></script>
  13. <script src="/static/scripts/teamsapp.js"></script>
  14. <script src="https://code.jquery.com/jquery-latest.min.js"></script>
  15. <title>Microsoft Teams Tab</title>
  16. <style>
  17. </style>
  18. </head>
  19. <body>
  20. <div class="wrap">
  21. <div class="content">
  22. <nav>
  23. <div class="tree">
  24. <li class="">
  25. <input type="checkbox" id="file">
  26. <label for="file">내 OFFICE 365 파일</label>
  27. </li>
  28. </div>
  29. <div class="total">모두</div>
  30. <div class="tree group"></div>
  31. </nav>
  32. <section>
  33. <div class="menu">
  34. <div class="sub-menu">
  35. <img src="/static/images/menu-icon.png" width="30" height="30" alt="메뉴 아이콘">
  36. </div>
  37. <div>새로만들기</div>
  38. <div>업로드</div>
  39. <div>새로고침</div>
  40. <div class="one-drive-button">OneDrive에서 열기</div>
  41. </div>
  42. <div class="panel"></div>
  43. <div class="file-title">
  44. <div><img src="/static/images/file.png" width="20" alt="파일"></div>
  45. <div class="head-name" onclick="sorting('name')">이름</div>
  46. <div class="head-size" onclick="sorting('size')">용량</div>
  47. <div class="head-lastModifiedDateTime" onclick="sorting('lastModifiedDateTime')">수정된 날짜</div>
  48. <div class="head-lastModifiedBy.user.displayName" onclick="sorting('lastModifiedBy.user.displayName')">수정한 사람</div>
  49. <div class="head-label" onclick="sorting('label')">민감도</div>
  50. </div>
  51. <div class="file-content"></div>
  52. </section>
  53. </div>
  54. </div>
  55. <div class="modal">
  56. <div class="modal-content">
  57. <div class="title">이름 바꾸기</div>
  58. <input type="text" name="file_name" id="" value="">.pdf
  59. <div>
  60. <div class="name-btn">이름 바꾸기</div>
  61. <div class="name-btn">취소</div>
  62. </div>
  63. </div>
  64. </div>
  65. </body>
  66. </html>
  67. <script>
  68. const groupId = '3df73dac-a8bc-4dd0-9159-fdb2c696c067';
  69. const groupMap = new Map();
  70. let _selectedData = [];
  71. $(()=>{
  72. microsoftTeams.appInitialization.notifySuccess();
  73. getGroupList();
  74. // callApi('get', '/me/drive/root/children', (jsonData)=>{
  75. // console.log('=======================one drive==========================');
  76. // console.log(jsonData);
  77. // console.log('============================================================');
  78. // let str = `<li>
  79. // <input type="checkbox" checked="false" id="my-one-drive" onclick="showOneDrive()">
  80. // <label for="my-one-drive">One Drive</label>
  81. // <ul>`;
  82. // if (jsonData && jsonData.value) {
  83. // const drives = jsonData.value;
  84. // drives.forEach((drive)=>{
  85. // str +=`<li id="${drive.id}" onclick="DrawOneDrive(${drive.id})">${drive.name}</li>`
  86. // })
  87. // }
  88. // str += `</ul>
  89. // </li>`;
  90. // $('.group').append(str);
  91. // });
  92. // callApi('get', '/me/joinedTeams', (jsonData)=>{
  93. // console.log('======================joinedTeams======================')
  94. // console.log(jsonData);
  95. // if (jsonData && jsonData.value && jsonData.value.length) {
  96. // // jsonData.value.forEach((team)=>{
  97. // // team.id
  98. // // callApi('get', '/')
  99. // // })
  100. // }
  101. // // let str = `<li>
  102. // // <input type="checkbox" checked="false" id="my-one-drive" onclick="showOneDrive()">
  103. // // <label for="my-one-drive">One Drive</label>
  104. // // <ul>`;
  105. // // if (jsonData && jsonData.value) {
  106. // // const drives = jsonData.value;
  107. // // drives.forEach((drive)=>{
  108. // // str +=`<li id="${drive.id}" onclick="DrawOneDrive(${drive.id})">${drive.name}</li>`
  109. // // })
  110. // // }
  111. // // str += `</ul>
  112. // // </li>`;
  113. // });
  114. // callApi('get', '/sites', (jsonData)=>{
  115. // console.log('=====================sites===================');
  116. // console.log(jsonData);
  117. // });
  118. // callApi('get', '/me/drives', (jsonData)=>{
  119. // console.log('=====================/me/drives===================');
  120. // console.log(jsonData);
  121. // // drawOneDrive(jsonData);
  122. // })
  123. // getGroupList();
  124. // callApi('get', '/groups/'+groupId+'/drive/items/root/children', (jsonData) =>drawFileList(jsonData, groupId));
  125. //
  126. window.oncontextmenu = function () {
  127. return false;
  128. };
  129. });
  130. function getFileList(id) {
  131. // callApi('get', "/"+id+"/drive/root/children", "Files.Read", drawFileList, id);
  132. callApi('get', "/users/"+id+"/drive", drawFileList, id);
  133. }
  134. // function drawList(jsonData) {
  135. // if (jsonData && jsonData.value) {
  136. // const group = $('.group');
  137. // let str = "";
  138. // jsonData.value.forEach(element => {
  139. // str+=`<li onclick="getFileList('${element.userPrincipalName}')">
  140. // <div style="display:flex;">
  141. // <div class="circle-name">${element.givenName}</div>
  142. // <div style="display:flex; flex-direction:column; justify-content:space-between;">
  143. // <div style="font-size: 16px; font-weight:bold;">${element.displayName}</div>
  144. // <div style="font-size: 12px; color: #7b7777ec;">${element.mail}</div>
  145. // </div>
  146. // </div>
  147. // </li>`
  148. // });
  149. // group.html(str);
  150. // }
  151. // }
  152. function drawFileList(jsonData) {
  153. _selectedData = [];
  154. if (jsonData && jsonData.value && jsonData.value.length > 0) {
  155. _selectedData = jsonData.value;
  156. let str = "";
  157. const $fileContent = $('.file-content');
  158. const $oneDriveBtn = $('.one-drive-button');
  159. const panel = $('.panel');
  160. let panelStr = "";
  161. jsonData.value.forEach((obj, idx)=>{
  162. if (idx === 0 && obj.parentReference) {
  163. const parent = $('#' + obj.parentReference.id);
  164. if (parent) {
  165. console.log(parent);
  166. }
  167. console.log(obj.parentReference.id);
  168. panelStr += `<span class="panel-item on" id="${obj.parentReference.id}" onclick="findChildrenItems(${obj.parentReference.id})">${obj.parentReference.name}</span>`
  169. panel.html(panelStr);
  170. }
  171. dragAndDrop(obj.id);
  172. let images = "/static/images/";
  173. $oneDriveBtn.off('click');
  174. if (obj.webUrl){
  175. $oneDriveBtn.on('click', ()=>{
  176. window.open(obj.webUrl);
  177. })
  178. }
  179. let modifyName = "";
  180. if (obj.lastModifiedBy && obj.lastModifiedBy.user) {
  181. modifyName = obj.lastModifiedBy.user.displayName;
  182. }
  183. if (obj.folder || obj.driveType) {
  184. images += "folder.png";
  185. }
  186. else if (obj.file && obj.name) {
  187. let ext = obj.name.substring(obj.name.lastIndexOf('.') + 1);
  188. if (obj.file.mimeType && obj.file.mimeType.includes('image')){
  189. ext = 'photo';
  190. }
  191. images += ext+ ".svg";
  192. }
  193. else {
  194. images += "file.png";
  195. }
  196. let amount = '';
  197. if (obj.quota) {
  198. amount = getVolume(obj.quota.remaining);
  199. }
  200. if (obj.size) {
  201. amount = getVolume(obj.size);
  202. }
  203. let modifyDate = obj.lastModifiedDateTime;
  204. if (modifyDate) {
  205. modifyDate = modifyDate.replace('T', ' ');
  206. modifyDate = modifyDate.substring(5, 7)+ '월 '+ modifyDate.substring(8, 10)+ '일';
  207. }
  208. str += `
  209. <div id="row_${idx}">
  210. <div>
  211. <input type="checkbox" name="row_${idx}" value="${obj.id}" onclick="event.stopPropagation()">
  212. <img src="${images}" width="20" height="20" alt="폴더 이미지">
  213. </div>
  214. <div class="file_name"><span class="sp-name" onclick="findChildrenItems('${obj.id}', '${obj.name}')">${obj.name}</span></div>
  215. <div>${amount}</div>
  216. <div>${modifyDate}</div>
  217. <div>${modifyName}</div>
  218. <div></div>
  219. </div>`
  220. });
  221. $fileContent.html(str);
  222. $('.file-content > div').on('click', function(e){
  223. e.preventDefault();
  224. const checkbox = $('input[name="' + $(this).attr('id') + '"]');
  225. if (checkbox[0]) {
  226. const isChecked = checkbox.prop("checked");
  227. checkbox.prop('checked', !isChecked);
  228. const method = !isChecked ? 'addClass' : 'removeClass';
  229. $(this)[method]('on');
  230. }
  231. });
  232. window.addEventListener('click', ()=>{
  233. if ($('.toggle-box')[0]){
  234. $('.toggle-box').remove();
  235. }
  236. })
  237. $('.file-content > div').on('mousedown', function(e){
  238. if ((e.button == 2) || (e.which == 3)) {
  239. const checkbox = $('input[name="'+$(this).attr('id') + '"]');
  240. if (!$(this).hasClass('on')) {
  241. checkbox.prop('checked', true);
  242. $(this).addClass('on');
  243. }
  244. if ($('.toggle-box')[0]) {
  245. $('.toggle-box').remove();
  246. }
  247. const {clientX, clientY} = e;
  248. const toggleBox = $(`<div class="toggle-box" style="position:absolute; top:${clientY}; left: ${clientX}">
  249. <div>편집</div>
  250. <div>탭으로 설정</div>
  251. <div>다운로드</div>
  252. <div>삭제</div>
  253. <div>이동</div>
  254. <div>복사</div>
  255. <div onclick="nameChange()">이름 바꾸기</div>
  256. </div>`);
  257. $('body').append(toggleBox);
  258. }
  259. });
  260. }
  261. }
  262. function drawOneDrive(jsonData, name) {
  263. _selectedData = [];
  264. const panel = $('.panel');
  265. let panelStr = `<span class="panel-item on" onclick="showOneDrive()">One Drive</span>`;
  266. panel.html(panelStr);
  267. if (jsonData && jsonData.value && jsonData.value.length > 0) {
  268. _selectedData = jsonData.value;
  269. let str = "";
  270. const $fileContent = $('.file-content');
  271. const $oneDriveBtn = $('.one-drive-button');
  272. jsonData.value.forEach((obj, idx)=>{
  273. console.log(obj);
  274. dragAndDrop(obj.id);
  275. let images = "/static/images/";
  276. $oneDriveBtn.off('click');
  277. if (obj.webUrl){
  278. $oneDriveBtn.on('click', ()=>{
  279. window.open(obj.webUrl);
  280. })
  281. }
  282. let modifyName = "";
  283. if (obj.lastModifiedBy && obj.lastModifiedBy.user) {
  284. modifyName = obj.lastModifiedBy.user.displayName;
  285. }
  286. if (obj.folder || obj.driveType) {
  287. images += "folder.png";
  288. }
  289. else if (obj.file && obj.name) {
  290. let ext = obj.name.substring(obj.name.lastIndexOf('.') + 1);
  291. if (obj.file.mimeType && obj.file.mimeType.includes('image')){
  292. ext = 'photo';
  293. }
  294. images += ext+ ".svg";
  295. }
  296. else {
  297. images += "file.png";
  298. }
  299. let amount = '0 Bytes';
  300. if (obj.size) {
  301. amount = getVolume(obj.size);
  302. }
  303. let modifyDate = obj.lastModifiedDateTime;
  304. if (modifyDate) {
  305. modifyDate = modifyDate.replace('T', ' ');
  306. modifyDate = modifyDate.substring(5, 7)+ '월 '+ modifyDate.substring(8, 10)+ '일';
  307. }
  308. str += `
  309. <div id="row_${idx}">
  310. <div>
  311. <input type="checkbox" name="row_${idx}" value="${obj.id}" onclick="event.stopPropagation()">
  312. <img src="${images}" width="20" height="20" alt="폴더 이미지">
  313. </div>
  314. <div class="file_name"><span class="sp-name" onclick="findOneDriveChildrenItems('${obj.id}')">${obj.name}</span></div>
  315. <div>${amount}</div>
  316. <div>${modifyDate}</div>
  317. <div>${modifyName}</div>
  318. <div></div>
  319. </div>`
  320. });
  321. $fileContent.html(str);
  322. $('.file-content > div').on('click', function(e){
  323. e.preventDefault();
  324. const checkbox = $('input[name="'+$(this).attr('id') + '"]');
  325. if (checkbox[0]) {
  326. const isChecked = checkbox.prop("checked");
  327. checkbox.prop('checked', !isChecked);
  328. const method = !isChecked ? 'addClass' : 'removeClass';
  329. $(this)[method]('on');
  330. }
  331. });
  332. window.addEventListener('click', ()=>{
  333. if ($('.toggle-box')[0]){
  334. $('.toggle-box').remove();
  335. }
  336. })
  337. $('.file-content > div').on('mousedown', function(e){
  338. if ((e.button == 2) || (e.which == 3)) {
  339. const checkbox = $('input[name="'+$(this).attr('id') + '"]');
  340. if (!$(this).hasClass('on')) {
  341. checkbox.prop('checked', true);
  342. $(this).addClass('on');
  343. }
  344. if ($('.toggle-box')[0]) {
  345. $('.toggle-box').remove();
  346. }
  347. const {clientX, clientY} = e;
  348. const toggleBox = $(`<div class="toggle-box" style="position:absolute; top:${clientY}; left: ${clientX}">
  349. <div>편집</div>
  350. <div>탭으로 설정</div>
  351. <div>다운로드</div>
  352. <div>삭제</div>
  353. <div>이동</div>
  354. <div>복사</div>
  355. <div onclick="nameChange()">이름 바꾸기</div>
  356. </div>`);
  357. $('body').append(toggleBox);
  358. }
  359. });
  360. }
  361. }
  362. // callApi('get','/deviceManagement', (jsonData)=>{
  363. // console.log(jsonData);
  364. // })
  365. function nameChange() {
  366. if ($('.file-content > .on .file_name')[0]) {
  367. console.log($('.file-content > .on .file_name').text());
  368. }
  369. }
  370. function dragAndDrop(driveId) {
  371. const $fileContent = $('.file-content');
  372. $fileContent.off('dragover');
  373. $fileContent.off('dragleave');
  374. $fileContent.off('drop');
  375. $fileContent.on('dragover', function(e){
  376. e.preventDefault();
  377. $(this).css('background-color', '#eee');
  378. });
  379. $fileContent.on('dragleave', function(e){
  380. $(this).css('background-color', '#f5f5f5');
  381. })
  382. $fileContent.on("drop", function(e){
  383. e.preventDefault();
  384. $(this).css('background-color', '#f5f5f5');
  385. const file = e.originalEvent.dataTransfer.files[0];
  386. encryptFile(file, driveId);
  387. // if (file && file.type.startsWith("image")) {
  388. // displayImage(file);
  389. // }
  390. });
  391. }
  392. function encryptFile(file, driveId) {
  393. const extArr = [
  394. 'lnk', 'exe', 'com', 'cmd', 'bat', 'dll', 'ini',
  395. 'pst', 'sca', 'drm', 'sys', 'cpl', 'inf', 'drv',
  396. 'dat', 'tmp', 'msp', 'msi', 'pdb', 'jar'
  397. ]
  398. if (file && file.name) {
  399. const ext = file.name.substring(file.name.lastIndexOf('.') + 1);
  400. if (extArr.includes(ext)) {
  401. const modal = `<div class="modal error" style="display: flex;">
  402. <div style="display:flex; border:1px solid red; flex-direction: column; padding:20px;justify-content:center;width:400px;height:120px; background-color:white;">
  403. <div style='width:100%;margin-bottom:10px; height:40px;display:flex;justify-content:space-between; align-items:center; font-weight: bold; font-size: 18px;'>
  404. <div style="">파일 형식 오류</div>
  405. <div onclick="modalClose()" style="cursor:pointer; user-select:none;">x</div>
  406. </div>
  407. <div>
  408. 암호화 할수 없는 형식의 파일입니다.<br>
  409. 파일명 : ${file.name}
  410. </div>
  411. </div>
  412. </div>`;
  413. $('body').append($(modal));
  414. }
  415. uploadFiles(itemId)
  416. }
  417. }
  418. function modalClose() {
  419. if ($('.modal.error')[0]){
  420. $('.modal.error').remove();
  421. }
  422. }
  423. function callApi(type, uri, callBackMethod, args, params) {
  424. $.ajax({
  425. method: 'post',
  426. url : "/api-"+type,
  427. data: {
  428. api_uri: uri,
  429. param : JSON.stringify(params),
  430. },
  431. success: (res)=> {
  432. callBackMethod(res, args);
  433. },
  434. error: (error)=> {
  435. console.log(error);
  436. }
  437. });
  438. }
  439. function makeFolder(type, uri, scopes, callBackMethod, args, params) {
  440. $.ajax({
  441. method: 'post',
  442. url : "/api-"+type,
  443. data: {
  444. api_uri: uri,
  445. scopes : scopes,
  446. param : params,
  447. },
  448. success: (res)=> {
  449. callBackMethod(res, args);
  450. },
  451. error: (error)=> {
  452. console.log(error);
  453. }
  454. });
  455. }
  456. function findChildrenItems(id, type) {
  457. window.event.preventDefault();
  458. window.event.stopPropagation();
  459. // const param = {
  460. // "requests": [
  461. // {
  462. // "entityTypes": [
  463. // "driveItem"
  464. // ],
  465. // "query": {
  466. // "queryString": id
  467. // }
  468. // }
  469. // ]
  470. // }
  471. //
  472. // callApi('post', '/search/query', (jsonData)=>{
  473. // console.log(jsonData);
  474. // },null, param);
  475. if ($('#' + id)[0]) return;
  476. let uri = '/groups/'+groupId+'/drive/items/'+id+'/children';
  477. callApi('get', uri, (jsonData)=>{
  478. drawFileList(jsonData);
  479. },null);
  480. }
  481. function findOneDriveChildrenItems(id) {
  482. callApi('get', '/me/drive/items/'+id+'/children', (jsonData)=>{
  483. drawOneDrive(jsonData);
  484. },null);
  485. }
  486. // $.ajax({
  487. // url: '/test',
  488. // method : 'post',
  489. // success: function(res){
  490. // console.log(res);
  491. // },
  492. // error: function(error) {
  493. // console.log(error);
  494. // }
  495. // })
  496. function getVolume(amount) {
  497. const tb = 1099511627776;
  498. const gb = 1073741824;
  499. const mb = 1048576;
  500. const kb = 1024;
  501. if (!isNaN(Number(amount)) && amount > 0) {
  502. if (amount >= tb) {
  503. amount = (amount/tb).toFixed(2) + 'TB';
  504. }
  505. else if (amount >= gb){
  506. amount = (amount/gb).toFixed(2) + 'GB';
  507. }
  508. else if (amount >= mb){
  509. amount = (amount/mb).toFixed(2) + 'MB';
  510. }
  511. else if (amount >= kb){
  512. amount = (amount/kb).toFixed(2) + 'KB';
  513. }
  514. else {
  515. amount += "Byte";
  516. }
  517. }
  518. return amount;
  519. }
  520. function uploadFiles(itemId) {
  521. //
  522. $.ajax({
  523. method: 'post',
  524. url : "/api-post",
  525. data: {
  526. api_uri: '/groups/'+groupId+'/drive/items/'+itemId+'/content',
  527. scopes : 'Files.ReadWrite',
  528. param : params,
  529. },
  530. success: (res)=> {
  531. callBackMethod(res, args);
  532. },
  533. error: (error)=> {
  534. console.log(error);
  535. }
  536. });
  537. }
  538. function getGroupList() {
  539. $.ajax({
  540. method: 'post',
  541. url : "/getGroupList",
  542. success: (res)=> {
  543. drawList(res);
  544. },
  545. error: (error)=> {
  546. console.log(error);
  547. }
  548. })
  549. }
  550. function drawList(jsonData) {
  551. const group = $('.group');
  552. group.empty();
  553. if (jsonData) {
  554. const {oneDrive, joinedTeams, sites} = jsonData;
  555. let str = `<li>
  556. <input type="checkbox" checked="false" id="my-one-drive" onclick="showOneDrive()">
  557. <label for="my-one-drive">One Drive</label>
  558. <ul>`;
  559. if (oneDrive && oneDrive.length > 0) {
  560. oneDrive.forEach((drive)=>{
  561. str +=`<li id="${drive.id}" onclick="DrawOneDriveFile('${drive.id}', '${drive.name}')">${drive.name}</li>`
  562. })
  563. }
  564. str += `</ul>
  565. </li>`;
  566. if (joinedTeams) {
  567. joinedTeams.teams.forEach((team)=>{
  568. str += `<li>
  569. <input type="checkbox" checked="false" id="joined-team" onclick="showJoinedTeam('${team.id}')">
  570. <label for="joined-team">${team.displayName}</label>
  571. <ul>`;
  572. console.log('팀 : ',team);
  573. const items = joinedTeams.items[team.id];
  574. if (items && items.length > 0) {
  575. items.forEach((item)=>{
  576. str +=`<li id="${item.id}" onclick="showJoinedTeam('${item.id}', '${item.name}')">${item.name}</li>`
  577. })
  578. }
  579. str +=`</ul></li>`;
  580. })
  581. }
  582. group.append($(str));
  583. }
  584. }
  585. function showOneDrive() {
  586. callApi('get', '/me/drive/root/children', (jsonData)=>{
  587. drawOneDrive(jsonData, 'One Drive', null);
  588. })
  589. }
  590. function DrawOneDriveFile(id, name) {
  591. callApi('get', '/me/drive/items/' + id, (jsonData)=>{
  592. drawOneDrive(jsonData, name, id);
  593. })
  594. }
  595. function showJoinedTeam(id, name) {
  596. callApi('get', '/groups/'+id+'/drive/items/root/children', (jsonData)=>{
  597. drawFileList(jsonData, name, id);
  598. })
  599. }
  600. function sorting(type) {
  601. console.log($('.head-'+type));
  602. console.log(_selectedData);
  603. // _selectedData.sort(function (a, b){
  604. // })
  605. }
  606. </script>