Advertisement
claukiller

Untitled

Apr 20th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.97 KB | None | 0 0
  1. list
  2. <template>
  3. <div class="container">
  4. <div class="tab">
  5. <button class="tablinks" id ="prueba" v-on:click="openTab(event, 'Lista')">Lista</button>
  6. <button class="tablinks" v-on:click="openTab(event, 'Galería')">Galería</button>
  7. </div>
  8.  
  9. <div id="Lista" class="tabcontent">
  10. <div class="row">
  11. <md-table class="col-xs-12">
  12. <md-table-row>
  13. <md-table-head>Nombre</md-table-head>
  14. <md-table-head>Tamaño</md-table-head>
  15. <md-table-head>Modificacion</md-table-head>
  16. <md-table-head>Opciones</md-table-head>
  17. </md-table-row>
  18. <md-table-row :key="file.webViewLink" v-for="file of files">
  19. <md-table-cell class="text-align-l">
  20. <a :href="file.webViewLink">
  21. <img class="icon padding-r-5" :src="chooseExtension(file.extension, file.type)">
  22. <span v-if="file.extension != '' ">
  23. {{file.filename}}.{{file.extension}}
  24. </span>
  25. <span v-else>
  26. {{file.filename}}
  27. </span>
  28. </a>
  29. </md-table-cell>
  30. <md-table-cell class="text-align-l"> {{convertToMbs(file.size)}} MB </md-table-cell>
  31. <md-table-cell class="text-align-l"> {{ file.modifiedTime | moment('LLLL') }} </md-table-cell>
  32. <md-table-cell class="text-align-l">
  33. <md-menu md-direction="bottom-start" :md-offset-x="127" :md-offset-y="-36">
  34. <md-button md-menu-trigger>⋮</md-button>
  35. <md-menu-content>
  36. <md-menu-item><button v-on:click='downloadFile(file)'>Descargar</button></md-menu-item>
  37. <md-menu-item><button v-on:click='deleteFile(file)'>Eliminar</button></md-menu-item>
  38. </md-menu-content>
  39. </md-menu>
  40. </md-table-cell>
  41. </md-table-row>
  42. <md-table-row :key="folder.webViewLink" v-for="folder of folders">
  43. <md-table-cell class="text-align-l">
  44. <a :href="'listfolders/' + folder.id">
  45. <img class="icon padding-r-5" :src="chooseExtension(folder.extension, folder.type)">
  46. {{folder.filename}}
  47. </a>
  48. </md-table-cell>
  49. <md-table-cell class="text-align-l"> - </md-table-cell>
  50. <md-table-cell class="text-align-l"> {{folder.modifiedTime | moment('LLLL')}} </md-table-cell>
  51. <md-table-cell class="text-align-l">
  52. <md-menu md-direction="bottom-start" :md-offset-x="127" :md-offset-y="-36">
  53. <md-button md-menu-trigger>⋮</md-button>
  54. <md-menu-content>
  55. <md-menu-item><a :href="folder.webViewLink">Ir a carpeta</a></md-menu-item>
  56. </md-menu-content>
  57. </md-menu>
  58. </md-table-cell>
  59. </md-table-row>
  60. </md-table>
  61. </div>
  62. </div>
  63.  
  64. <div id="Galería" class="tabcontent">
  65. <table class="row">
  66. <tr :key="file.webViewLink" v-for="file of files" class="col-lg-3 col-md-4 col-sm-6 col-xs-12 text-align-c">
  67. <a :href="file.webViewLink">
  68. <img class="width-020" :src="chooseExtension(file.extension, file.type)">
  69. <span v-if="file.extension != '' ">
  70. <p>{{file.filename}}.{{file.extension}} </p>
  71. </span>
  72. <span v-else>
  73. <p>{{file.filename}}</p>
  74. </span>
  75. </a>
  76. </tr>
  77. <tr :key="folder.webViewLink" v-for="folder of folders" class="col-lg-3 col-md-4 col-sm-6 col-xs-12 text-align-c">
  78. <a :href="'listfolders/' + folder.id">
  79. <img class="width-020" :src="chooseExtension(folder.extension, folder.type)">
  80. <p>{{folder.filename}}</p>
  81. </a>
  82. </tr>
  83. </table>
  84. </div>
  85. </div>
  86. </template>
  87.  
  88. <script>
  89. import axios from 'axios'
  90. export default {
  91. data () {
  92. return {
  93. files: [],
  94. folders: []
  95. }
  96. },
  97. created () {
  98. axios.get('http://localhost:9005/list')
  99. .then(response => {
  100. this.files = response.data
  101. })
  102. axios.get('http://localhost:9005/listfolders')
  103. .then(response => {
  104. this.folders = response.data
  105. })
  106. },
  107. methods: {
  108. openTab (evt, name) {
  109. var i, tabcontent, tablinks
  110. tabcontent = document.getElementsByClassName('tabcontent')
  111. for (i = 0; i < tabcontent.length; i++) {
  112. tabcontent[i].style.display = 'none'
  113. }
  114. tablinks = document.getElementsByClassName('tablinks')
  115. for (i = 0; i < tablinks.length; i++) {
  116. tablinks[i].className = tablinks[i].className.replace(' active', '')
  117. }
  118. document.getElementById(name).style.display = 'block'
  119. evt.currentTarget.className += ' active'
  120. },
  121. convertToMbs (bytes) {
  122. return ((bytes / 1024) / 1024).toFixed(2)
  123. },
  124. chooseExtension (extension, type) {
  125. extension = extension.toLowerCase()
  126. if (type === 'dir') {
  127. return 'static/img/folder.jpg'
  128. }
  129. if (extension === 'txt') {
  130. return 'static/img/txt.jpg'
  131. }
  132. if (extension === 'pptx') {
  133. return 'static/img/ppt.jpg'
  134. }
  135. if (extension === 'docx') {
  136. return 'static/img/docx.jpg'
  137. }
  138. if (extension === 'pdf') {
  139. return 'static/img/pdf.jpg'
  140. }
  141. if (extension === 'xlsx') {
  142. return 'static/img/xlsx.jpg'
  143. }
  144. if (extension === 'zip') {
  145. return 'static/img/zip.jpg'
  146. }
  147. if (extension === 'jpg' || extension === 'png') {
  148. return 'static/img/img.png'
  149. }
  150. if (extension === '') {
  151. return 'static/img/docs.png'
  152. }
  153. },
  154. downloadFile (file) {
  155. var path = file.path
  156. var filename = file.filename + '.' + file.extension
  157. var mimetype = file.mimetype
  158.  
  159. axios.post('http://localhost:9005/get', {path, filename, mimetype}, {responseType: 'blob'})
  160. .then(response => {
  161. let blob = new Blob([response.data], { type: mimetype })
  162. let link = document.createElement('a')
  163. link.href = window.URL.createObjectURL(blob)
  164. link.download = filename
  165. link.click()
  166. })
  167. },
  168. deleteFile (file) {
  169. var path = file.path
  170. axios.get('http://localhost:9005/delete/' + path)
  171. .then(response => {
  172. console.log(response)
  173. })
  174. }
  175. }
  176. }
  177. </script>
  178.  
  179. <!-- Add "scoped" attribute to limit CSS to this component only -->
  180. <style>
  181.  
  182. h1, h2 {
  183. font-weight: normal;
  184. }
  185.  
  186. .width-020{
  187. width: 20%;
  188. }
  189.  
  190. .text-align-c{
  191. text-align: center;
  192. }
  193.  
  194. .text-align-l{
  195. text-align: left;
  196. }
  197.  
  198. .icon {
  199. height: 30px;
  200. width: 30px;
  201. }
  202.  
  203. .display-ib{
  204. display: inline-block;
  205. }
  206.  
  207. .padding-r-5{
  208. padding-right: 5px;
  209. }
  210.  
  211. /* prueba */
  212.  
  213. /* Style the tab */
  214. .tab {
  215. overflow: hidden;
  216. border: 1px solid #ccc;
  217. background-color: #f1f1f1;
  218. }
  219.  
  220. /* Style the buttons inside the tab */
  221. .tab button {
  222. background-color: inherit;
  223. float: left;
  224. border: none;
  225. outline: none;
  226. cursor: pointer;
  227. padding: 14px 16px;
  228. transition: 0.3s;
  229. font-size: 17px;
  230. }
  231.  
  232. /* Change background color of buttons on hover */
  233. .tab button:hover {
  234. background-color: #ddd;
  235. }
  236.  
  237. /* Create an active/current tablink class */
  238. .tab button.active {
  239. background-color: #ccc;
  240. }
  241.  
  242. /* Style the tab content */
  243. .tabcontent {
  244. display: none;
  245. padding: 6px 12px;
  246. border: 1px solid #ccc;
  247. border-top: none;
  248. }
  249.  
  250. </style>
  251. ------------------------------
  252. web
  253. <?php
  254. use Illuminate\Http\Request;
  255.  
  256. /*
  257. |--------------------------------------------------------------------------
  258. | Web Routes
  259. |--------------------------------------------------------------------------
  260. |
  261. | Here is where you can register web routes for your application. These
  262. | routes are loaded by the RouteServiceProvider within a group which
  263. | contains the "web" middleware group. Now create something great!
  264. |
  265. */
  266.  
  267. Route::get('/', function () {
  268. return view('welcome');
  269. });
  270.  
  271. Route::get('put', function() {
  272. Storage::cloud()->put('test.txt', 'Hello World');
  273. return 'File was saved to Google Drive';
  274. });
  275.  
  276. Route::get('put-existing', function() {
  277. $filename = 'laravel.png';
  278. $filePath = public_path($filename);
  279. $fileData = File::get($filePath);
  280.  
  281. Storage::cloud()->put($filename, $fileData);
  282. return 'File was saved to Google Drive';
  283. });
  284.  
  285. Route::get('list', function() {
  286. $dir = '/';
  287. $recursive = false; // Get subdirectories also?
  288. $contents = collect(Storage::cloud()->listContents($dir, $recursive));
  289.  
  290. //return $contents->where('type', '=', 'dir'); // directories
  291. return $contents->where('type', '=', 'file'); // files
  292. });
  293.  
  294. Route::get('listfolders', function() {
  295. $dir = '/';
  296. $recursive = false; // Get subdirectories also?
  297. $contents = collect(Storage::cloud()->listContents($dir, $recursive));
  298.  
  299. return $contents->where('type', '=', 'dir'); // directories
  300. //return $contents->where('type', '=', 'file'); // files
  301. });
  302.  
  303. Route::get('listfoldercontents/{id}', function($id) {
  304. return collect(Storage::cloud()->listFolderContents($id));
  305. });
  306.  
  307. Route::post('get', function(Request $request) {
  308. $path = $request->get('path');
  309. $filename = $request->get('filename');
  310. $mimetype = $request->get('mimetype');
  311.  
  312. $rawData = Storage::cloud()->get($path);
  313.  
  314. return response($rawData, 200)
  315. ->header('ContentType', $mimetype)
  316. ->header('Content-Disposition', "attachment; filename='$filename'");
  317. });
  318.  
  319. Route::get('delete/{path}', function($path) {
  320.  
  321. Storage::cloud()->delete($path);
  322.  
  323. return 'File was deleted from Google Drive';
  324. });
  325.  
  326. Route::get('delete', function(Request $request) {
  327.  
  328. $path = $request->get('path');
  329.  
  330. Storage::cloud()->delete($path);
  331.  
  332. return 'File was deleted from Google Drive';
  333. });
  334.  
  335. Route::get('put-get-stream', function() {
  336. // Use a stream to upload and download larger files
  337. // to avoid exceeding PHP's memory limit.
  338.  
  339. // Thanks to @Arman8852's comment:
  340. // https://github.com/ivanvermeyen/laravel-google-drive-demo/issues/4#issuecomment-331625531
  341. // And this excellent explanation from Freek Van der Herten:
  342. // https://murze.be/2015/07/upload-large-files-to-s3-using-laravel-5/
  343.  
  344. // Assume this is a large file...
  345. $filename = 'laravel.png';
  346. $filePath = public_path($filename);
  347.  
  348. // Upload using a stream...
  349. Storage::cloud()->put($filename, fopen($filePath, 'r+'));
  350.  
  351. // Get file listing...
  352. $dir = '/';
  353. $recursive = false; // Get subdirectories also?
  354. $contents = collect(Storage::cloud()->listContents($dir, $recursive));
  355.  
  356. // Get file details...
  357. $file = $contents
  358. ->where('type', '=', 'file')
  359. ->where('filename', '=', pathinfo($filename, PATHINFO_FILENAME))
  360. ->where('extension', '=', pathinfo($filename, PATHINFO_EXTENSION))
  361. ->first(); // there can be duplicate file names!
  362.  
  363. //return $file; // array with file info
  364.  
  365. // Store the file locally...
  366. //$readStream = Storage::cloud()->getDriver()->readStream($file['path']);
  367. //$targetFile = storage_path("downloaded-{$filename}");
  368. //file_put_contents($targetFile, stream_get_contents($readStream), FILE_APPEND);
  369.  
  370. // Stream the file to the browser...
  371. $readStream = Storage::cloud()->getDriver()->readStream($file['path']);
  372.  
  373. return response()->stream(function () use ($readStream) {
  374. fpassthru($readStream);
  375. }, 200, [
  376. 'Content-Type' => $file['mimetype'],
  377. //'Content-disposition' => 'attachment; filename="'.$filename.'"', // force download?
  378. ]);
  379. });
  380.  
  381. Route::get('create-dir/{name_project}', function($name_project) {
  382. Storage::cloud()->makeDirectory($name_project);
  383.  
  384. $dir = '/';
  385. $recursive = false; // Get subdirectories also?
  386. $contents = collect(Storage::cloud()->listContents($dir, $recursive));
  387.  
  388. $dir = $contents->where('type', '=', 'dir')
  389. ->where('filename', '=', $name_project)
  390. ->first(); // There could be duplicate directory names!
  391.  
  392. Storage::cloud()->makeDirectory($dir['path'].'/Enviados');
  393. Storage::cloud()->makeDirectory($dir['path'].'/Recibidos');
  394. Storage::cloud()->makeDirectory($dir['path'].'/Trabajo');
  395. Storage::cloud()->makeDirectory($dir['path'].'/Informe');
  396. Storage::cloud()->makeDirectory($dir['path'].'/Administracion');
  397. Storage::cloud()->put($dir['path'].'/Log.txt', 'Log del proyecto');
  398.  
  399. return 'Directory was created in Google Drive';
  400. });
  401.  
  402. function base64url_decode($data) {
  403. return base64_decode(strtr($data, '-_', '+/'));
  404. }
  405.  
  406. Route::post('put-in-dir/', function(Request $request) {
  407.  
  408. $folderId = $request->get('FolderId');
  409. $to = $request->get('To');
  410. $from = $request->get('From');
  411. $ref = $request->get('Reference');
  412. $attachsRaw = $request->get('AttachRaw');
  413. $attNames = $request->get('AttachNames');
  414. $dateMail = $request->get('DateMail');
  415. //$dataMail = $request->get('DataMail');
  416. $subject = $request->get('Subject');
  417. $content = $request->get('FileRaw');
  418. $attachRaw = $request->get('AttachRaw');
  419.  
  420. $folderName=$subject.'_1234_'.$from.'_'.$dateMail;
  421. //Hay que añadir un punto al final del string porque si no coge el . del mail y lo parte como si fuese la extension
  422. Storage::cloud()->makeDirectory($folderId.'/'.$folderName.'.');
  423.  
  424. $contents = collect(Storage::cloud()->listFolderContents($folderId));
  425.  
  426.  
  427. $newFolder = $contents->where('type', '=', 'dir')
  428. ->where('filename', '=', $folderName)
  429. ->first();
  430.  
  431. $folderId2 = $newFolder['path'];
  432.  
  433. Storage::cloud()->put($folderId2.'/'. $subject.'.eml', $content);
  434.  
  435. $listSize = count($attNames);
  436.  
  437. for ($i = 0; $i< $listSize; $i++){
  438. Storage::cloud()->put($folderId2.'/'. $attNames[$i], base64url_decode($attachsRaw[$i]) );
  439. }
  440.  
  441. return $contents;
  442. });
  443.  
  444. Route::get('newest', function() {
  445. $filename = 'test.txt';
  446.  
  447. Storage::cloud()->put($filename, \Carbon\Carbon::now()->toDateTimeString());
  448.  
  449. $dir = '/';
  450. $recursive = false; // Get subdirectories also?
  451.  
  452. $file = collect(Storage::cloud()->listContents($dir, $recursive))
  453. ->where('type', '=', 'file')
  454. ->where('filename', '=', pathinfo($filename, PATHINFO_FILENAME))
  455. ->where('extension', '=', pathinfo($filename, PATHINFO_EXTENSION))
  456. ->sortBy('timestamp')
  457. ->last();
  458.  
  459. return Storage::cloud()->get($file['path']);
  460. });
  461.  
  462. Route::get('delete-dir', function() {
  463. $directoryName = 'test';
  464.  
  465. // First we need to create a directory to delete
  466. Storage::cloud()->makeDirectory($directoryName);
  467.  
  468. // Now find that directory and use its ID (path) to delete it
  469. $dir = '/';
  470. $recursive = false; // Get subdirectories also?
  471. $contents = collect(Storage::cloud()->listContents($dir, $recursive));
  472.  
  473. $directory = $contents
  474. ->where('type', '=', 'dir')
  475. ->where('filename', '=', $directoryName)
  476. ->first(); // there can be duplicate file names!
  477.  
  478. Storage::cloud()->deleteDirectory($directory['path']);
  479.  
  480. return 'Directory was deleted from Google Drive';
  481. });
  482.  
  483. Route::get('rename-dir', function() {
  484. $directoryName = 'test';
  485.  
  486. // First we need to create a directory to rename
  487. Storage::cloud()->makeDirectory($directoryName);
  488.  
  489. // Now find that directory and use its ID (path) to rename it
  490. $dir = '/';
  491. $recursive = false; // Get subdirectories also?
  492. $contents = collect(Storage::cloud()->listContents($dir, $recursive));
  493.  
  494. $directory = $contents
  495. ->where('type', '=', 'dir')
  496. ->where('filename', '=', $directoryName)
  497. ->first(); // there can be duplicate file names!
  498.  
  499. Storage::cloud()->move($directory['path'], 'new-test');
  500.  
  501. return 'Directory was renamed in Google Drive';
  502. });
  503.  
  504. Route::get('share', function() {
  505. $filename = 'test.txt';
  506.  
  507. // Store a demo file
  508. Storage::cloud()->put($filename, 'Hello World');
  509.  
  510. // Get the file to find the ID
  511. $dir = '/';
  512. $recursive = false; // Get subdirectories also?
  513. $contents = collect(Storage::cloud()->listContents($dir, $recursive));
  514. $file = $contents
  515. ->where('type', '=', 'file')
  516. ->where('filename', '=', pathinfo($filename, PATHINFO_FILENAME))
  517. ->where('extension', '=', pathinfo($filename, PATHINFO_EXTENSION))
  518. ->first(); // there can be duplicate file names!
  519.  
  520. // Change permissions
  521. $service = Storage::cloud()->getAdapter()->getService();
  522. $permission = new \Google_Service_Drive_Permission();
  523. $permission->setRole('reader');
  524. $permission->setType('anyone');
  525. $permission->setAllowFileDiscovery(false);
  526. $permissions = $service->permissions->create($file['basename'], $permission);
  527. });
  528. ----------------------------------
  529. listreceived
  530. <template>
  531. <div class="container">
  532. <div id="Galería">
  533. <div class="col-xs-12">
  534. <md-table class="col-xs-12">
  535. <md-table-row>
  536. <md-table-head class="text-align-c">Asunto</md-table-head>
  537. <md-table-head class="text-align-c">De</md-table-head>
  538. <md-table-head class="text-align-c">Para</md-table-head>
  539. <md-table-head class="text-align-c">Fecha</md-table-head>
  540. <md-table-head class="text-align-c">Guardar</md-table-head>
  541. </md-table-row>
  542. <md-table-row :key="file.id" v-for="file of listPayload">
  543. <md-table-cell>
  544. <a v-on:click="show(file.id)">
  545. {{checkSubject(file)}}
  546. <!--{{checkAttachs(file)}}-->
  547. </a>
  548. </md-table-cell>
  549. <md-table-cell>
  550. <a v-on:click="show(file.id)">
  551. {{checkFrom(file)}}
  552. </a>
  553. </md-table-cell>
  554. <md-table-cell>
  555. <a v-on:click="show(file.id)">
  556. {{checkTo(file)}}
  557. </a>
  558. </md-table-cell>
  559. <md-table-cell>
  560. <a v-on:click="show(file.id)">
  561. {{checkDate(file) | moment('LLLL')}}
  562. </a>
  563. </md-table-cell>
  564. <md-table-cell>
  565. <button v-on:click='saveMail(file)'>Guardar</button>
  566. </md-table-cell>
  567.  
  568. <modal :name="'hello-world' + file.id" height="auto" :scrollable="true">
  569. <p class="padding-modal-p format-text"> Asunto: {{checkSubject(file)}} </p>
  570. <p class="padding-modal-p format-text"> De: {{checkFrom(file)}} </p>
  571. <p class="padding-modal-p format-text"> Para: {{checkTo(file)}} </p>
  572. <p class="padding-modal-p format-text"> Fecha:{{ checkDate(file) | moment('LLLL') }} </p>
  573. <p class="padding-modal-p format-text"> ---------------------- Correo ------------------------ </p>
  574. <p class="padding-modal-p format-text" v-html="checkData(file)"> </p>
  575. <span v-if="file.payload.parts">
  576. <span :key="attach" v-for="attach in checkAttachmentName(file)">
  577. <p class="padding-modal-p format-text"> {{attach}} </p>
  578. </span>
  579. </span>
  580. <p class="padding-modal-p format-text"> {{file.id}}</p>
  581. </modal>
  582. </md-table-row>
  583. </md-table>
  584. </div>
  585. </div>
  586.  
  587. </div>
  588. </template>
  589.  
  590. <script>
  591. import axios from 'axios'
  592. import {Base64 as decoder} from 'js-base64'
  593.  
  594. export default {
  595. data () {
  596. return {
  597. files: [],
  598. listPayload: [],
  599. listMessages: [],
  600. listRaw: []
  601. }
  602. },
  603. created () {
  604. axios.get('https://www.googleapis.com/gmail/v1/users/me/messages?q="in:inbox"',
  605. { headers: {'Authorization': 'Bearer ya29.GlujBd3WfAEAQp9S5kGb6pocXDrsTrmoSedoDfowO3vQdlvNkjG3PuBenauw1Ou21ner41envxdz1hlwXBhEmVf9gbBgX6uk41KgOgaQeOcy9Okazpz-azGKkab1'} })
  606. .then(response => {
  607. this.files = response.data
  608. this.listMessages = this.files.messages
  609.  
  610. for (var i = 0; i < this.listMessages.length; i++) {
  611. axios.get('https://www.googleapis.com/gmail/v1/users/me/messages/' + this.listMessages[i].id,
  612. // + '?format=raw',
  613. { headers: {'Authorization': 'Bearer ya29.GlujBd3WfAEAQp9S5kGb6pocXDrsTrmoSedoDfowO3vQdlvNkjG3PuBenauw1Ou21ner41envxdz1hlwXBhEmVf9gbBgX6uk41KgOgaQeOcy9Okazpz-azGKkab1'} })
  614. .then(response => {
  615. this.filePayload = response.data
  616. this.listPayload.push(this.filePayload)
  617. })
  618. }
  619. })
  620. },
  621. methods: {
  622. decodeRaw (text) {
  623. return (decoder.decode(text.replace(/-/g, '+').replace(/_/g, '/')))
  624. },
  625. show (id) {
  626. this.$modal.show('hello-world' + id)
  627. },
  628. checkReturn (file) {
  629. if (file.payload.headers[7].name === 'Return-Path') {
  630. return file.payload.headers[7].value
  631. } else if (file.payload.headers[7].name === 'From') {
  632. return file.payload.headers[7].value
  633. } else {
  634. return file.payload.headers[6].value
  635. }
  636. },
  637. checkSubject (file) {
  638. return ((file.payload.headers).find(x => x.name === 'Subject')).value
  639. },
  640. getRef (file) {
  641. var subj = ((file.payload.headers).find(x => x.name === 'Subject')).value
  642. return subj.substr(0, 6)
  643. },
  644. /*
  645. checkAttachs (file) {
  646. if (file.payload.parts) {
  647. if (file.payload.parts[2]) {
  648. return 'pruebi2' + file.payload.parts[2].filename
  649. } else if (file.payload.parts[1] && file.payload.parts[1].filename) {
  650. return 'pruebi1' + file.payload.parts[1].filename
  651. } else if (file.payload.parts[0]) {
  652. return 'pruebi0' + file.payload.parts[0].filename
  653. } else {
  654. return 'nose'
  655. }
  656. } else {
  657. return 'no tiene parts'
  658. }
  659. }, */
  660. checkAttachmentName (file) {
  661. var attachmentList = []
  662. if (file.payload.parts) {
  663. for (var i = 0; i <= (file.payload.parts.length) - 1; i++) {
  664. if (file.payload.parts[i].filename) {
  665. attachmentList.push(file.payload.parts[i].filename)
  666. }
  667. }
  668. }
  669. return attachmentList
  670. },
  671. checkAttachmentId (file) {
  672. var attachmentsIds = []
  673. if (file.payload.parts) {
  674. for (var i = 0; i <= (file.payload.parts.length) - 1; i++) {
  675. if (file.payload.parts[i].body.attachmentId) {
  676. attachmentsIds.push(file.payload.parts[i].body.attachmentId)
  677. }
  678. }
  679. }
  680. return attachmentsIds
  681. },
  682. saveMail (file) {
  683. var attachIds = this.checkAttachmentId(file)
  684. let AttachRaw = attachIds.map(attId => {
  685. return axios.get('https://www.googleapis.com/gmail/v1/users/me/messages/' + file.id + '/attachments/' + attId,
  686. { headers: {'Authorization': 'Bearer ya29.GlujBd3WfAEAQp9S5kGb6pocXDrsTrmoSedoDfowO3vQdlvNkjG3PuBenauw1Ou21ner41envxdz1hlwXBhEmVf9gbBgX6uk41KgOgaQeOcy9Okazpz-azGKkab1'}
  687. }
  688. )
  689. })
  690. var url = window.location.href
  691. var arr = url.split('/')
  692. var FolderId = arr[4]
  693. var AttachNames = this.checkAttachmentName(file)
  694. var FileRaw = ''
  695. var From = this.checkFrom(file).replace('"', '').replace('"', '_').replace(' <', '<')
  696. var To = this.checkTo(file)
  697. var Reference = this.getRef(file)
  698. var DateMail = this.checkDate(file)
  699. var Subject = this.checkSubject(file)
  700. // var DataMail = this.checkData(file)
  701.  
  702. axios.all(AttachRaw).then(
  703. AttachRaw => {
  704. AttachRaw = AttachRaw.map(attData => attData.data.data)
  705. this.checkRaw(file).then(response => {
  706. FileRaw = this.decodeRaw(response.data.raw)
  707. console.log(AttachRaw)
  708. axios.post('http://localhost:9005/put-in-dir/', { From, To, FolderId, Reference, AttachNames, DateMail, Subject, FileRaw, AttachRaw })
  709. .then(response => {
  710. console.log(response)
  711. })
  712. .catch(error => {
  713. console.log(error.response)
  714. })
  715. })
  716. })
  717. },
  718. checkRaw (file) {
  719. return axios.get('https://www.googleapis.com/gmail/v1/users/me/messages/' + file.id + '?format=raw',
  720. { headers: {'Authorization': 'Bearer ya29.GlujBd3WfAEAQp9S5kGb6pocXDrsTrmoSedoDfowO3vQdlvNkjG3PuBenauw1Ou21ner41envxdz1hlwXBhEmVf9gbBgX6uk41KgOgaQeOcy9Okazpz-azGKkab1'} })
  721. },
  722. checkFrom (file) {
  723. return ((file.payload.headers).find(x => x.name === 'From')).value
  724. },
  725. checkTo (file) {
  726. return ((file.payload.headers).find(x => x.name === 'To')).value
  727. },
  728. checkDate (file) {
  729. return ((file.payload.headers).find(x => x.name === 'Date')).value
  730. },
  731. checkData (file) {
  732. if (file.payload.body.data) {
  733. return this.decodeRaw(file.payload.body.data)
  734. } else if (file.payload.parts[0]['body'].data) {
  735. return (this.decodeRaw(file.payload.parts[0]['body'].data))
  736. } else if (!file.payload.parts[0].parts) {
  737. return 'este correo solo tiene attachments' + file.id
  738. } else if (file.payload.parts[0].parts[0]['body'].data) {
  739. return this.decodeRaw(file.payload.parts[0].parts[0]['body'].data)
  740. } else {
  741. return 'este correo no se puede mostrar' + file.id
  742. }
  743. }
  744. }
  745. }
  746. </script>
  747.  
  748. <!-- Add "scoped" attribute to limit CSS to this component only -->
  749. <style>
  750.  
  751. h1, h2 {
  752. font-weight: normal;
  753. }
  754.  
  755. ul {
  756. list-style-type: none;
  757. }
  758.  
  759. a {
  760. color: #35495E;
  761. }
  762.  
  763. .width-020{
  764. width: 20%;
  765. }
  766.  
  767. .text-align-c{
  768. text-align: center;
  769. }
  770.  
  771. .text-align-l{
  772. text-align: left;
  773. }
  774.  
  775. .icon {
  776. height: 30px;
  777. width: 30px;
  778. }
  779.  
  780. .display-ib{
  781. display: inline-block;
  782. }
  783.  
  784. .padding-r-5{
  785. padding-right: 5px;
  786. }
  787.  
  788. .padding-modal-p{
  789. padding-left: 50px;
  790. padding-right: 50px;
  791. }
  792.  
  793. .format-text{
  794. overflow-wrap: break-word;
  795. white-space: pre-wrap;
  796. }
  797.  
  798.  
  799. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement