share_search.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const axios = require("axios");
  2. const share_download = require("./API/share_download");
  3. const share_info = require("./API/share_info");
  4. const share_search = require("./API/share_search");
  5. const share_save = require("./API/share_save");
  6. var keywork, go;
  7. async function file_down(m) { // 文件下载
  8. var url = await share_download(m.key, cookie);
  9. if (url != false) {
  10. $ui.browser(url);
  11. $ui.toast("开始下载...");
  12. } else {
  13. $ui.toast("获取失败");
  14. }
  15. }
  16. async function file_info(m) {
  17. var data = await share_info(m.key, cookie);
  18. if (data == false) {
  19. $ui.toast("获取失败!");
  20. } else {
  21. $ui.showCode(`文件名: ${data.source.name}\n文件大小: ${(data.source.size/1024/1024).toFixed(2)}M\n访问次数: ${data.views}\n下载次数: ${data.downloads}\n创建时间: ${data.create_date}\n储存节点: ${data.creator.group_name}`);
  22. }
  23. }
  24. async function dir_info(m) {
  25. var data = await share_info(m.key, cookie);
  26. if (data == false) {
  27. $ui.toast("获取失败!");
  28. } else {
  29. $ui.showCode(`文件夹名: ${data.source.name}\n访问次数: ${data.views}\n下载次数: ${data.downloads}\n创建时间: ${data.create_date}\n储存节点: ${data.creator.group_name}`);
  30. }
  31. }
  32. async function copySourceUrl(m) { // 复制分享链接和密码
  33. var url = `https://mo.own-cloud.cn/s/${m.key}?path=%2F`;
  34. $clipboard.text = url;
  35. $ui.toast("复制链接成功");
  36. }
  37. async function save_to(m) {
  38. if(await share_save(m.key, path=="" ? "/" : path, cookie)) {
  39. $ui.toast("保存成功!");
  40. } else {
  41. $ui.toast("保存失败!");
  42. }
  43. }
  44. module.exports = {
  45. type: 'list',
  46. async beforeCreate() {
  47. getCookie();
  48. go = true;
  49. keywork = await $input.text({
  50. title: '分享文件搜索',
  51. hint: '文件名',
  52. value: ''
  53. });
  54. },
  55. async fetch({page}) {
  56. page = page || 1;
  57. keywork == null ? this.finish() : null;
  58. var list = await share_search(keywork, page, cookie);
  59. if (list != false) {
  60. if (list.length < 18) {
  61. go = false;
  62. }
  63. var data = list.map(m => {
  64. if (m.is_dir) {
  65. return {
  66. title: `* ${m.source.name}`,
  67. route: $route("listshare", {
  68. title: m.source.name,
  69. key: m.key,
  70. path: '/'
  71. }),
  72. onLongClick: async () => {
  73. var selected = await $input.select({
  74. title: '选择哪一个',
  75. options: [
  76. {title: '保存文件', fun: save_to},
  77. {title: '复制链接', fun: copySourceUrl},
  78. {title: '属性', fun: dir_info}
  79. ]
  80. })
  81. selected != null ? selected.fun(m) : null;
  82. }
  83. }
  84. } else {
  85. return {
  86. title: m.source.name,
  87. onClick: () => {
  88. file_down(m);
  89. },
  90. onLongClick: async () => {
  91. var selected = await $input.select({
  92. title: '选择哪一个',
  93. options: [
  94. {title: '保存文件', fun: save_to},
  95. {title: '复制链接', fun: copySourceUrl},
  96. {title: '属性', fun: file_info}
  97. ]
  98. })
  99. selected != null ? selected.fun(m) : null;
  100. }
  101. }
  102. }
  103. });
  104. } else {
  105. $ui.toast("没有匹配文件!");
  106. }
  107. if (go) {
  108. return {
  109. nextPage: page+1,
  110. items: data
  111. }
  112. } else {
  113. return data;
  114. }
  115. }
  116. }