feat: direct file link

This commit is contained in:
Elias Schneider
2023-01-31 15:22:08 +01:00
parent cd9d828686
commit 008df06b5c
11 changed files with 144 additions and 25 deletions

View File

@@ -20,6 +20,9 @@ export class ShareDTO {
@Expose()
description: string;
@Expose()
hasPassword: boolean;
from(partial: Partial<ShareDTO>) {
return plainToClass(ShareDTO, partial, { excludeExtraneousValues: true });
}

View File

@@ -34,10 +34,12 @@ export class ShareSecurityGuard implements CanActivate {
include: { security: true },
});
const isExpired =
moment().isAfter(share.expiration) && !moment(share.expiration).isSame(0);
if (!share || isExpired) throw new NotFoundException("Share not found");
if (
!share ||
(moment().isAfter(share.expiration) &&
!moment(share.expiration).isSame(0))
)
throw new NotFoundException("Share not found");
if (share.security?.password && !shareToken)
throw new ForbiddenException(

View File

@@ -26,10 +26,12 @@ export class ShareTokenSecurity implements CanActivate {
include: { security: true },
});
const isExpired =
moment().isAfter(share.expiration) && !moment(share.expiration).isSame(0);
if (!share || isExpired) throw new NotFoundException("Share not found");
if (
!share ||
(moment().isAfter(share.expiration) &&
!moment(share.expiration).isSame(0))
)
throw new NotFoundException("Share not found");
return true;
}

View File

@@ -204,12 +204,13 @@ export class ShareService {
return sharesWithEmailRecipients;
}
async get(id: string) {
async get(id: string): Promise<any> {
const share = await this.prisma.share.findUnique({
where: { id },
include: {
files: true,
creator: true,
security: true,
},
});
@@ -218,8 +219,10 @@ export class ShareService {
if (!share || !share.uploadLocked)
throw new NotFoundException("Share not found");
return share as any;
return {
...share,
hasPassword: share.security?.password ? true : false,
};
}
async getMetaData(id: string) {