mirror of
https://github.com/swissmakers/swiss-datashare.git
synced 2026-04-17 12:43:13 +02:00
feat: direct file link
This commit is contained in:
@@ -20,6 +20,9 @@ export class ShareDTO {
|
||||
@Expose()
|
||||
description: string;
|
||||
|
||||
@Expose()
|
||||
hasPassword: boolean;
|
||||
|
||||
from(partial: Partial<ShareDTO>) {
|
||||
return plainToClass(ShareDTO, partial, { excludeExtraneousValues: true });
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user