1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-11-05 15:30:14 +01:00

fix: share fails if a share was created with a reverse share link recently

This commit is contained in:
Elias Schneider 2023-02-10 10:58:49 +01:00
parent 5d1a7f0310
commit edc10b72b7
No known key found for this signature in database
GPG Key ID: 07E623B294202B6C

View File

@ -44,12 +44,11 @@ export class ShareService {
let expirationDate: Date;
// If share is created by a reverse share token override the expiration date
if (reverseShareToken) {
const { shareExpiration } = await this.reverseShareService.getByToken(
reverseShareToken
);
expirationDate = shareExpiration;
const reverseShare = await this.reverseShareService.getByToken(
reverseShareToken
);
if (reverseShare) {
expirationDate = reverseShare.shareExpiration;
} else {
// We have to add an exception for "never" (since moment won't like that)
if (share.expiration !== "never") {
@ -84,12 +83,14 @@ export class ShareService {
},
});
if (reverseShareToken) {
if (reverseShare) {
// Assign share to reverse share token
await this.prisma.reverseShare.update({
where: { token: reverseShareToken },
data: {
shareId: share.id,
shares: {
connect: { id: shareTuple.id },
},
},
});
}
@ -164,10 +165,10 @@ export class ShareService {
// Check if any file is malicious with ClamAV
this.clamScanService.checkAndRemove(share.id);
if (reverseShareToken) {
if (share.reverseShare) {
await this.prisma.reverseShare.update({
where: { token: reverseShareToken },
data: { used: true },
data: { remainingUses: { decrement: 1 } },
});
}