1
0

UIWindowRequestFiles.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import UIWindow from './UIWindow.js'
  20. async function UIWindowRequestFiles(options){
  21. let h = '';
  22. h += `<div>`;
  23. h += `<h3 style="margin-bottom: 0;">File Request Link:</h3>`;
  24. h += `<p style="word-break: break-all;" class="filereq-link"></p>`;
  25. h += `</div>`;
  26. const el_window = await UIWindow({
  27. title: `Request Files`,
  28. icon: null,
  29. uid: null,
  30. is_dir: false,
  31. body_content: h,
  32. draggable_body: false,
  33. has_head: true,
  34. selectable_body: false,
  35. draggable_body: false,
  36. allow_context_menu: false,
  37. is_resizable: false,
  38. is_droppable: false,
  39. init_center: true,
  40. allow_native_ctxmenu: true,
  41. allow_user_select: true,
  42. width: 400,
  43. dominant: true,
  44. onAppend: function(el_window){
  45. },
  46. window_class: 'window-item-properties',
  47. window_css:{
  48. height: 'initial',
  49. },
  50. body_css: {
  51. padding: '10px',
  52. width: 'initial',
  53. 'max-height': 'calc(100vh - 200px)',
  54. 'background-color': 'rgba(231, 238, 245)',
  55. 'backdrop-filter': 'blur(3px)',
  56. 'padding-bottom': 0,
  57. 'height': 'initial',
  58. }
  59. });
  60. //check if there is a fr token available
  61. let stat = await puter.fs.stat(options.dir_path);
  62. if(stat.file_request_url !== undefined && stat.file_request_url !== null && stat.file_request_url !== ''){
  63. $(el_window).find('.filereq-link').html(stat.file_request_url);
  64. }
  65. // generate new fr url
  66. else{
  67. $.ajax({
  68. url: api_origin + "/filereq",
  69. type: 'POST',
  70. data: JSON.stringify({
  71. dir_path: options.dir_path
  72. }),
  73. async: true,
  74. contentType: "application/json",
  75. headers: {
  76. "Authorization": "Bearer "+auth_token
  77. },
  78. statusCode: {
  79. 401: function (){
  80. logout();
  81. },
  82. },
  83. success: function (filereq){
  84. $(el_window).find('.filereq-link').html(filereq.url);
  85. }
  86. });
  87. }
  88. }
  89. export default UIWindowRequestFiles