diff --git a/server/api/manifest.plist.get.ts b/server/api/manifest.plist.get.ts index 78ff19c..10e60eb 100644 --- a/server/api/manifest.plist.get.ts +++ b/server/api/manifest.plist.get.ts @@ -2,25 +2,56 @@ import _ from 'lodash' import { takeUniqueOrThrow } from './detail-app.get' import { getArtifactLinkFromPublicIdAndReleaseId } from './install/download.get' import { getArtifactFromInternal } from './artifacts/download-artifact.get' +import { S3AppClient } from '../services/S3AppClient' +import { GetObjectCommand } from '@aws-sdk/client-s3' export default defineEventHandler(async (event) => { const query = getQuery(event) const data = JSON.parse(atob(query.data!.toString())) - const publicId = data.publicLink + let publicId = data.publicLink const releaseId = data.releaseId - // Param from logged in user (without public id) - const orgName = data.orgName - const appName = data.appName - - const { signedUrl, app, detailArtifact: artifact } = publicId ? - await getArtifactLinkFromPublicIdAndReleaseId(event, publicId, releaseId) - : await getArtifactFromInternal( + var plist: string | undefined = undefined + if (publicId) { + const { signedUrl, app, detailArtifact: artifact } = await getArtifactLinkFromPublicIdAndReleaseId(event, publicId, releaseId) + plist = generatePlist( + signedUrl, + artifact.packageName!, + artifact.versionName2, + app.displayName) + } else { + // Param from logged in user (without public id) + const orgName = data.orgName + const appName = data.appName + const { userOrg, app, detailArtifact } = await getArtifactFromInternal( event, orgName!.toString(), appName!.toString(), releaseId!.toString()) - const plist = ` + const { assets } = getStorageKeys(userOrg.organizationsId!, app.id, detailArtifact.fileObjectKey) + const s3 = new S3AppClient() + const signedUrl = await s3.getSignedUrlGetObject(event, new GetObjectCommand({ + Bucket: s3BucketName, + Key: assets, + ResponseContentDisposition: `attachment; filename ="${app.name}${detailArtifact.extension ? `.${detailArtifact.extension}` : ''}"`, + }), 1800) + plist = generatePlist( + signedUrl, + detailArtifact.packageName!, + detailArtifact.versionName2, + app.displayName, + ) + } + setResponseHeader(event, 'Content-Type', "text/xml plist") + return plist +}) + +const generatePlist = ( + signedUrl: string, + packageName: string, + versionName: string, + displayName: string) => { + return ` @@ -40,19 +71,17 @@ export default defineEventHandler(async (event) => { metadata bundle-identifier - ${artifact.packageName} + ${packageName} bundle-version - ${artifact.versionName2} + ${versionName} kind software title - ${app.displayName} + ${displayName} ` - setResponseHeader(event, 'Content-Type', "text/xml plist") - return plist -}) +} \ No newline at end of file