self_tag.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. const search_tag = require("./API/search_tag");
  2. const tags = require("./API/tags");
  3. const preview = require("./API/preview");
  4. const property = require("./API/property");
  5. const share = require("./API/share");
  6. const rename = require("./API/rename");
  7. const download = require("./API/download");
  8. // var cookie;
  9. function formatUtcTime(v) { // 时间格式化
  10. if (!v) {
  11. return ''
  12. }
  13. let date = new Date(v);
  14. date = new Date(date.valueOf());
  15. return date.getFullYear() +
  16. "-" + ((date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)) +
  17. "-" + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) +
  18. " " + (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) +
  19. ":" + (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) +
  20. ":" + (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  21. }
  22. async function attribute(m) { // 属性
  23. var info = await property(m.id, false, cookie);
  24. $ui.showCode(`文件名: ${m.name}\n文件大小: ${(info.size/1024/1024).toFixed(2)}M\n创建时间: ${formatUtcTime(info.created_at)}\n更新时间: ${formatUtcTime(info.updated_at)}\n查询时间: ${formatUtcTime(info.query_date)}\n储存节点: ${info.policy}`);
  25. }
  26. async function make_share(m) { // 分享文件、分享文件夹
  27. var new_pwd = "";
  28. var char = 'abcdefghijklmnopqrstuvwxyz1234567890';
  29. for (var i = 0; i < 6; i++) {
  30. j = Math.floor(Math.random() * char.length);
  31. new_pwd += char.charAt(j);
  32. }
  33. $ui.toast("已随机生成密码, 可自行修改");
  34. var password = await $input.text({
  35. title: '输入分享密码',
  36. hint: "分享密码",
  37. value: new_pwd
  38. })
  39. if (password != null) {
  40. var data = await share(m.id, false, password, true, 0, cookie);
  41. $ui.toast("分享成功");
  42. $ui.showCode(`链接: ${data}\n密码: ${password}`);
  43. } else {
  44. $ui.toast("取消分享");
  45. }
  46. }
  47. async function file_rename(m) { // 重新命名文件
  48. var new_name = await $input.text({
  49. title: '修改文件名',
  50. hint: "新文件名",
  51. value: m.name
  52. })
  53. var data = await rename(m.id, true, new_name, cookie);
  54. if (data) {
  55. $ui.toast("重新命名成功!");
  56. } else {
  57. $ui.toast("重新命名失败!");
  58. }
  59. }
  60. async function file_down(m) { // 文件下载
  61. var url = await download(m.id, cookie);
  62. if (url != false) {
  63. $ui.browser(url);
  64. $ui.toast("开始下载...");
  65. } else {
  66. $ui.toast("获取失败");
  67. }
  68. }
  69. async function file_delete(m) { // 删除文件
  70. var data = await object_delete(m.id, true, cookie);
  71. if (data) {
  72. $ui.toast("删除文件成功!");
  73. } else {
  74. $ui.toast("删除文件失败!");
  75. }
  76. }
  77. module.exports = {
  78. type: 'list',
  79. beforeCreate() {
  80. // cookie = `cloudreve-session=${$prefs.get("moCookie")}`;
  81. getCookie();
  82. },
  83. async fetch({args}) {
  84. var list = await search_tag(args.id, cookie);
  85. var file = [];
  86. if (list != false) {
  87. list.map(m => {
  88. if (m.type == "file") {
  89. file.push({
  90. title: m.name,
  91. onClick: async () => {
  92. var type = ['.flv', '.mp4', '.ts'];
  93. var video = false;
  94. type.forEach(f => {m.name.includes(f) ? video=true : null});
  95. if (video) {
  96. var url = await preview(m.id, cookie);
  97. $router.to($route('@video', {url: url, title: m.name}));
  98. } else {
  99. $ui.toast("不是视频");
  100. }
  101. },
  102. onLongClick: async () => {
  103. var selected = await $input.select({
  104. title: '选择哪一个',
  105. options: [
  106. {title: '文件下载', fun: file_down},
  107. {title: '重新命名', fun: file_rename},
  108. {title: '分享文件', fun: make_share},
  109. {title: '删除文件', fun: file_delete},
  110. {title: '属性', fun: attribute},
  111. ]
  112. })
  113. selected != null ? selected.fun(m) : null;
  114. }
  115. });
  116. }
  117. })
  118. }
  119. return file;
  120. }
  121. }