feat: object download

This commit is contained in:
马登山
2025-07-22 11:04:17 +08:00
parent 93d3f67dc2
commit e2ef8e6cc4
4 changed files with 55 additions and 5 deletions
-1
View File
@@ -312,7 +312,6 @@ const retentionFormRef = ref();
const retentionMode = ref<string | null>(null);
const retainUntilDate = ref<string | null>(null);
console.log('🚀 ~ retainUntilDate:', retainUntilDate.value);
const retentionLoading = ref(false);
const showRetentionView = ref(false);
+51 -2
View File
@@ -90,7 +90,14 @@ import { useAsyncData, useRoute, useRouter } from '#app';
import { NuxtLink } from '#components';
import { ListObjectsV2Command, type _Object, type CommonPrefix } from '@aws-sdk/client-s3';
import dayjs from 'dayjs';
import type { DataTableColumns, DataTableRowKey } from 'naive-ui';
import {
NButton,
NSpace,
NPopconfirm,
type DataTableColumns,
type DataTableRowKey,
} from 'naive-ui';
import { Icon } from '#components';
import { joinRelativeURL } from 'ufo';
import { computed, ref, watch, type VNode } from 'vue';
import { useDeleteTaskManagerStore } from '~/store/delete-tasks';
@@ -229,6 +236,41 @@ const columns: DataTableColumns<RowData> = [
return row.LastModified ? dayjs(row.LastModified).format('YYYY-MM-DD HH:mm:ss') : '';
},
},
{
title: t('Actions'),
key: 'actions',
align: 'center',
width: 100,
render: (row: RowData) => {
if (row.type === 'object')
return h(
NSpace,
{
justify: 'center',
},
{
default: () => [
h(
NPopconfirm,
{ onPositiveClick: () => handledownload(row) },
{
default: () => t('Confirm Download'),
trigger: () =>
h(
NButton,
{ size: 'small', secondary: true },
{
default: () => '',
icon: () => h(Icon, { name: 'ri:download-2-line' }),
}
),
}
),
],
}
);
},
},
];
interface ListObjectsResponse {
@@ -278,7 +320,6 @@ watch(
);
const contents = computed(() => data.value?.contents || []);
console.log('🚀 ~ contents:', contents.value);
const commonPrefixes = computed(() => data.value?.commonPrefixes || []);
const nextToken = computed(() => data.value?.nextContinuationToken || null);
@@ -371,6 +412,14 @@ function handleBatchDelete() {
});
}
// 下载
const handledownload = async (item: any) => {
const msg = message.loading(t('Getting URL'));
const url = await objectApi.getSignedUrl(item.Key);
msg.destroy();
window.open(url, '_blank');
};
// 为了实现 "Previous" 功能,需要记录访问过的 token 列表。
// 因为我们是通过路由导航,每次下一页时会改变 URL,从而 SSR 获取新数据。
// 当访问过的 token 会体现在浏览器历史记录中。
+2 -1
View File
@@ -555,5 +555,6 @@
"Batch allocation policies": "Batch allocation policies",
"Object Versions": "Object Versions",
"VersionId": "VersionId",
"LastModified": "LastModified"
"LastModified": "LastModified",
"Confirm Download": "Confirm Download?"
}
+2 -1
View File
@@ -645,5 +645,6 @@
"Search User Group": "搜索用户组",
"Object Versions": "对象版本",
"VersionId": "版本ID",
"LastModified": "最后修改时间"
"LastModified": "最后修改时间",
"Confirm Download": "确认下载?"
}