tag.js 4.5 KB

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