Skip to content

Commit

Permalink
download in detial
Browse files Browse the repository at this point in the history
  • Loading branch information
yunusefendi52 committed Apr 4, 2024
1 parent 403fde1 commit 5fc70a0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/Releases.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ const upload = () => {
const selectRow =async (row: DataTableRowClickEvent) => {
console.log(row.data)
await navigateTo(`${props.appName}/${row.data.id}`)
}
</script>
21 changes: 20 additions & 1 deletion pages/orgs/[orgName]/apps/[appId]/[detailArtifact].vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
<template>
{{ params }}
{{ data }}

<Button label="Download" @click="download"></Button>
</template>

<script setup lang="ts">
const { params } = useRoute()
const appName = params.appId as string
const orgName = params.orgName as string
const releaseId = params.detailArtifact as string
const { data } = await useFetch('/api/artifacts/detail-artifact', {
query: {
appName: appName,
orgName: orgName,
releaseId: releaseId,
},
})
const download = () => {
const url = `/api/artifacts/download-artifact?fileObjectKey=${data.value?.fileObjectKey}`
console.log(url)
window.open(url, '_blank')
}
</script>
File renamed without changes.
25 changes: 25 additions & 0 deletions server/api/artifacts/detail-artifact.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getStorageKeys } from "~/server/utils/utils"

export default defineEventHandler(async (event) => {
const prisma = event.context.prisma
const { appName, orgName, releaseId } = getQuery(event)
return await prisma.artifacts.findFirstOrThrow({
include: {
apps: true,
},
where: {
releaseId: parseInt(releaseId?.toString() ?? ''),
apps: {
name: appName?.toString(),
Organization: {
name: orgName?.toString(),
OrganizationsPeople: {
every: {
userId: event.context.auth.userId,
},
},
},
},
},
})
})
14 changes: 14 additions & 0 deletions server/api/artifacts/download-artifact.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { GetObjectCommand } from "@aws-sdk/client-s3"
import { getSignedUrl } from "@aws-sdk/s3-request-presigner"
import { getStorageKeys } from "~/server/utils/utils"

export default defineEventHandler(async (event) => {
const { fileObjectKey } = getQuery(event)
const { assets } = getStorageKeys(event.context.auth, fileObjectKey?.toString()!)
const signedUrl = await getSignedUrl(event.context.s3Client, new GetObjectCommand({
Bucket: 'app-deployin',
Key: assets,
}))

await sendRedirect(event, signedUrl)
})

0 comments on commit 5fc70a0

Please sign in to comment.